在 Drools 的列表中搜索元素
Search element in List in Drools
我有 Person 对象列表。对象 Person 包含对象 Car 的列表。我如何才能 select 从列表中只选择包含 Car selected 类型的人。例如:品牌为 "BMW" 的汽车。我不知道没有 for 循环。
person[0].addCar(new Car("BMW"));
person[0].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
我如何才能return人[0]遵守流口水规定。
我的代码不起作用。
rule "HardDrool"
salience 100
when
$world : World();
$persons: Human(
(name == "Yura"),
(!cars.isEmpty()),
(Car(name == "BMW") from getCars())
) from $world.getPersons()
then
System.out.println($persons);
end
rule "HardDrool"
when
$world : World();
$person: Human( name == "Yura", !cars.isEmpty() )
from $world.getPersons()
exists Car( name == "BMW" ) from $person.getCars())
then
System.out.println( $person );
end
每个拥有至少一辆宝马的人类应该触发一次。如果要查看每辆宝马,请省略存在。
我有 Person 对象列表。对象 Person 包含对象 Car 的列表。我如何才能 select 从列表中只选择包含 Car selected 类型的人。例如:品牌为 "BMW" 的汽车。我不知道没有 for 循环。
person[0].addCar(new Car("BMW"));
person[0].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
person[1].addCar(new Car("Ford"));
我如何才能return人[0]遵守流口水规定。
我的代码不起作用。
rule "HardDrool"
salience 100
when
$world : World();
$persons: Human(
(name == "Yura"),
(!cars.isEmpty()),
(Car(name == "BMW") from getCars())
) from $world.getPersons()
then
System.out.println($persons);
end
rule "HardDrool"
when
$world : World();
$person: Human( name == "Yura", !cars.isEmpty() )
from $world.getPersons()
exists Car( name == "BMW" ) from $person.getCars())
then
System.out.println( $person );
end
每个拥有至少一辆宝马的人类应该触发一次。如果要查看每辆宝马,请省略存在。