[rules-users] Comparing multiple instances of the same object
Brian Enderle
brianke at gmail.com
Tue Sep 25 17:35:19 EDT 2007
I have 3 Rfrnc objects that I would like to compare and return a message if
the firstNm, middleNm and lastNm of two objects match. I set up the Rfrnc
objects with the names "Brian A Enderle", "Brian B Enderle" and "Brian C
Enderle" and created the following rule (with the intent of building up to
checking first, middle and last name).
rule "LevelTwo: Duplicate Reference check"
agenda-group "LevelTwo"
when
$i : Rfrnc($firstNm : firstNm, $middleNm : middleNm, $lastNm :
lastNm)
$j : Rfrnc(this != $i, firstNm == $firstNm)
then
System.out.println("Duplicate refernce found: " +
$i.getMiddleNm() + $i.getLastNm() + ":" + $j.getMiddleNm() + $j.getLastNm());
end
This produces the following output (which is what I would expect):
Duplicate refernce found: CEnderle:BEnderle
Duplicate refernce found: BEnderle:CEnderle
Duplicate refernce found: CEnderle:AEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: AEnderle:BEnderle
Duplicate refernce found: BEnderle:AEnderle
While doing some testing I changed "Brian B Enderle" to "Brian A Enderle" so
that now I have two Rfrnc objects with the name of "Brian A Enderle". When I
rerun the same rule from above I get the following output:
Duplicate refernce found: CEnderle:AEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: AEnderle:CEnderle
Duplicate refernce found: CEnderle:AEnderle
What I don't understand is why do I not have any return statements
of "Duplicate reference found AEnderle:AEnderle". I would expect 2 of these
messages, one for when the first "Brian A Enderle" object is compared to the
second and vice versa.
Is the "$i == this" condition checking values within the object itself? Am I
missing something here as to how this rule should work?
Thanks in advance,
Brian Enderle
More information about the rules-users
mailing list