<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16608" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial
color=#0000ff size=2>The MVEL trick works. That was exactly what I was
hoping to find.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial
color=#0000ff size=2>thanks,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=846194623-11112008><FONT face=Arial
color=#0000ff size=2>-Jess</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Edson
Tirelli<BR><B>Sent:</B> Tuesday, November 11, 2008 3:40 PM<BR><B>To:</B> Rules
Users List<BR><B>Subject:</B> Re: [rules-users] top n - accumulate function
parameters<BR></FONT><BR></DIV>
<DIV></DIV><BR> 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> 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>
sum( $price * 10 ) )<BR><BR> So the engine will calculate $price *
10 and will send the result into the function implementation.<BR>
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> dialect
"mvel"<BR>when<BR> ...<BR>... accumlate( Cheese( $price :
price
),<BR>
averageTop( [10, $price ] ) )<BR>then<BR>
...<BR>end<BR><BR> The syntax [ ] will create a list in MVEL
and will pass it into the method call:<BR><BR> public void
accumulate(Serializable context, Object value)
{<BR> List values = (List)
value;<BR>
...<BR> }<BR><BR> Problem is you
only have the parameters available in the accumulate() and reverse() call... you
don't have access to them in the init() and result() call.<BR><BR>
If you want to improve this, you are more than
welcome!<BR><BR> []s<BR>
Edson<BR><BR> <BR><BR>
<DIV class=gmail_quote>2008/11/11 Evans, Jess <SPAN dir=ltr><<A
href="mailto:JEvans@collegeboard.org">JEvans@collegeboard.org</A>></SPAN><BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV><SPAN><FONT face=Arial size=2>I'm trying to average top N items. 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. However, the accumulate function interface methods only
take one parameter. If I were to declare a function top(N, things)
within an accumulate call would drools autobox the parameters into some sort
of collection? </FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>Maybe this is a naive solution
anyway. I am still learning to think declaratively.</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>cheers,</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV><FONT
color=#888888>
<DIV><SPAN><FONT face=Arial
size=2>-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> Edson Tirelli<BR> JBoss Drools Core
Development<BR> JBoss, a division of Red Hat @ <A
href="http://www.jboss.com">www.jboss.com</A><BR></BODY></HTML>