[rules-users] Strategy for initializing objects

sonia robotnic+drools at gmail.com
Fri Aug 7 19:48:19 EDT 2009


Hello

I want to achieve this:
box1.setX(0)
box2.setX(box1.size());
box2.setX(box1.size + box2.size)
...

I want to do it with rules, and would like to know what's the best
method of initializing (or any other operation with varying data) a
group of objects

rule "init box"
 when
   b : Box( x == -1)
 then
   b.setX(Box.getX());
   Box.setX( Box.getX() + b.size);
end

This does not work.
A single box object is matched several times instead of different box objects.
What is happening? how come a single box object is matched several
times? Why doesnt drools choose other instances of box?

What do I need to do to initialize all boxes, once for every box?

Thank you.

-- 
robosonia



More information about the rules-users mailing list