Wolfgang I tried both using collect and accumulate and they both worked as you suggested.
ArrayList( $total : size>0 ) from collect ( Asset()) Number ($total:intValue ) from accumulate ($asset:Asset() ,count($asset)) Thanks, Ram --- On Sat, 9/3/11, Wolfgang Laun <[email protected]> wrote: From: Wolfgang Laun <[email protected]> Subject: Re: [rules-users] How to count number of facts of a type in memory? To: "Rules Users List" <[email protected]> Date: Saturday, September 3, 2011, 9:47 PM 2011/9/4 puja nandamuri <[email protected]> > > I tried to create the following rule using a simple drl to just count the > number of Asset facts in memory. > An Asset can be a very simple class. I am not sure if the fields or methods > are really relevant in this rule. > > rule " Count number of Assets Rule" > dialect "mvel" > when > asset:Asset() > ArrayList($total:size >0) from collect ( asset) The first operand of collect is a pattern, not a bound variable. Therefore, use ArrayList($total:size >0) from collect ( Asset() ) Just for counting, accumulate would also be possible: Number( $total: intValue ) from accumulate( Assert(), count(1) ) -W > then > System.out.println(" Number of Assets in memory"+total); > end > This fails. my understanding of how collect works seems to be wrong :( > can you please correct the mistake I might be doing here ? > > _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
