The HashSet is created on the fly, just for checking; no data structure needs to be changed.<br><br>I'm not sure I understand what you mean by "check for dups", but that may be because I don't see class the details of class Group.<br>
<br>-W<br><br><div class="gmail_quote">2009/4/17 David Sinclair <span dir="ltr"><<a href="mailto:dsinclair@chariotsolutions.com">dsinclair@chariotsolutions.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
How are items added to the list? Can you just change the data structure to a set as Wolfgang suggested? <br><br>If all the groups are in working memory you can write a rule similar to the following<br><br>rule "check for dups"<br>
when<br> $group1 : Group($index : index)<br> $group2 : Group(this != $group1, index == $index)<br> then<br> System.out.println($group2 + " has a duplicate index ");<br>
end<br><br><div class="gmail_quote">2009/4/17 Wolfgang Laun <span dir="ltr"><<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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><font color="#888888"><br>-W</font><div><div></div><div><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" target="_blank">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" target="_blank">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>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><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>
<br></blockquote></div><br>