【问题标题】:Drools rule to check a collection with compound value restrictionDrools 规则检查具有复合值限制的集合
【发布时间】:2011-01-03 10:33:26
【问题描述】:
我想检查一个集合是否包含 not 三个元素。在java中我会做
!(collection.contains("s1") && collection.contains("s2") && collection.contains("s3"))
我怎样才能用流口水做到这一点?我搜索了两个小时并尝试了任何方法,但找不到解决这个“简单”问题的方法。我找到了我真正需要的“复合值限制”,但它不适用于集合和“包含”运算符。
非常感谢您的回答。
拿但内尔
【问题讨论】:
标签:
collections
contains
rules
drools
【解决方案1】:
这和 Java 代码一样:
Collection( this not contains "s1" ||
this not contains "s2" ||
this not contains "s3")
【解决方案2】:
我认为,您可以使用规则方言“java”。
以下示例可以帮助您。
global java.util.ArrayList responseList
rule "checkCollectionRule"
dialect "java"
salience -1
when
eval(ifContains(responseList, val1, val2.....))
then
responseList.add(new Boolean("true"));
end
function Boolean ifContains(List responseList, String val1, String val2,....) {
return (responseList.contains("s1") && responseList.contains("s2") && responseList.contains("s3"));
}
希望对您有所帮助。
谢谢。