[rules-users] problem binding variable to map value

Ming Fang mingfang at mac.com
Fri Feb 10 00:04:32 EST 2012


Below is a very simple rule that binds a variable to a map value...

rule "how many times is map.get() called?"

   when
       p:Parameter(
           $value:tags[1]==1,
           $value == 1,
           $value != 2,
           $value != null,
           $value in ("1","2")
       )
   then
       System.out.println("value=" + $value);
end

The problem is map.get() is called 6 times when executing this rule using a Stateless session.
To test this I implement a mock Map that the get(key) simply returns the key. 
So in this example tags[1] return 1.
And in the get() I simply print a test message to see how many times it's been called.
Here is the sequence...

1x = tags[1]
2x = tags[1] == 1
3x = $value == 1
4x = $value != 2
5x = $value != null
and most surprisingly none for $value in ("1","2")
but
6x == System.out.println("value="+$value)

Is this a bug?
It's a huge problem for my application since the call to get() is expensive for my map implementation.

Thanks
--ming



More information about the rules-users mailing list