如何编写 Drools 规则来验证数组或列表中的多个值

How to write Drools rule to validate several values in an array or list

我有一个包含集合或值数组的数组。 我想写一个这种形式的规则:

rule "listRule"

when 
$first: from list1() and $first!= "a" and $first!="b"
$second: from list1() and $second!="c" and $second != "z"
then
System.out.println(" this works!")

end

objective 是为了能够评估列表或数组是否具有 2 个或更多对象($first、$second 等),每个对象都满足它们的不同条件。它可以是数组或列表。

插入多个 String[]List<String> 对象几乎肯定不是一个好主意,因为您将无法识别这些对象。但方法如下:

rule "listRule"
when
    $list: ArrayList()
    $s1: String( toString != "a" && != "b" ) from $list
    $s2: String( this != $s1, toString !="c" && != "z" ) from $list
then
    System.out.println( "Strings: " + $s1 + " - " + $s2 );
end