Validation Drools:字符串列表的任何值都是另一个字符串列表的成员
如果字符串列表的任何值是另一个字符串列表的成员,我很难找到如何检查droolsValidation Drools:字符串列表的任何值都是另一个字符串列表的成员,validation,drools,Validation,Drools,如果字符串列表的任何值是另一个字符串列表的成员,我很难找到如何检查drools when //any value of stringList1 member of stringList2 then // whatever... 我想,我可能会用forall手术,但还是找不到路。有什么帮助吗 假设我的验证bean类似于: public final class StringListValidationBean { private List<String> string
when
//any value of stringList1 member of stringList2
then
// whatever...
我想,我可能会用forall手术,但还是找不到路。有什么帮助吗
假设我的验证bean类似于:
public final class StringListValidationBean {
private List<String> stringList1;
private List<String> stringList2;
//... gets & sets
}
公共最终类StringListValidationBean{
私人名单1;
私人名单2;
//…获取和设置
}
试试这个:
rule someString
when
$l1: List()
$s: String() from $l1
List( hashCode > $l1.hashCode, this contains $s )
then
System.out.println( "both: " + $s );
end
如果必须使用ValidationBean,则可以从bean中引用列表:
$vb: ValidationBean( $sl1: stringList1 )
$s: String() from $sl1
ValidationBean( this == $vb, stringList2 contains $s )
这将为两个列表中包含的每个字符串激发
另一种方法是使用List.retainal()的DRL函数,类似
function boolean (List l1, List l2){
List is = new ArrayList( l1 );
is.retainAll( l2 );
return is.size() > 0;
}
或者让函数返回带有公共字符串的列表