Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Date: Sat, 06 Oct 2012 13:53:35 +0200 Lines: 62 Message-ID: <50701BBF.1020603@googlemail.com> References: <0fca6c33-cce6-410e-a8c9-cf503969a9ff@googlegroups.com> <8603e8f1-5c24-432a-b42a-540b44f8c577@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net bfBaM1fAQLUQpGUphGF8HQj/oakp9R4GvP7zCoSbj9ElZfreA= Cancel-Lock: sha1:OUPWGntcwQ2nHckgFUYreVBsTAA= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: <8603e8f1-5c24-432a-b42a-540b44f8c577@googlegroups.com> Xref: csiph.com comp.lang.java.programmer:19170 On 05.10.2012 20:05, Lew wrote: > Robert Klemme wrote: >> Lew wrote: >>> Robert Klemme wrote: >>> So what difference does the order make? >> >> There are some use cases described in the class JavaDoc. > > It doesn't explain how you reveal the order, only how you put it into another structure. Lew, I'm sorry, but I think you're overly picky here. >>> I can guess, but the docs don't confirm, that iterators off the keyset or entryset would >>> respect the order, but the documentation for the 'keySet()' and 'entrySet()' methods doesn't >>> promise this. >> >> >> You do not have to guess - logical reasoning is enough. The only way to >> iterate through a Map is via entrySet(), keySet() and values(). What >> other methods could make use of the order if not these? > > But these methods do not promise to return the data in any particular order, particularly > they do not promise to return the data in the order stored. In fact, they promise not to, > necessarily. From Set#iterator(): "The elements are returned in no particular order > (unless this set is an instance of some class that provides a guarantee)." Well, the entrySet() obtained for LHM does provide this guarantee. Even though it's not explicitly stated in comments for methods entrySet(), keySet() and values() because they are inherited the class level comment makes it clear that the ordering observed during iteration will usually be insertion order. I would conceded that the fact that you can also have access order if invoking one specific constructor is a not made explicit enough in the class JavaDoc. > The Map makes the guarantee, and one has to infer the underlying Set will therefore > make that guarantee, but when one copies the Map into another Map implementation, > even that implicit promise is removed. Furthermore, why do they not state that the Set > implementation iterator's order is guaranteed? It seems there's a hole in the docs. I think that clearly derives from the class comment because there is no other way to iterate a Map than through the three dependent collections (which usually include this comment in their accessor methods: "The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa."). >>> It's useful for subclasses, from what the documentation hints, but to the public? >> >> It seems you could create a LRU Map with this, right. Other uses are >> described in the class doc as mentioned above. > > Right, that LRU Map would be a subclass, as I said. And? Regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/