[rules-users] doubt regarding FORALL and contains operator...

Sudhir M sudhir.cse at gmail.com
Tue Feb 3 02:49:52 EST 2009


Hi ALL,
We are using drools 4.0.7  for one of our projects. We encountered some
issues which I thought are strange.

1. When using FORALL on an entity for which we haven't asserted any of the
instances in the working memory the rule always fires. I thought this rule
should be evaluted to true only if all the asserted instances satisfy the
condition and if we don't insert any of the instances in the working memory
it should no fire the rule. Is this the expected behaviour or am I wrong?

  ex: rule "rule1"
 when
forall (
 Vehicle( model == "bmw" )
)

 then
                System.out.println("in forall");end

2. When using 'contains' operator on array or collection of strings its
working fine. But when we use it for an array of primitive type double it
gives a classcastexception . Is auto boxing not supported? May be this is
fine as it mentioned in the documentation that it works only on Objects. I
tried using the array of Double objects, here it doesn't throw an excpetion
but the rule wasn't firing. The behaviour was same even if I use a
collection of Double objects. Is this a bug or am I missing something?

 ex:
using Array

     rule "OrderArray"
 when

 Order(valueArray contains 0)

 then
             System.out.println("OrderArray");
end.

using Collection


 rule "OrderList"
 when

 Order(valueList contains 0)

 then
             System.out.println("OrderList");
end.

May be for collections I can write it as below


rule "OrderList"
 when

$order : Order( $val:valueList)
              Double(doubleValue   ==0) from $val

 then
       System.out.println("OrderList");
end.   but this working but not intuitive as these rules were maintained
later by a business user it will be easy for him if we contains and also if
we can directly use array instead of collections it would be a great as
current BOM uses arrays everywhere.

Thanks,
sudhir.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090203/3cc7425a/attachment.html 


More information about the rules-users mailing list