[rules-users] Test for element in an arraylist
Bojan Janisch
bojan.janisch at scai.fraunhofer.de
Wed Jan 16 12:03:36 EST 2013
Nah thats not gonna work, because I'm using
an ArrayList as a global variable. I'm adding
and removing ODMAnswers in it and always want to
check if there are 2 ODMAnswers in it, to remove
them and generate a new one.
Of course I differ them in their properties, just
wanted to keep the problem simple and understandable.
Do you got another option than creating a local
$list variable?
----- Ursprüngliche Mail -----
Von: "Jeremy Ary" <jeremy.ary at gmail.com>
An: "Rules Users List" <rules-users at lists.jboss.org>
Gesendet: Mittwoch, 16. Januar 2013 17:54:32
Betreff: Re: [rules-users] Test for element in an arraylist
I should note that hopefully you can limit this to something like $list : ODAList ( ) (a specific extends type of list where you could specify some criteria to be more specific with) or can assure that you only have one List in play at that time, or you're going to spend some execution going through every List in memory to check for these occurrences.
Jeremy
On Wed, Jan 16, 2013 at 10:50 AM, Jeremy Ary < jeremy.ary at gmail.com > wrote:
Argh...Sorry, wrong key too early...here's the full changes:
rule "Combine ODMAnswers"
when
$list : List( )
$a1:ODMAnswer( some check ) from $list $a2:ODMAnswer( assuming something making this one different than $a1 ) from $list
then
$list.add( new ODMAnswer( ) );
$list.remove($a1);
$list.remove($a2);
end
On Wed, Jan 16, 2013 at 10:47 AM, Jeremy Ary < jeremy.ary at gmail.com > wrote:
Try this;
rule "Combine ODMAnswers"
when
$a1:ODMAnswer( some check )
$a2:ODMAnswer( assuming something making this one different than $a1 )
eval(odmList contains $a1 && odmList contains $a2)
then
ODMAnswer answer = new ODMAnswer( );
odmList.add(answer);
odmList.remove($a1);
odmList.remove($a2);
end
On Wed, Jan 16, 2013 at 10:41 AM, Bojan Janisch < bojan.janisch at scai.fraunhofer.de > wrote:
rule "Combine ODMAnswers"
when
$a1:ODMAnswer( )
$a2:ODMAnswer( )
eval(odmList contains $a1 && odmList contains $a2)
then
ODMAnswer answer = new ODMAnswer( );
odmList.add(answer);
odmList.remove($a1);
odmList.remove($a2);
end
_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list