<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Edson,<br>Works like a champ. Thank you so much for you quick response.<br><br>Regards,<br>Gerald<br><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">----- Original Message ----<br>From: Edson Tirelli <tirelli@post.com><br>To: Rules Users List <rules-users@lists.jboss.org><br>Sent: Thursday, March 13, 2008 7:17:14 PM<br>Subject: Re: [rules-users] accumulate / sum and ArrayList<br><br>
<br> Gerald, <br><br> It is not clear if you want to calculate the sum of all integers in the original list or the sum of all integers greater than 0.<br> Assuming you want to sum all integers greater than 0, see example bellow. Adjust the example to your needs if you want something different. <br>
<br> You already know how to access the elements of a list:<br><br>Number( intValue > 0 ) from $mo.getNumbers()<br><br> You already know how to collect them:<br><br>$i : ArrayList ( ) from collect ( Number( intValue > 0 ) from $mo.getNumbers() )<br>
<br> If instead of collecting them, you want to "accumulate" them:<br><br>$total : Number() from accumulate( $n:Number( intValue > 0 ) from $mo.getNumbers(),<br> sum( $n ) )<br>
<br> Hope it helps,<br> Edson <br><br><br><br><br><br><br><div><span class="gmail_quote">2008/3/13, Gerald Cantor <<a rel="nofollow" ymailto="mailto:geraldmcantor@yahoo.com" target="_blank" href="mailto:geraldmcantor@yahoo.com">geraldmcantor@yahoo.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br> I have an Object in working memory. This object has an ArrayList of Integer<br> objects. I am trying to create a rule that will count all occurrences of<br> Integers in this ArrayList that are non-zero and then calculate the sum of<br>
all the Integers in the ArrayList and then check the total against a range.<br> <br> I understand how to count the non-zero occurrences but I am at a complete<br> loss as to how to calculate the sum of the Integer objects in the ArrayList.<br>
<br> Here is the rule I have thus far<br> rule "Rule 1"<br> dialect "java"<br> when<br> $mo : MyObject( )<br> $i : ArrayList ( ) from collect ( Number( intValue > 0 ) from<br>
$mo.getNumbers() )<br> $total : Number( ) from accumulate ???<br> then<br> System.out.println("Rule 1: i.size() = " + $i.size());<br> System.out.println("Rule 1: total = " + $total);<br>
end<br> <br> I have been unsuccessful in finding a post that deals with how to fill in<br> the ??? portion of my rule. My apologies in advance if I happen to miss such<br> a post.<br> <br> Any help is greatly appreciated.<br>
<br> Regards,<br> Gerald<br> <br>--<br> View this message in context: <a rel="nofollow" target="_blank" href="http://www.nabble.com/accumulate---sum-and-ArrayList-tp16033216p16033216.html">http://www.nabble.com/accumulate---sum-and-ArrayList-tp16033216p16033216.html</a><br>
Sent from the drools - user mailing list archive at <a rel="nofollow" target="_blank" href="http://Nabble.com">Nabble.com</a>.<br> <br> _______________________________________________<br> rules-users mailing list<br> <a rel="nofollow" ymailto="mailto:rules-users@lists.jboss.org" target="_blank" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a rel="nofollow" target="_blank" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br> </blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br>
Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a rel="nofollow" target="_blank" href="http://www.jboss.com">www.jboss.com</a>
<!-- kill --><div><br><br>-----Inline Attachment Follows-----<br><br>_______________________________________________<br>rules-users
mailing
list<br><a ymailto="mailto:rules-users@lists.jboss.org" href="mailto: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></div><br></div></div><br>
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a>
</body></html>