drools arraylist收集访问对象

时间:2013-04-10 19:20:27

标签: drools

如何从项目ArrayList访问getter访问,这是Drools 5.5中collect的结果?

在类似于下面示例的代码中,我得到The method getStatus() is undefined for the type Object

我尝试过投射结果,我尝试了generics ArrayList<Alarm>

在一天结束时,我正在尝试访问ArrayList()中的两个项目。

rule "Raise priority if system has more than 3 pending alarms"
when
    $system : System()
    $alarms : ArrayList( size >= 3 )
              from collect( Alarm( system == $system, status == 'pending' ) )
then
    System.out.println($alarms.get(0)); // show Alarm.toString() 
    System.out.println($alarms.get(0).getClass()); // prints "Alarm"
    System.out.println($alarms.get(0).getStatus());

   // Raise priority, because system $system has
   // 3 or more alarms pending. The pending alarms
   // are $alarms.
end

0 个答案:

没有答案