简体   繁体   English

比较Drools 6 when子句中集合中的不同项

[英]Comparing distinct items from collection in drools 6 when clause

I've searched around the internet but could not find an solution for a problem we are currently facing with drools (6.2.0). 我已经在互联网上进行搜索,但是找不到解决我们目前面临的问题的解决方案(6.2.0)。

Suppose i have a rule like this: 假设我有这样一条规则:

when
    $list: ProductList()
    $product: Product() from $list
    $product2: Product(this != product) from $list
then
    // do something
end

if $list contains 2 products, A and B, this rule will fire for combinations: 如果$ list包含2个产品A和B,则此规则将针对以下组合触发:

  1. AB AB
  2. BA BA

For some reason I am not able to make the rule fire only once (either ONLY AB or ONLY BA) 由于某种原因,我无法使规则仅触发一次(仅AB或BA)

Does anybody know if there is a standard way to achieve the desired result? 有人知道是否有一种标准的方法来达到预期的结果吗?

Many Thanks in advance! 提前谢谢了!

Regards, 问候,

Kim

You need to have a Product attribute that is comparable and unique. 您需要具有可比较且唯一的Product属性。 I'm assuming a product number: 我假设一个产品编号:

rule comp2prod
when
  $list: ProductList()
  $product: Product( $pn: productNumber ) from $list
  $product2: Product( productNumber > $pn ) from $list
then
  // do something
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM