Without any conditions and constraints, this is just a simple computation
you could code in Java and invoke in some appropriate place. But I
suspect you haven't told us the whole story...
You don't say where this "list" is; so I assume it's a field in some other fact.
This code is absolutely untested.
rule count
when
ListHolder( $list : list )
$map: Map from accumulate ( XXX( $id: id, $type: type ) from $list,
init( Map map = new HashMap(); ),
action( Integer count = map.get( $type );
count = Integer.valueOf( count == null ? 1 : count+1 );
map.put( $type, count ); ),
result( map ) )
then
// ... use $map
end
-W
Hi All,I need to go over a not distinct list and count distinct each element in the list.for example:Object XXX {int id;String type;}XXX:id type1 A2 B3 A4 C5 CThe rule should be activated per type and give as a result the count of each type:A 2B 1C 2Thanks
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users