tags:

views:

663

answers:

1

Using Drools 3.0.6 (old, I know), what is an efficient evaluation for finding a fact in a known, fixed and quite large array or collection (the inverse of contains, i.e. "is contained in"). Using an OR series of normal "equals" results in StackOverflowError as the array/collection can contain a few thousand entries, as the Drools binary operator evaluation is recursive.

We have a single value fact and an array of values to match. The current "code" looks like this:

$f: Fact(name="TheFact", $data)
eval(!($data.equals("1") || $data.equals("2") || $data.equals("3") ... ))

for a large number of fixed values (1,2,3, ...). I'm looking for something more like "$data in (1,2,3, ...)".

A: 

Sometimes you need to (or it is more readable to) put some of the evaluation into the object itself. Then you can reduce the eval statements to sometihng like eval(!$f.isInRange(1, 200))

Christopher Zahrobsky