Drools:如何在List <string> </string>中获取String

时间:2014-04-02 07:31:46

标签: string list drools

我想在列表中获取字符串&lt;字符串&gt;但是没有用。

Drools Rule

import schedule.Schedule
import schedule.Control_Exam_List

rule "People"
    salience 5
    when
        $controlExamList : Control_Exam_List( ) from accumulate( $scheduleCheck : Schedule( $scheduleCECheck1 : control1 , $scheduleCECheck2 : control2 , $scheduleCECheck3 : control3 ) ,
                              init( Control_Exam_List CEL = new Control_Exam_List(); ),
                              action( CEL.addData($scheduleCECheck1); CEL.addData($scheduleCECheck2); CEL.addData($scheduleCECheck3); ),
                              result( CEL ) )
    then
        System.out.println("Test1: "+$controlExamList);
end

结果返回列表但我从此列表中获取所有字符串。

结果:仍然列表&lt;字符串&gt;

Test1: schedule.Control_Exam_List@22916a

Control_Exam_List类:列表&lt;字符串&gt;

import java.util.ArrayList;
import java.util.List;

public class Control_Exam_List {
    private List<String> code = new ArrayList<String>();

    public void addData(String code){
        if(this.code.contains(code) != true && !code.equals(""))
            this.code.add(code); 
    }

    public List<String> getCode() {
        return code;
    }
}

日程安排课程:从此课程累积

public class Schedule {

    private String control1 = "", control2 = "", control3 = "";

    public String getControl1() {
        return control1;
    }

    public String getControl2() {
        return control2;
    }

    public String getControl3() {
        return control3;
    }

    public void setControlExam1(String ce_code) {
        this.control1 = ce_code;
    }

    public void setControlExam2(String ce_code) {
        this.control2 = ce_code;
    }

    public void setControlExam3(String ce_code) {
        this.control3 = ce_code;
    }
}

1 个答案:

答案 0 :(得分:0)

这几乎和Java一样,$controlExamList绑定到Control_Exam_List对象;虽然,在Drools,你可能需要施展:

then
  for( Object obj: $controlExamList.getCode() ){
    System.out.println( (String)obj );
  }
end

但你也可以尝试:

then
  for( String str: $controlExamList.getCode() ){
    System.out.println( str );
  }
end