Drools:为什么 indexOf() 在 LHS 中不起作用?
Drools: why indexOf() does not work in LHS?
为什么我不能使用 indexOf() 在 when
的 List 中查找特定对象的索引?
这是例子。一旦我注释掉 list.indexOf($o) > 0
,规则就会执行并且索引在 then
部分中显示正确。
declare Seq
list: List
end
rule "initSeq"
when
$p: ObjectWrapper (
...
)
$list: List () from collect (ObjectWrapper (...))
not initSeq (....)
then
Seq w = new Seq ();
w.setList($list);
end
rule "doSeq"
when:
$o: ObjectWrapper (
...
)
$rr: Seq (
...
list.indexOf($o) > 0
)
then:
DroolsLogger.debug ("index: " + $rr.getList().indexOf($o));
end
作为替代方案,您可以从模式中删除 list.indexOf($o) > 0
过滤器并添加新条件作为
eval($rr.getList().indexOf($o) > 0)
在规则的 when 部分。
我确认 indexOf() 在 LHS 中有效。
我仍然不明白为什么它以前对我不起作用,但现在我在 LHS 中使用了 indexOf 的工作规则。
为什么我不能使用 indexOf() 在 when
的 List 中查找特定对象的索引?
这是例子。一旦我注释掉 list.indexOf($o) > 0
,规则就会执行并且索引在 then
部分中显示正确。
declare Seq
list: List
end
rule "initSeq"
when
$p: ObjectWrapper (
...
)
$list: List () from collect (ObjectWrapper (...))
not initSeq (....)
then
Seq w = new Seq ();
w.setList($list);
end
rule "doSeq"
when:
$o: ObjectWrapper (
...
)
$rr: Seq (
...
list.indexOf($o) > 0
)
then:
DroolsLogger.debug ("index: " + $rr.getList().indexOf($o));
end
作为替代方案,您可以从模式中删除 list.indexOf($o) > 0
过滤器并添加新条件作为
eval($rr.getList().indexOf($o) > 0)
在规则的 when 部分。
我确认 indexOf() 在 LHS 中有效。 我仍然不明白为什么它以前对我不起作用,但现在我在 LHS 中使用了 indexOf 的工作规则。