Maybe I'm missing something but couldn't you simply create checkGroups as a Set<String>and just compare its size() to $fact.Groups.size() ?<br><br><br>rule check<br> when<br> $fact : StrColl( $gr : groups, eval( $gr.size() != (new HashSet( $gr )).size() ) )<br>
then<br> System.out.println( "failed" );<br>end<br><br>-W<br><br><div class="gmail_quote">On Fri, Apr 17, 2009 at 8:22 AM, campbeln <span dir="ltr"><<a href="mailto:nicholas.campbell@arc.gov.au">nicholas.campbell@arc.gov.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
I have an ArrayList of strings that I need to ensure are all internally<br>
unique (ie: {"1","2","3"} = OK, {"1","2","1"} = Error). I've managed to<br>
cobble together the code below but I'm running into the "forall w/ an<br>
internal from" issue. I don't believe an upgrade is feasible at the moment,<br>
so are there any alternative solutions?<br>
<br>
NOTE: The collection of both $factGroups and $checkGroups is almost<br>
definitely redundant, so please keep any laughing to a minimum =)<br>
<br>
<br>
rule "BR033"<br>
no-loop true<br>
when<br>
$fact : MyFact()<br>
<br>
//# Get 2 copies of all the Groups associated with the $fact<br>
$factGroups : ArrayList() from collect (<br>
Group() from $fact.Groups<br>
)<br>
$checkGroups : ArrayList() from collect (<br>
Group() from $fact.Groups<br>
)<br>
<br>
//# Traverse the $factGroups comparing each $currentGroup to the list<br>
//# within $checkGroups, erroring out if something other then 1 is found<br>
forall (<br>
$currentGroup : Group(this memberOf $factGroups)<br>
$test : ArrayList(size != 1) from collect(<br>
Group(this == $currentGroup) from $checkGroups<br>
)<br>
)<br>
then<br>
System.out.println("Failed: BR033");<br>
end<br>
<br>
I have found a number of postings that seem to be related, namely<br>
<a href="http://www.nabble.com/Best-practice-for-rules-against-multiple-objects-td5621720.html#a5621720" target="_blank">http://www.nabble.com/Best-practice-for-rules-against-multiple-objects-td5621720.html#a5621720</a><br>
but I've been unable to cobble together a solution thus far. All help is<br>
appreciated!<br>
<br>
Thanks!<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Ensure-all-values-in-a-list-are-unique--tp23071079p23071079.html" target="_blank">http://www.nabble.com/Ensure-all-values-in-a-list-are-unique--tp23071079p23071079.html</a><br>
Sent from the drools - user mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>