比较DROOLS中两个列表中的值

时间:2013-02-08 09:21:33

标签: drools

我刚刚开始使用drools规则引擎。我在一个事实中有两个列表,并且希望迭代地使用它们内部的值。我尝试了一个小东西,但它没有工作。我需要在drools中实现类似嵌套for循环的东西。在两个列表中,一个是String类型,另一个是用户定义的对象。

rule "for the Handling Exception"

when
$billInfo : BillingInfo ( $except : exceptions , $handException : handlingExceptions , $rate : rate , $price : price);

  HandlingException ( $exc : exceptionValue ; $exce : this  )from $except
 exists ( String ( $handExc : this == $exc  ) from $handException)
then 

$billInfo.setPrice($price + ($rate * $exce.getDiscount()) );


end

以上,除了是用户定义的列表,$handexception属于String

1 个答案:

答案 0 :(得分:0)

如果您要实现的目的是检查BillingInfo中是否至少有一个HandlinExpection($ h)和一个字符串($ s),来自handlingExceptions,这样:$ h.exceptionValue == $ s ,你可以这样做:

when
    $b: BillingInfo()
    exists (
        $h: HandlingException(exceptionValue memberof $b.handlingExceptions) from $b.exceptions
    )
then

end

希望它有所帮助,

相关问题