2016-11-22 21 views
0
rule "Your First Rule" 
no-loop 
salience 10 
when 
    $c : Company() 
    // $e : String() 
    $e : StaffException() 
    $r : StaffExcCode($r.getCode() == "1") from $e.getStaffException() 
    $y : ArrayList() 
     from collect (String() from $r.getStaffExc()) 
     $ee : Staff(StaffCode not memberOf($y)) from $c.getStaffInfo() 

then 
    //actions 
    System.out.println("Satisfied." + $y); 
    //System.out.println("Satisfied." + $ee); 

Drools的 - 如何获得的String []从ArrayList中收集

我的ArrayList $ y和希望产生一个String []数组作为的memberOf的条件来使用。如何才能实现这一转变?

这是在演示中使用的类: 类StaffExcCode:

public class StaffExcCode { 
    private String StaffExc; 
    private String code; 

    public StaffExcCode(String StaffExc, String code) { 
     this.StaffExc = StaffExc; 
     this.code = code; 
    } 
    /* ignore the get and set */ 
} 

类StaffException:

public class StaffException { 
    private List<StaffExcCode> exc; 
    /* ignore the get and set */ 
} 

一流的工作人员:

public class Staff { 
    private String StaffCode; 

    private String StaffName; 

    private int StaffAge; 
    /* ignore the get and set */ 
} 

类公司:

public class Company { 
    private int CompanyCode; 

    private String CompanyName; 

    private int StaffNumber; 

    private List<Staff> StaffInfo; 
    /* ignore the get and set */ 
} 
+0

我会尝试重写规则,以便它能够正常工作,但是由于您发布的规则的不完整和不一致的片段,所以这是不可能的。编辑,提供有关相关课程和相关领域的精确类型信息。 – laune

+0

Updated ..谢谢你的帮助。 – Calvin

回答

0

我不知道我是否正确,因为您没有发布声明规则应该做什么或(甚至更好)具有预期结果的数据集。 (如果你坚持通常的JavaBeans约定,excStaffException不匹配$e.getStaffException()。)

我不认为你必须收集数据到列表;还有就是not CE可以应用到图案

rule "Your First Rule" 
when 
    $c : Company($si: staffInfo) 
    $staff: Staff($staffCode: staffCode, $sn: staffName) from $si 
    StaffException($exc: exc) 
    not StaffExcCode(staffExc == $staffCode, code == "1") from $exc 
then 
    System.out.println("Satisfied: " + $sn); 
end 

如果你插入的工作人员和StaffExcCode的事实,而不是从包含事实对象提取出来这将是更简单。

相关问题