An array and an ArrayList may or may not associate a meaning with the order of elements, or even with the array index, e.g., if the index is a month's number (-1).
If your facts MyFact need to reflect this order or even the index number, you ought to add this as an attribute to MyFact, and storing these objects in destination[] should use this index attribute. I would not rely on any evaluation order of rules, or try to influence rule firing so that it maintains order. -W On Mon, Jan 4, 2010 at 7:37 PM, Nawrocki, Dan (IS) <[email protected]>wrote: > I want to control the order of firing for facts that match a single > rule. I'm using Drools 5.0.1. Is there any way to do this? > > My problem can be boiled down as follows. I have an array structure > that I want to conditionally copy to a new array structure. I would > like to order of the destination array to match the source array. The > code to insert facts into working memory increments in ascending order. > It is equivalent to: > > for( Object o : sourceArray ) > ksess.insert( convertToMyFact( o ) ); > > I have constructed my rules as such: > > rule "rule1" > when > $f : MyFact( prop == "testVal" ) > then > copyToDestination( $f.prop, $f.index ); > end > > After running, however, the destination array appears in reverse order: > source[0] == destination[5] > source[1] == destination[4] > source[2] == destination[3] > source[3] == destination[2] > source[4] == destination[1] > source[5] == destination[0] > > Which seems to make sense if the facts are evaluated as if they were > popped off a stack. Is there any way to force Drools to use a list > instead? Or should I just insert facts in reverse order? > > I would like the order: > source[0] == destination[0] > source[1] == destination[1] > etc. > > Thanks, > Dan > > > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users >
_______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
