2014-04-02 26 views
0

我想獲取列表中的字符串<字符串>但沒有工作。Drools:如何獲取列表中的字符串<String>

Drools的規則

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 

結果返回名單,但我得到從這個列表中的所有字符串。

結果:仍然列出<字符串>

Test1: [email protected] 

Control_Exam_List類:名單<字符串>

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

回答

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 
+0

可能陣列字符串比較在Drools中的字符串? –

+0

運算符包含用於檢查作爲集合或數組的字段是否包含指定的值。請參閱Drools「專家」手冊。 – laune

相關問題