[rules-users] finding matching entries in parallel arrays

Aaron Dixon atdixon at gmail.com
Mon Aug 6 12:03:46 EDT 2007


My problem boils down to finding matching entries in parallel arrays.

Here is a rule that succesfully does just that:

rule "Find matching entry in parallel arrays"
    when
        $first : ArrayList( )
        $second : ArrayList( this != $first )
        $i : Integer( this < $first.size )
        eval( $first.get($i) == $second.get($i) )
    then
        System.out.println ( "Found match at index " + $i + "!" );
end


To execute this rule, I must insert (assert) the two ArrayList facts as well
as at least as many Integer facts as there are items in the ArrayLists.

What I don't like about this rule is that

    (1) I have to assert the Integers
    (2) I can't support arbitrarily-sized lists in my rules (without
asserting that many Integer facts)

So -- Is there a better way?

What if a future version of Drools supported implicit Number facts that
allowed for these kinds of indexing rules?

Aaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070806/032366cf/attachment.html 


More information about the rules-users mailing list