Using your idea, I added an == comparison inside the compareTo() method. (I didn't have to change the equals() method)

if(this==otherObject)
   return 0;
else
   return -1;

I beleive this does break the compareTo contract to some extent, but it does work.



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" <[EMAIL PROTECTED]>

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.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to