Dear all,<br><br>In my problem, I have to calculate the sum of "price" field from many Drink facts. Here is the code I have:<br><br>when<br>&nbsp;&nbsp;&nbsp; Likes($nameS : name, $drinkS : drinkSpeciality)<br>&nbsp;&nbsp;&nbsp; Drink(speciality == $drinkS, $price : price) &nbsp;&nbsp;&nbsp; <br>then<br>&nbsp;&nbsp;&nbsp; //calculate something like: &nbsp; totalPrice+=$price<br><br>Inspired from what Edson said, I've defined an Accumulator class and I solve the problem:<br><br>when<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $a:Accumulator()<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Likes($nameS : name, $drinkS : drinkSpeciality)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Drink($speciality : speciality -&gt;($speciality == $drinkS), $price : price) &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; then<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $a.incrementDrinksPrice($price.intValue());<br><br>In this context, my questions are: <br><br>1) Is there another appropriate
 solution to calculate the sum of prices? <br><br>2) What is the use of global variables? (because I think I missunderstood their meanings). Can I solve my problem using a global variable like an accumulator, knowing that a global variable is acting like a static variable?<br> <br>Best regards,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Oana.<br><br><br><b><i>Edson Tirelli &lt;tirelli@post.com&gt;</i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> <br>   Jeevan, sorry, I missed your e-mail in the limbo.<br><br>   Just create a class or an attribute to be your accumulator...<br>   For instance, if you create a "branchCounter" attribute in the Tree <br>object, you  can do that:<br><br>rule "Count branches" salience 10<br>when<br>      $t : Tree()<br>      Branch( tree == $t )<br>then<br>      $t.incrementBranchCounter();<br>     
 modify( $t );<br>end<br> <br>rule "Check branch count" salience 0<br>when<br>      $t : Tree( branchCounter &gt; 100 )<br>then<br>     // do something<br>end<br><br>   The only trick is the salience. The first rule must have a higher <br>salience in order to only fire the second rule after all branches are <br>counted.<br><br>   Yes, in trunk you could do better with "accumulate" or "collect". For <br>your case, "collect" would be simpler:<br><br>rule "Check branches"<br>when<br>    $t : Tree()<br>    $branches : ArrayList( size &gt; 100 ) from collect( Branch( tree == $t ) )<br>then<br>    // do something<br>end<br><br>   []s<br>   Edson<br><br>Jeevan Tambuluri wrote:<br><br>&gt; Hello all,<br>&gt;<br>&gt; I have been told that you could implement a helper class to simulate <br>&gt; "accumulate" command in drools. Could you please ealborate on how to <br>&gt; do this? Some code snippet to illustrate this would be very much <br>&gt; appreciated.<br>&gt;<br>&gt; My problem
 is as follows.I have two types of facts - Tree and Branch.  <br>&gt; Each Branch object has a reference to the Tree object it belongs to. I <br>&gt; want to write a rule: The number of  branches in a tree must not <br>&gt; exceed 100. I guess this would be easy to write with "accumulate" <br>&gt; command, which is not yet available in 3.0.x.<br>&gt;<br>&gt; Thanks<br>&gt;<br>&gt; Jeevan<br>&gt;<br>&gt;------------------------------------------------------------------------<br>&gt;<br>&gt;_______________________________________________<br>&gt;rules-users mailing list<br>&gt;rules-users@lists.jboss.org<br>&gt;https://lists.jboss.org/mailman/listinfo/rules-users<br>&gt;  <br>&gt;<br><br><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3124-6000<br> Mobile: +55 11 9218-4151<br> JBoss, a division of Red Hat @ www.jboss.com<br><br><br>_______________________________________________<br>rules-users mailing
 list<br>rules-users@lists.jboss.org<br>https://lists.jboss.org/mailman/listinfo/rules-users<br></blockquote><br><p>&#32;

<hr size=1><a href="
http://us.rd.yahoo.com/evt=49981/*http://advision.webevents.yahoo.com/mailbeta/features_spam.html">Sucker-punch spam</a> with award-winning protection.<br> Try the <a href="
http://us.rd.yahoo.com/evt=49981/*http://advision.webevents.yahoo.com/mailbeta/features_spam.html">free Yahoo! Mail Beta.</a>