[rules-users] multi-factor rule

Ronald Albury ronalbury at gmail.com
Wed Nov 23 10:44:05 EST 2011


Hi - I am a Drools newbie and I apologize in advance if the answer to my
question is intuitively obvious to the casual user.

I have an object that has two fields: location(there are more than 50
locations) and age.  I am having difficulty building clean rules for the
following pseudo-code


// Rule One
if(location == "A") {
   if(age > 60)
      do_something();
}
// Rule Two
else if(location == "B") {
    if(age > 70)
        do_something();
}
// Rule Three
else if(location == "C") {
    if(age > 80)
        do_something();
}
// Rule Four
else {
    if(age > 65)
        do_something();
}

The issue comes with Rule Four.  How do I avoid writing the rule so that I
don't have to say (location!="A"&&location!="B"&&location!="C") ?  I also
don't want to have to write an explicit rule for every possible location.

I considered an activation-group with salience to have the rules executed
in order, but the problem is that if rules 1-3 do not fire, then rule 4
fires for all locations - I can get a hit if location=="C" and age==70.

Is it possible to have a 'Map' and do something like
(age>map.get(location)) ?  I could live with creating a map with all
possible locations for key, although I'd rather not go this route.

This problem is typical for the types of rules I'll be writing ... there
can be completely different sets of rule criteria depending on location.


Thanks in advance for your suggestions and your patience.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111123/2a3acbd1/attachment.html 


More information about the rules-users mailing list