2017-04-24 27 views
0

我有一個包含一個Collection或一組值的數組。 我想寫這種形式的規則:如何編寫Drools規則來驗證數組或列表中的多個值

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 

的目標是能夠評估如果列表或陣列具有2個或更多個對象($第一,$第二等等),每個滿足他們的不同狀況。它可以是一個數組或列表。

回答

1

插入多個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 
+0

爲我工作。感謝你的回答。我可以有一個還是在那裏?從$ list 或$ s2:String(this!= $ s1,toString!=「c」&&!=「z」)從$ s1:String(toString!=「a」&&!=「b」)from $ list列表 –

+0

是的。用括號圍繞兩個模式。 ---但它沒有意義,因爲可以以更簡單的方式實現相同的效果。 – laune