<br>&nbsp;&nbsp; Accumulate functions support only a single parameter, as they are defined now, but would be great if someone can come up with a good way of adding support to variable number of parameters.<br><br>&nbsp;&nbsp; Having said that, you can probably try a quick trick for your rules. The way accumulate function works now is that it takes an expression as the parameter, evaluate the expression and sends the result of the expression to the accumulate function implementation. Example:<br>
<br>... accumulate( Cheese( $price: price ),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum( $price * 10 ) )<br><br>&nbsp;&nbsp; So the engine will calculate $price * 10 and will send the result into the function implementation.<br>&nbsp;&nbsp; So, if you are using MVEL dialect, you can use the list creation simplified syntax to pass multiple parameters to the function. I never tried, but should work:<br>
<br>rule xyz<br>&nbsp;&nbsp;&nbsp; dialect &quot;mvel&quot;<br>when<br>&nbsp;&nbsp;&nbsp; ...<br>... accumlate( Cheese( $price : price ),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; averageTop( [10, $price ] ) )<br>then<br>&nbsp; ...<br>end<br><br>&nbsp;&nbsp;&nbsp; The syntax [ ] will create a list in MVEL and will pass it into the method call:<br>
<br>&nbsp;&nbsp;&nbsp; public void accumulate(Serializable context, Object value) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List values = (List) value;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp; Problem is you only have the parameters available in the accumulate() and reverse() call... you don&#39;t have access to them in the init() and result() call.<br>
<br>&nbsp;&nbsp; &nbsp; If you want to improve this, you are more than welcome!<br><br>&nbsp;&nbsp;&nbsp; []s<br>&nbsp;&nbsp;&nbsp; Edson<br><br>&nbsp;<br><br><div class="gmail_quote">2008/11/11 Evans, Jess <span dir="ltr">&lt;<a href="mailto:JEvans@collegeboard.org">JEvans@collegeboard.org</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">



<div>
<div><span><font size="2" face="Arial">I&#39;m trying to 
average top N items.&nbsp; I can of course collect the items and do the rest in 
the consequence, but thought it might be a scenario applicable to a custom 
accumulate function.&nbsp; However, the accumulate function 
interface&nbsp;methods only take one parameter.&nbsp; If I were to declare a 
function&nbsp;top(N, things) within an accumulate call would drools autobox the 
parameters into some sort of collection?&nbsp; </font></span></div>
<div><span><font size="2" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" face="Arial">Maybe this is a 
naive solution anyway.&nbsp; I am still learning to think 
declaratively.</font></span></div>
<div><span><font size="2" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" face="Arial"></font></span>&nbsp;</div>
<div><span><font size="2" face="Arial">cheers,</font></span></div>
<div><span><font size="2" face="Arial"></font></span>&nbsp;</div><font color="#888888">
<div><span><font size="2" face="Arial">-Jess</font></span></div></font></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a 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>
<br></blockquote></div><br><br clear="all"><br>-- <br> &nbsp;Edson Tirelli<br> &nbsp;JBoss Drools Core Development<br> &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>