[rules-users] How to count number of facts of a type in memory?
Wolfgang Laun
wolfgang.laun at gmail.com
Sun Sep 4 00:47:30 EDT 2011
2011/9/4 puja nandamuri <med_9501 at yahoo.com>
>
> 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 ?
>
>
More information about the rules-users
mailing list