I'm finding the same object twice in my HashSet, and since I'm building
that HashSet using
Set getSelectedContentItems()
{
Set ciSet = new HashSet();
Iterator chIt = children.iterator();
while (chIt.hasNext())
{
TreeNode child = (TreeNode)chIt.next();
ciSet.addAll(child.getSelectedContentItems());
}
ciSet.add(myContentItem);
return ciSet;
}
I'm wondering if somehow addAll is adding things without enforcing the
Set's constraint against duplicate items. I've already checked that the
class "MyContentItem" class has a "public boolean equals(Object other)"
method.

Signature
Paul Tomblin <ptomblin@xcski.com> http://blog.xcski.com/
Networks are like sewers ... My job is to make sure your data goes
away when you flush, and to stop the rats climbing into your toilet
through the pipes. -- Network administration, as told by Tanuki
Daniel Dyer - 08 Dec 2006 19:27 GMT
> I'm finding the same object twice in my HashSet, and since I'm building
> that HashSet using
[quoted text clipped - 16 lines]
> class "MyContentItem" class has a "public boolean equals(Object other)"
> method.
Does it also over-ride hashCode(), and are the two methods consistent with
each other?
Dan.

Signature
Daniel Dyer
http://www.uncommons.org
Thomas Hawtin - 08 Dec 2006 19:32 GMT
> I'm finding the same object twice in my HashSet, and since I'm building
^^^^
> that HashSet using
> Set's constraint against duplicate items. I've already checked that the
> class "MyContentItem" class has a "public boolean equals(Object other)"
> method.
And an @Override public int hashCode()?
Tom Hawtin
Paul Tomblin - 08 Dec 2006 19:48 GMT
In a previous article, ptomblin+netnews@xcski.com (Paul Tomblin) said:
>Set's constraint against duplicate items. I've already checked that the
>class "MyContentItem" class has a "public boolean equals(Object other)"
>method.
Thomas and Daniel hit the nail on the head - I forgot to override
hashCode. Thanks.

Signature
Paul Tomblin <ptomblin@xcski.com> http://blog.xcski.com/
C has features?? I thought the whole point of that language was to
offer nothing but bare metal.
-- David P. Murphy