Question

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, ...)".

Was it helpful?

Solution

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))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top