[rules-users] Comparing multiple instances of the same object

Edson Tirelli tirelli at post.com
Wed Sep 26 07:45:30 EDT 2007


    Brian,

    Maybe you have equals() method implemented in the class? "==" will call
equals() method on the objects...
    I assume you are using 4.0.1 or later (snapshot).

    []s
    Edson

2007/9/25, Brian Enderle <brianke at gmail.com>:
>
> 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
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070926/6e73437c/attachment.html 


More information about the rules-users mailing list