gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:20:20 25 4
gpt4 key购买 nike

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

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 个或多个对象($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

关于java - 如何编写 Drools 规则来验证数组或列表中的多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43592927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com