Question

I want to get String in List< String > but did not work.

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

The result return list but I get all string from this list.

Result : Still list< String >

Test1: schedule.Control_Exam_List@22916a

Control_Exam_List Class : List< String >

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

Schedule Class : Accumulate from this class

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;
    }
}
Était-ce utile?

La solution

This is almost as you'd do it Java, with $controlExamList being bound to a Control_Exam_List object; although, in Drools, you may have to cast:

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

But you can also try:

then
  for( String str: $controlExamList.getCode() ){
    System.out.println( str );
  }
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top