我需要创建一个规则来检查List [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 。
答案 0 :(得分:1)
rule "New Assistance"
when
$room:Room($tags : tags contains "protocol")
then
System.out.println("Error");
end