commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [Collections] What collection fits my problem?
Date Wed, 16 Mar 2005 02:38:23 GMT
Hmm..my understanding of "Bag" would have matched Mike Zatko's, ie it is
a collection where multiple instances of identical objects can be added,
and those *instances* are added to the collection.

I have therefore attached a patch that updates the javadoc for class
o.a.c.c.Bag to make this clear. I hope these changes are acceptable.

Note that the javadoc changes I have made indicate that when duplicate
objects are added, a reference to the *first* added object is retained.
If this is not the case, then this would need to be updated.

Thanks,

Simon

On Tue, 2005-03-15 at 22:51 +0000, Stephen Colebourne wrote:
> You describe the correct behaviour of SortedBag, and collections in general. 
> Most collections use .equals() comparisons.
> 
> You have two choices:
> a) Write a sorted collection that uses == for comparison instead of .equals
> 
> b) Use a TreeSet, but wrap each of your objects in an inner class style 
> wrapper, eg:
> public class Wrapper {
>   public Object realData;
> }
> 
> Stephen
> 
> ----- Original Message ----- 
> From: "Mike Zatko" <mzatko@boscovs.com>
> > FYI, I did try a sorted bag which appeared to be what I was looking for. 
> > But, for some reason if you add 2 identical objects (deep copied) and add 
> > them to the bag, it will merely overwrites the first objects reference 
> > with the second objects reference. To me, this seems like it would be a 
> > bug, but I could be wrong. Any thoughts?
> >
> >
> > Mike Zatko wrote:
> >
> >> I need a sorted collection that also allows deep copied duplicate objects 
> >> (exact same object, different memory addresses). Is there a collection 
> >> that fits that requirement? I've been having difficulty finding one 
> >> myself. Thanks for any help.
> >>

Mime
View raw message