[rules-users] To group some objects by type
mdzaebel
mdzaebel at web.de
Fri Feb 8 12:07:59 EST 2013
Mister Nono wrote
> ... only the last car is in the TreeMap
Thats why I said "/you need Lists or Maps as values of the TreeMap/".
*Here is fast solution:*
import Vehicle
import java.util.*
rule "Print grouped vehicles"
when $map : Map() from accumulate ($v : Vehicle($w : wheels),
init(TreeMap map=new TreeMap()),
action( if(map.containsKey($w)) ((List)map.get($w)).add($v);
else map.put($w, new ArrayList(Arrays.asList($v)));),
result(map))
then System.out.println($map);
end
--
View this message in context: http://drools.46999.n3.nabble.com/To-group-some-objects-by-type-tp4022085p4022167.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list