流口水-检查List< String>中是否存在/包含字符串 [英] Drools - check if exists/contains string in a List<String>
本文介绍了流口水-检查List< String>中是否存在/包含字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个规则来检查List [String]中是否存在一部分字符串。我有办法做到吗?
I need to create a rule to check if a part of string exists inside a List[String]. Is there a way that i could do it?
我正在尝试使用包含,但是它不起作用。
I'm trying using contains but it's not working.
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
// tests 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
这篇关于流口水-检查List< String>中是否存在/包含字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文