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