我需要创建一个规则来检查列表[String]中是否存在字符串的一部分。有什么办法可以做到吗?
我正在尝试使用包含,但它不起作用。
rule "New Assistance"
when
$room:Room($tags : tags)
//$room:Room(tags contains "protocol")
$value:String() from $tags
//Boolean(booleanValue == true) from $value == "protocol"
Boolean(booleanValue == true) from $value.contains("protocol")
then
System.out.println("Error");
end
这是我的代码
...
val room = new Room(null, List[User](), List[Message](message),
new Date, null, List[String]("protocol"))
kieSession.insert(room)
kieSession.fireAllRules()
....
谢谢!
//测试java
import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<String> tags = new ArrayList<>();
tags.add("protocol");
Room room = new Room(tags);
System.out.println(room.tags.contains("protocol") );
}
}
class Room {
public List<String> tags;
public Room(List<String> tags){
this.tags = tags;
}
}
//测试 scala
val room = new Room(null, List[User](), List[Message](message),
new Date, null, List[String]("protocol"))
var xx = room.tags.contains("protocol")
两者都返回true。
最佳答案
rule "New Assistance"
when
$room:Room($tags : tags contains "protocol")
then
System.out.println("Error");
end
关于java - Drools - 检查列表中是否存在/包含字符串<String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326953/