如何解决Drools规则左侧的“ this”等效关键字
给定一个配置类Config,其中包含属性excludeShifts(这是Shift类的列表),是否存在像“ this”这样的关键字表示匹配过程中的当前对象?例如,
rule "Match but not if excluded"
when
$config : Config(...) // additional matching criteria deleted
$shift : Shift(this not memberOf $config.excludeShifts,... // additional criteria deleted
)
... // additional criteria deleted
then
...
end
我认识到在功能上,我可以使用以下命令来实现此匹配:
$shift : Shift()
$config : Config(excludeShifts not contains $shift
)
解决方法
this
是一个公认的关键字,其使用方式与您指示的方式相同,用作对要评估的当前对象的引用。
一些例子:
// An even integer in working memory
$even: Integer( this % 2 == 0 )
// A string with a specific value
$animal: String(this in ("cat","dog","fish"))
// A value from a map
Map( $value: this['key'] )
您的示例与您编写的示例一样有效。
rule "Match but not if excluded"
when
$config : Config($excluded: excludedShifts)
$shift : Shift(this not memberOf $excluded)
then
end
我拨通了documentation,但看不到是否曾经this
被用作关键字(尽管要搜索它有点困难。)在一些示例中使用了它。 ,例如,在forall
运算符示例代码中。正如Esteban在评论中所建议的那样,欢迎您打开错误报告或提交文档修订以纠正这种疏忽。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。