I am having difficulty understanding the part value : value == 0? How does this code work?
rule "My rule"
when
m : MyClass( value : value == 0)
then
end
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you are using Drools 5.4 or a newer snapshot, you can write any boolean expression as a constraint, so
value == 0is a constraint where “value” is a field name in MyClass.Drools also allows you do use “:” to bind an attribute to a variable name, like this:
So, you can write:
Finally, since Drools uses a “context-aware” parser, you can have a variable with the same name as the attribute name, because Drools knows what comes before the : is a variable name, not a field. So, in your example: the variable “value” will be bound to the attribute “value” and the constraint “value == 0” will be true if the value attribute is equal to 0.
Hope it helps.