检查列表的所有元素(Drools Expert)

时间:2011-02-24 15:11:44

标签: java rules drools decision-tree rule-engine

我正在尝试在Drools Expert中编写规则。在规则的when部分中,我检查了Application对象的一些属性。这个对象包含一个List,我想检查一堆规则是否适用于此列表中SomeOtherType的所有对象。仅当约束对该列表中的所有对象有效时,才应触发该规则。

rule "Application eligible"
    when
        app : Application(
               some constrains
               & write some constraints for all objects in app.getList() (a method
               that returns a List<SomeOtherType> object)
        )
    then 
        // application is eligible
end

2 个答案:

答案 0 :(得分:3)

如果你想要使用像Geoffry建议的那样将你的对象插入到工作记忆中,我还发现了另一种黑客方法:

rule "Person has all brothers"
  when
    $person : Person(siblings != null, siblings.size > 0) 
    List(size == siblings.size) from collect (Person(sex != null, sex == "m") from $person.siblings)
  then
    #Person has all brothers
  end

答案 1 :(得分:2)

如果您还没有将所有SomeOtherType实例插入工作内存中。 如果你想检查所有SomeOtherType的颜色是RED:

,那么尝试这样的事情
rule "Application eligible"
when
    $app : Application()
    forall( $x : SomeOtherType( application == $app ) 
            SomeOtherType( this == $x, color == RED ) )
then 
    // application is eligible
end
相关问题