Hey Geoffrey,

   Lets talk about short term and long term.

* Long term: we may need to find a way to support primitives. Right now, primitives are wrapped to simplify custom function developments.

* Short term: knowing that all primitives are wrapped, we always recommend you to use Number instead of the concrete wrapper classes implementations.

     public void accumulate(Object context,
                            Object value) {
         SumIntegerAccumulateFunction.SumData data = (SumIntegerAccumulateFunction.SumData) context;
         data.total += ((Number) value).intValue();
     }

    Now, the explanation: to add flexibility to the users writing rules with your function, we support expressions that are MVEL evaluated and the result is sent to the function implementation. So, in your example, if the user wanted to sum the double of the distances, he could write instead:

     $totalDistance : Integer() from accumulate(
        Hop($distance : distance),
        sumInteger( $distance * 2 )
     );

    So, what goes between () is really any valid mvel expression and as such, MVEL decides what is the wrapper class to return the result. Apparently, it is returning a Long for integer type numbers.

    Being brief, it is flexible, powerful and expressive, but it may require some refactorings in the future to improve performance, if it becomes an issue.

    Hope it helps.

       Edson


2007/8/11, Geoffrey De Smet <ge0ffrey.spam@gmail.com>:
It looks like the value objects of the accumulate framework are always
Long's - even when they are Integers?


Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast
to java.lang.Integer
        at
org.drools.base.accumulators.SumIntegerAccumulateFunction.accumulate(SumIntegerAccumulateFunction.java:36)
        at
org.drools.base.accumulators.JavaAccumulatorFunctionExecutor.accumulate(JavaAccumulatorFunctionExecutor.java :79)



Here's the piece of code:

     public void accumulate(Object context,
                            Object value) {
         SumIntegerAccumulateFunction.SumData data =
(SumIntegerAccumulateFunction.SumData ) context;
         data.total += ((Integer) value).intValue(); // breaks
     }


Here's the drl:

   when
     $totalDistance : Integer() from accumulate(
        Hop($distance : distance),
        sumInteger($distance)
     );


Here's the Hop object:

     public int getDistance() {
         ...
     }

Look ma, no longs :) Still a ClassCastException on them though.
I must be missing something really obvious?

--
With kind regards,
Geoffrey De Smet

_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com