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


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

Re: Alternative to TreeSet?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Alternative to TreeSet?
Date 2013-05-06 11:19 -0400
Organization A noiseless patient Spider
Message-ID <km8hel$fh4$1@dont-email.me> (permalink)
References <2ce32328-92a2-4fa3-8f23-27202009ac66@googlegroups.com>

Show all headers | View raw


On 5/6/2013 11:10 AM, 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.

     None that I know of.

> 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.

     Sounds like the compareTo() method should take the products' other
attributes into account, and not use the order ID alone. If compareTo()
is not easily changed (for example, if some other piece of the system
relies on its ID-only sensitivity), use a TreeSet with a custom
Comparator.

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next 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