Drools - 如何从 ArrayList 中获取 String[]

Drools - How to get String[] from ArrayList collect

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);

结束

我得到一个 arrayList $y 并希望生成一个 String[] 数组用作 memberOf 中的条件。如何实现这种转变?

这是演示中使用的Class: Class 员工执行代码:

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 */
}

Class 员工异常:

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

Class 工作人员:

public class Staff {
    private String StaffCode;

    private String StaffName;

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

Class 公司:

public class Company {
    private int CompanyCode;

    private String CompanyName;

    private int StaffNumber;

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

我不确定我是否做对了,因为您没有发布规则应该做什么的声明,或者(甚至更好)具有预期结果的数据集。 (如果您坚持通常的 JavaBeans 约定,StaffException 中的 exc$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

如果您将 Staff 和 StaffExcCode 作为事实插入,而不是从包含的事实对象中提取它们,那就更简单了。