<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Wolfgang<br><br>I tried both using collect and accumulate and they both worked as you suggested.<br><br> ArrayList( $total : size>0 ) from collect ( Asset())<br> <br> Number ($total:intValue ) from accumulate ($asset:Asset() ,count($asset)) <br><br>Thanks,<br><br>Ram<br><br><br><br><br><br><br>--- On <b>Sat, 9/3/11, Wolfgang Laun <i><wolfgang.laun@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Wolfgang Laun <wolfgang.laun@gmail.com><br>Subject: Re: [rules-users] How to count number of facts of a type in memory?<br>To: "Rules Users List" <rules-users@lists.jboss.org><br>Date: Saturday, September 3, 2011, 9:47 PM<br><br><div class="plainMail">2011/9/4 puja nandamuri <<a
ymailto="mailto:med_9501@yahoo.com" href="/mc/compose?to=med_9501@yahoo.com">med_9501@yahoo.com</a>><br>><br>> I tried to create the following rule using a simple drl to just count the number of Asset facts in memory.<br>> An Asset can be a very simple class. I am not sure if the fields or methods are really relevant in this rule.<br>><br>> rule " Count number of Assets Rule"<br>> dialect "mvel"<br>> when<br>> asset:Asset()<br>> ArrayList($total:size >0) from collect ( asset)<br><br>The first operand of collect is a pattern, not a bound variable. Therefore, use<br><br> ArrayList($total:size >0) from collect ( Asset() )<br><br>Just for counting, accumulate would also be possible:<br><br> Number( $total: intValue ) from accumulate( Assert(), count(1) )<br><br>-W<br><br><br>> then<br>> System.out.println(" Number of Assets in memory"+total);<br>> end<br>> This fails.
my understanding of how collect works seems to be wrong :(<br>> can you please correct the mistake I might be doing here ?<br>><br>><br><br>_______________________________________________<br>rules-users mailing list<br><a ymailto="mailto:rules-users@lists.jboss.org" href="/mc/compose?to=rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></div></blockquote></td></tr></table>