在 drools 的列表中收集事实的任何特定属性值
Collect any particular attribute value of a fact in a list in drools
我有一个类似下面pojo的pojo
public class TestData {
int number;
String name;
//Getters, setters, rest of class
}
这个pojo的多个对象被插入到规则引擎中。现在我想要一个列表,其中 name attribute
通过规则从所有插入的 pojo 中收集。
即 List<String>
来自插入的 pojo 的名称。
谢谢
肖拉夫
这个非常简单的规则收集了 TestData 事实中的所有名称:
rule "collect names"
when
accumulate( TestData( $n: name ); $names: collectList( $n ) )
then
// ... $names is a List containing String objects
end
请注意,列表 $names
被编译为 List<?>
。右侧的处理可能必须将列表元素转换为 String
.
我有一个类似下面pojo的pojo
public class TestData {
int number;
String name;
//Getters, setters, rest of class
}
这个pojo的多个对象被插入到规则引擎中。现在我想要一个列表,其中 name attribute
通过规则从所有插入的 pojo 中收集。
即 List<String>
来自插入的 pojo 的名称。
谢谢 肖拉夫
这个非常简单的规则收集了 TestData 事实中的所有名称:
rule "collect names"
when
accumulate( TestData( $n: name ); $names: collectList( $n ) )
then
// ... $names is a List containing String objects
end
请注意,列表 $names
被编译为 List<?>
。右侧的处理可能必须将列表元素转换为 String
.