Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #23897

Re: Alternative to TreeSet?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail
From Sven Köhler <remove-sven.koehler@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Alternative to TreeSet?
Date Tue, 07 May 2013 19:36:44 +0300
Lines 25
Message-ID <ausosuFp51dU1@mid.dfncis.de> (permalink)
References <2ce32328-92a2-4fa3-8f23-27202009ac66@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.dfncis.de B5X8Dc8w4Jm094oSEjlS4gefs73/jFIHMmkmu+r0rujhVSvNDTduvAAfa4
Cancel-Lock sha1:sx1bnRsCHsNxxlDswmTdW6kjqCQ=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130404 Thunderbird/17.0.5
In-Reply-To <2ce32328-92a2-4fa3-8f23-27202009ac66@googlegroups.com>
Xref csiph.com comp.lang.java.programmer:23897

Show key headers only | View raw


On 05/06/2013 06:10 PM, laredotornado@zipmail.com wrote:
> Hi,
>
> We're using Java 6.  Is there a java.util.Set data structure that can
> return a sorted list of elements and can contain two elements even if
> compareTo returns 0 against those two elements but calling equals
> against the two elements returns false?  TreeSet doesn't do the job.

Implement a Comparator and pass it to the TreeSet. The Comparator can 
sort objects for which equals returns false in any arbitrary (but 
deterministic) order.

> In our example, we have products with an order ID column, so two
> products could have the same order ID but may not be equal.  We would
> like to sort the products based on this order ID, however.

The Comparator would sort the products based on their ID first - and if 
the IDs are equal it would sort them based on other attributes.

Is that what you want?



Regards,
   Sven

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Alternative to TreeSet? laredotornado@zipmail.com - 2013-05-06 08:10 -0700
  Re: Alternative to TreeSet? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-06 11:19 -0400
    Re: Alternative to TreeSet? Lew <lewbloch@gmail.com> - 2013-05-06 11:33 -0700
    Re: Alternative to TreeSet? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-05-06 18:01 -0300
  Re: Alternative to TreeSet? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-06 08:25 -0700
    Re: Alternative to TreeSet? Robert Klemme <shortcutter@googlemail.com> - 2013-05-07 07:58 +0200
  Re: Alternative to TreeSet? Roedy Green <see_website@mindprod.com.invalid> - 2013-05-07 09:21 -0700
  Re: Alternative to TreeSet? Sven Köhler <remove-sven.koehler@gmail.com> - 2013-05-07 19:36 +0300

csiph-web