[rules-users] How to count number of facts of a type in memory?
puja nandamuri
med_9501 at yahoo.com
Sun Sep 4 13:15:46 EDT 2011
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 <wolfgang.laun at gmail.com> wrote:
From: Wolfgang Laun <wolfgang.laun at gmail.com>
Subject: Re: [rules-users] How to count number of facts of a type in memory?
To: "Rules Users List" <rules-users at lists.jboss.org>
Date: Saturday, September 3, 2011, 9:47 PM
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 ?
>
>
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110904/5e162241/attachment.html
More information about the rules-users
mailing list