[rules-users] Constraints over Lists
Wolfgang Laun
wolfgang.laun at gmail.com
Tue Jan 22 06:43:35 EST 2013
On 22/01/2013, Phani Saripalli <saripalli.phani at gmail.com> wrote:
> Hi, I have a query reg. writing constraints over lists.
The combination of dialect "mvel" and DRL functions appears to cause
an exception, due to a bug (in 5.5.0).
Below is code that works although I doubt whether neqq implements what
I guess that you think it should.
-W
function boolean isDefined(Object ob) {
return ob != null;
}
function boolean neqq(List l1, List l2) {
return l1 != l2;
}
declare Project
@typesafe (false)
list1 : List
list2 : List
end
rule kickoff
salience 999999
when
then
insert( new Project() );
insert( new Project() );
end
rule " Config rule "
no-loop true
when
P : Project()
then
modify(P) {
setList1( Arrays.asList(10, 15, 20, 25) ),
setList2( Arrays.asList(11, 2, 3, 4, 5, 10, 9, 8, 7) )
};
end
rule "listEq1"
when
P : Project()
eval( isDefined(P.list1)
&&
neqq(P.getList1(), new ArrayList(Arrays.asList(1, 2, 3))))
then
System.out.println("Lists are not equal - 1");
end
rule "listEq2"
when
P : Project()
eval( isDefined(P.getList1()) && isDefined(P.getList2())
&& neqq(P.getList1(), P.getList2() ) )
then
System.out.println("Lists are not equal - 2");
end
More information about the rules-users
mailing list