You have to establish the age of one applicant as bound to a variable so that you
can ascertain this being equal to the age of all Applicants.
rule "age-2"
when
$list : List( size > 0 ) # ensure non-empty so that get(0) doesn't NPE
forall( Applicant( $age : age == ( ((Applicant)$list.get(0)).getAge() ) ) from $list )
then
System.out.println( "success" );
end
On 15 September 2010 09:52, tushmish
<Tushar.Mishra@lntinfotech.com> wrote:
rule "age"
when
$list : List();
forall( $app : Applicant( $age : age) from $list
Applicant( this == $app, age == $age ) );
then
System.out.println("success" );
end
It's noteworthy that this rule would fire if you insert all Applicant objects that are in the List as 1st order facts. What is does is
forall( $app | $app in List &
forall ( $f | $f in WM & $f instanceof Applicant & $f == $app & $f.age == $app.age ) )
where the inner "forall" is implied by the general fact matching algorithm. The last term of the inner conjunction is redundant as we have established the identity by $f == $app - the pattern just matches all list elements with themselves.
-W