[rules-users] How to check for a variable number of "conditions" ina rule?
Anstis, Michael (M.)
manstis1 at ford.com
Wed Jul 23 02:19:24 EDT 2008
Hi Ron,
Have a look at the "Alarms" example for "Collect" in the (4.0.5) manual.
This should give you a good starting point.
Cheers,
Mike
-----Original Message-----
From: rules-users-bounces at lists.jboss.org
[mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Ron Kneusel
Sent: 22 July 2008 23:01
To: rules-users at lists.jboss.org
Subject: [rules-users] How to check for a variable number of
"conditions" ina rule?
Greetings!
I want to create a rule that checks a fact which contains an array to
see if n or more of the elements of that array have a specific value.
The number of elements to check will vary from invocation to invocation
of the rules engine and will likely be added as a global.
I can do this by using a helper function. Say, for example, I have:
rule "fire_when_testFlags_true"
when
eval(testFlags(flags, limit.intValue()));
then
System.out.println("Yup, " + limit + " or more flags are
true!");
end
Where flags and limit are both globals. Then I can define testFlags as:
function boolean testFlags(Flags flags, int threshold) {
int count = 0;
for(int i=0; i < flags.getSize(); i++) {
if (flags.getValue(i)) {
count++;
if (count>= threshold) {
return true;
}
}
}
return false;
}
This works but violates the warning not to use a global that isn't
immutable in the LHS of a rule. Does anyone have an idea about how to
implement a rule that in effect has an arbitrary number of conditions to
be tested?
Ron
_________________________________________________________________
Keep your kids safer online with Windows Live Family Safety.
http://www.windowslive.com/family_safety/overview.html?ocid=TXT_TAGLM_WL
_family_safety_072008
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list