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


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

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!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Alternative to TreeSet?
Date Tue, 07 May 2013 07:58:34 +0200
Lines 33
Message-ID <aurjgbFgviiU1@mid.individual.net> (permalink)
References <2ce32328-92a2-4fa3-8f23-27202009ac66@googlegroups.com> <ZXPht.9385$wS4.8978@newsfe30.iad>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net Gxp5DWoiy4ljyqNN0x5eUgL94ubRSRRVEkt5P2vshBfsati5k=
Cancel-Lock sha1:Jrb+wQ5TGvvS22aGsPVmhNtzWWs=
User-Agent Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
In-Reply-To <ZXPht.9385$wS4.8978@newsfe30.iad>
X-Antivirus avast! (VPS 130506-1, 06.05.2013), Outbound message
X-Antivirus-Status Clean
Xref csiph.com comp.lang.java.programmer:23883

Show key headers only | View raw


On 06.05.2013 17:25, Daniel Pitts wrote:
> On 5/6/13 8:10 AM, laredotornado@zipmail.com wrote:

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

> It sounds like you don't want a set, but a sorted bag.  There may be
> something in Apache Commons to solve this problem for you.  Depending on
> the size of the data set, I'd probably just use an ArrayList and call
> Collections.sort().

And there are methods for binary search which will help with finding 
element positions efficiently, e.g.
http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#binarySearch(java.lang.Object[], 
int, int, java.lang.Object)

I am not entirely sure though whether OP really wants a multiset (bag) 
or just a custom ordering which takes more fields into account.  It 
depends on the operations executed on the collection.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

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