I have an ArrayList of strings that I need to ensure are all internally
unique (ie: {"1","2","3"} = OK,
{"1","2","1"} = Error). I've managed to
cobble together the code below but I'm running into the "forall w/ an
internal from" issue. I don't believe an upgrade is feasible at the moment,
so are there any alternative solutions?
NOTE: The collection of both $factGroups and $checkGroups is almost
definitely redundant, so please keep any laughing to a minimum =)
rule "BR033"
no-loop true
when
$fact : MyFact()
//# Get 2 copies of all the Groups associated with the $fact
$factGroups : ArrayList() from collect (
Group() from $fact.Groups
)
$checkGroups : ArrayList() from collect (
Group() from $fact.Groups
)
//# Traverse the $factGroups comparing each $currentGroup to the list
//# within $checkGroups, erroring out if something other then 1 is found
forall (
$currentGroup : Group(this memberOf $factGroups)
$test : ArrayList(size != 1) from collect(
Group(this == $currentGroup) from $checkGroups
)
)
then
System.out.println("Failed: BR033");
end
I have found a number of postings that seem to be related, namely
http://www.nabble.com/Best-practice-for-rules-against-multiple-objects-td...
but I've been unable to cobble together a solution thus far. All help is
appreciated!
Thanks!
--
View this message in context:
http://www.nabble.com/Ensure-all-values-in-a-list-are-unique--tp23071079p...
Sent from the drools - user mailing list archive at
Nabble.com.