java - 如何使用drools文件中的索引/索引遍历列表
问题描述
我需要使用 drools 文件中的索引遍历列表,因为我想将列表中的值与列表中的下一个值进行比较。一种方法是使用from
关键字来获取单个列表项,但我也需要索引
value : String() from $listOfString
解决方案
通过在 when 中访问列表并在 then 子句中循环遍历它来解决它
rule "Iterate and compare"
when
$list : ArrayList()
then
for (int i = 0; i < $list.size(); i++) {
if (list.get(i) comapred to list.get(i+1)) {
// insert/aggregate the result
}
}
end
推荐阅读
- jar - Java 11 是否支持 adal4j-1.6.2.jar
- extjs - ExtJS 4.2 可编辑组合奇怪行为
- ruby-on-rails - Rails 5.2 和 Sidekiq 5:Errno::EADDRNOTAVAIL:无法分配请求的地址 - “localhost”端口 25 的连接(2)
- node.js - 如何返回值然后捕获块
- angularjs - 如何将活动选项卡绑定到范围内数组的最后一个元素
- spring-boot - 不从属性文件中选择 Redis 的属性
- jenkins - 将 Jenkinsfile 脚本移植到声明性 withEnv{} => environment{} 的问题
- python - Pandas DataFrame 中嵌套列表的列太多错误
- jquery - 附加到DOM树后克隆元素上的jQuery附加方法
- php - 从对象内部的数组创建对象