gpt4 book ai didi

java - Drools - 检查列表中是否存在/包含字符串

转载 作者:行者123 更新时间:2023-11-30 03:34:22 25 4
gpt4 key购买 nike

我需要创建一个规则来检查列表[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/

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