[rules-users] Checking for a lack of an object

Wolfgang Laun wolfgang.laun at gmail.com
Fri Aug 19 02:46:13 EDT 2011


On 19 August 2011 15:17, Chris Richmond <crichmond at referentia.com> wrote:

> How do I fire a rule if an object with certain characterstics does not
> exists.
>
> For example my class Foo, if I have a rule:
>
> rule "Identify Foos with values"
>
> when
>         Foo(stringProp=="blah", intProp==5)
> then
>         System.err.println("A Foo was found!");
> end
>
>
> So how do I check for lack of existence of an object with certain
> characteristics
>
> I tried:
> rule "Flag missing Foos with values"
>
> when
>         not(Foo(stringProp=="blah", intProp==5))
> then
>         System.err.println("A proper foo does not exist");
> end
>

That's the way to do it.


>
> I also tried:
> rule "Flag missing Foos with values"
>
> when
>         not(exists(Foo(stringProp=="blah", intProp==5)))
> then
>         System.err.println("A proper foo does not exist");
> end
>

Since not( Foo(...)) means "if no Foo(...) exists", the addition of "exists"
is superfluous and generally considered bad style (even though some systems
accept it to mean just "not".

-W


> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110819/4e3241d5/attachment.html 


More information about the rules-users mailing list