Re: [rules-users] Drools and ArrayList
Sorry I'm not quire sure I'm following your errors... Are you saying you are having null pointer exceptions with this version: global List list rule "count from global List - but don't do it" when Number( $i: intValue ) from accumulate( Person( age > 20 ) from list, count(1) ) then System.out.println( $i + " Persons" ); end -- View this message in context: http://drools.46999.n3.nabble.com/Drools-and-ArrayList-tp3140821p3158948.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools and ArrayList
This is how to do it - although it's not recommended to use globals in rule conditions. (For one thing: the list must be complete before you call fireAllRules().) global List list rule "count from global List - but don't do it" when Number( $i: intValue ) from accumulate( Person( age > 20 ) from list, count(1) ) then System.out.println( $i + " Persons" ); end -W On 6 July 2011 12:08, wendy wrote: > I think normally setGlobal variables are only used when you want to be able > to call back out to the java code again. (I'm not an expert by any stretch > so please take that with a grain of salt.) So you might be able to just > insert the list. > > I'm going to assume the List is really List if that > is > not true please let me know. > > what about something like this? First is collects all the > NombersUnTypeDefault that match your constraints from list then it counts > them using an accumulate function. > > global java.util.List list > > rule "Calcul redondance" > when > $i: Number() from accumulate($c: NombersUnTypeDefault() > from collect(NombersUnTypeDefault($code == > "AAA", $int == 1) from list) > , count($c)); >then > System.out.println($i); > end > > -- > View this message in context: > http://drools.46999.n3.nabble.com/Drools-and-ArrayList-tp3140821p3144161.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > ___ > rules-users mailing list > rules-users@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users > ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools and ArrayList
I think normally setGlobal variables are only used when you want to be able to call back out to the java code again. (I'm not an expert by any stretch so please take that with a grain of salt.) So you might be able to just insert the list. I'm going to assume the List is really List if that is not true please let me know. what about something like this? First is collects all the NombersUnTypeDefault that match your constraints from list then it counts them using an accumulate function. global java.util.List list rule "Calcul redondance" when $i: Number() from accumulate($c: NombersUnTypeDefault() from collect(NombersUnTypeDefault($code == "AAA", $int == 1) from list) , count($c)); then System.out.println($i); end -- View this message in context: http://drools.46999.n3.nabble.com/Drools-and-ArrayList-tp3140821p3144161.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Drools and ArrayList
Have you tried using the accumulate function? //taken from the link below and modified a bit to use count.. (it is untested) rule "Count the number of items in the order" when $order : Order() $total : Number( ) from accumulate( OrderItem( order == $order), count( ) ) then System.out.println("There are "+$total+ " number of items in the order"); end http://docs.redhat.com/docs/en-US/JBoss_Enterprise_SOA_Platform/4.3/html/JBoss_Rules_Reference_Guide/ch05s05s02s10.html -- View this message in context: http://drools.46999.n3.nabble.com/Drools-and-ArrayList-tp3140821p3141665.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users