You are inserting the collected lists and printing them later, with
low salience. The previously shown rule printed the collected facts on
the fly, which will fire the rule repeatedly and visibly. The new
solution still fires the collecting rule repeatedly, but you don't see
that.
-W
On 20/12/2012, devan.vanreenen(a)gmail.com <devan.vanreenen(a)gmail.com> wrote:
I'm not sure what I did earlier, but when executing the below
rules, I get
the desired results. I insert 20 Alert objects and the rule collects alerts
according to a specific case number, rules and output below
Rules
rule 'Group alerts for a specific case'
dialect 'java'
when
Alert( $caseNumber : caseNumber, $alertNo: alertNo )
$list : List( ) from collect($alert : Alert( caseNumber == $caseNumber))
then
insertLogical($list);
end
rule 'Print inserted lists'
salience -10
dialect 'java'
when
$list : List( )
then
System.out.println("******Printing list******: ");
System.out.println("******List hashCode: " + $list.hashCode());
for(Object o : $list){
System.out.println(o);
}
end
Output
******Printing list******:
******List hashCode: -1902211073
Alert [caseNumber=1021567, alertNo=1]
Alert [caseNumber=1021567, alertNo=2]
Alert [caseNumber=1021567, alertNo=8]
******Printing list******:
******List hashCode: -68071555
Alert [caseNumber=1012283, alertNo=1]
Alert [caseNumber=1012283, alertNo=2]
Alert [caseNumber=1012283, alertNo=6]
Alert [caseNumber=1012283, alertNo=2]
Alert [caseNumber=1012283, alertNo=8]
Alert [caseNumber=1012283, alertNo=2]
******Printing list******:
******List hashCode: -485211774
Alert [caseNumber=1022621, alertNo=6]
Alert [caseNumber=1022621, alertNo=6]
Alert [caseNumber=1022621, alertNo=6]
Alert [caseNumber=1022621, alertNo=2]
Alert [caseNumber=1022621, alertNo=1]
Alert [caseNumber=1022621, alertNo=2]
Alert [caseNumber=1022621, alertNo=2]
Alert [caseNumber=1022621, alertNo=8]
******Printing list******:
******List hashCode: 1815474720
Alert [caseNumber=55506677, alertNo=1]
Alert [caseNumber=55506677, alertNo=2]
Alert [caseNumber=55506677, alertNo=6]
--
View this message in context:
http://drools.46999.n3.nabble.com/Collecting-items-in-a-List-tp4021256p40...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users