[rules-users] using forall to validate same field value from a list

tushmish Tushar.Mishra at lntinfotech.com
Wed Sep 15 03:52:06 EDT 2010


Hi, 

My requirement is to check for same field value from a list of items. in the
test case mentioned below, I want to verify that all the applicants are of
same age. 

I am running the rule as mentioned below. The 'then' part does not execute.
Please suggest. 

Thanks for your time. 

public class Applicant { 

        private String name; 
        private int age; 
        private BigDecimal amount; 

        // getter and setters 

} 

rule "age" 
        when 
                $list : List();     
                forall( $app : Applicant( $age : age) from $list 
                   Applicant( this == $app, age == $age ) ); 

        then 
                System.out.println("success" ); 
                
end 

// setting data in working memory 
Applicant applicant1 = new Applicant("aaaa", 20, new BigDecimal(16.50)); 
Applicant applicant2 = new Applicant("aaaa", 20, new BigDecimal(16.50)); 
Applicant applicant3 = new Applicant("aaaa", 20, new BigDecimal(16.50)); 

List<Applicant> list = Arrays.asList(new Applicant[] { applicant1,
applicant2, applicant3 }); 
ksession.insert(list); 

Regards, 
Tushar 
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/using-forall-to-validate-same-field-value-from-a-list-tp1478178p1478178.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list