1

I have a scenario where i need to accumulate two different sets from the same input:

accumulate (ord : Order(type == A); $aSet : collectSet(ord))
accumulate (ord : Order(type == B); $bSet : collectSet(ord))

Is there a way to accomplish it with only one accumulate? This is a simple example, but in my application there is a lot of mutual conditions in these two accumulates and it seems like it does a lot of extra work by iterating two times on the same data with same conditions.

Performance-wise, it seems i would want to iterate only one time over the records and collect different data to different sets.

Any suggestions?

Thanx.

supermax2015
  • 69
  • 10

1 Answers1

1

You can write your own accumulate:

rule coll
when
  $map: Map()
    from accumulate( $o: Order( $t: type ),
         init( Map m = new HashMap();
               m.put( "A", new HashSet() );
               m.put( "B", new HashSet() ); ),
         action( ((Set)m.get( $t )).add( $o ); ),
         reverse( ((Set)m.get( $t )).remove( $o ); ),
         result( m ) )
then
  System.out.println( $map.get( "A" ) );
  System.out.println( $map.get( "B" ) );
end
laune
  • 31,114
  • 3
  • 29
  • 42