The days list property needs to be a Collection (at the moment I think
it uses the collection semantics in java, which sadly arrays are not
part of the collections family).
You can do Arrays.asList() to convert it to a list in the getter
method, and it should work. If you however make it a hashset, it in
theory will be slightly faster then most other collection types.
On Sat, Sep 27, 2008 at 2:04 AM, Marcin Krol <mrkafk(a)gmail.com> wrote:
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
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Michael D Neale
home:
www.michaelneale.net
blog:
michaelneale.blogspot.com