[rules-users] Working with collections
Marcin Krol
mrkafk at gmail.com
Fri Sep 26 12:04:18 EDT 2008
Hello everyone,
I'm a beginner in Drools, so please account for that. :-)
How do I use memberOf operator when working with collections? Depending
on a day of week, I want to check if a day is a working day or weekend day.
I tried this:
package com.sample
dialect "mvel"
import com.sample.ThermostatTimeData;
import com.sample.Thermostat.WorkDay;
import com.sample.Thermostat.WorkDays;
rule "Rule 1"
when
$wd : WorkDays()
$ttd : ThermostatTimeData( day memberOf $wd.daylist )
//$ttd: ThermostatTimeData ( day == "Monday" || day == "Tuesday" || day
== "Wednesday" || day == "Thursday" || day == "Friday" )
then
insert( new WorkDay() );
System.out.println("inserting new workday");
end
with this in my Thermostat class:
public static class WorkDays {
private String[] dl = {"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday"};
public WorkDays() {
}
public String[] getDaylist() {
return this.dl;
}
}
Now the above rule works fine when I select days using the regular fact
field selection in Drools:
$ttd: ThermostatTimeData ( day == "Monday" || day == "Tuesday" || day ==
"Wednesday" || day == "Thursday" || day == "Friday"
However, when I try to access WorkDays.dl or WorkDays.daylist(), the
rule doesn't fire (the program output is empty).
Regards,
MK
More information about the rules-users
mailing list