Conceptually it's quite simple. Consider a loop

int sum( int[] array )
i = 0;                            // init
for( int a: array ){
   i += a;                     // action
}
return i;                     // result

Drools does the loop, calling your callbacks providing the appropriate context from the scope of the ___ in the accumulate( _____________________ ,

You could look at the implementations of the built-in accumulate functions, and you'll see the same callbacks as methods of the function provider class.

Just for fun: You can also use:

import java.util.Set;
import java.util.HashMap;

rule countById
when
    $set: Set()
            from accumulate( Request( $id: id ),
              init( HashMap id2count = new HashMap() ),
              action( Integer i = (Integer)id2count.get( $id );
                      if( i == null ) i = 0;
                      i++;
                      id2count.put( $id, i ); )
              reverse( Integer i = (Integer)id2count.get( $id );
                       i--;
                       id2count.put( $id, i ); )
              result( id2count.entrySet() ) )
    java.util.Map.Entry( $id: key, $count: value > 1 ) from $set
then
    System.out.println( "Id " + $id + ": " + $count );
end

Don't worry - I wanted to research this for some time; never had an opportunity ;-)
-W


On 7 July 2011 17:18, Andre <morpheusandre@web.de> wrote:
sry if my questions are looking that "nooby", that you are coding for me  i
just wanna know, how this statemachine works behind this ..

--
View this message in context: http://drools.46999.n3.nabble.com/sliding-window-combination-tp3132340p3148523.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users