在集合中找到除P之外的Drools约束对象 [英] Drools Constraint object other than P is found in collection

查看:194
本文介绍了在集合中找到除P之外的Drools约束对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图把这个打开和关闭很长时间。我可以想象很多非常冗长和非流动的方式去完成这个。但是,我想知道处理这种情况的最佳做法。我想知道如何在drools方言中写下面的约束。

I have been trying to figure this out on and off for a really long time. I can imagine a lot of very verbose and non-droolsy ways to go about accomplishing this. However, I would like to know the best practice for dealing with a situation like this. I would like to know how to write the constraint I describe below in the drools dialect.

我想写一个处理集合的约束。假设我们有CustomType,它有一个字段集合。约束应该表达我们想要找到CustomType的事实,它在集合中有指定对象(P)中的任何对象。最重要的是,如果指定的对象存在没关系。只有在集合中至少有一个其他对象才有意义。

I wish to write a constraint that deals with a collection. Let's say we have CustomType which has a field Collection. The constraint should express we want to find facts of CustomType who have any object in the collection other than the specified object(P). Critically, it does not matter if the specified object is present. It only matters if there is at least one other object in the collection.

问题集合不是集合。在同一个集合中可能有多个P实例。

The collection in question is not a set. It is possible there are multiple instances of P in the same collection.

在伪Java中,我可能会写一个类似的方法:

In pseudo Java I might write a method like:

public Boolean isThereANotP(CustomType cs){
for(str : cs.Collection){
    if(str != P){
        return true}
}
return false
}

这在流口水的when子句中表示?最接近我可以来指定有一个P,但这不是我想要的。我想知道

How would this be expressed in the when clause of a drool? The closest I could come is specifying there is not a P, but that isn't what I want. I want to know that there is a not P.

推荐答案

$c: CustomType()
$notP: Object(this != objectP) from $c.collection

实际上,这将激活集合中的每个对象,而不是objectP。这可能更好:

Actually that would activate for each object in the collection which is not objectP. This might be better:

$c: CustomType()
exists Object(this != objectP) from $c.collection

这篇关于在集合中找到除P之外的Drools约束对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆