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


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

Re: Glitch in Java Collections (No descendingMap in LinkedHashMap)

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Glitch in Java Collections (No descendingMap in LinkedHashMap)
Date 2012-10-06 13:53 +0200
Message-ID <50701BBF.1020603@googlemail.com> (permalink)
References <k4jua8$77d$1@news.albasani.net> <ad6bpvFcuttU1@mid.individual.net> <0fca6c33-cce6-410e-a8c9-cf503969a9ff@googlegroups.com> <ad8im6FsiqpU1@mid.individual.net> <8603e8f1-5c24-432a-b42a-540b44f8c577@googlegroups.com>

Show all headers | View raw


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/

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


Thread

Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-04 14:09 +0200
  Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-04 23:01 +0200
    Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-04 14:43 -0700
      Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 00:17 +0200
      Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-05 19:11 +0200
        Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-05 11:05 -0700
          Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 20:18 +0200
          Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-05 12:06 -0700
            Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-05 13:04 -0700
              Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 23:44 +0200
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-05 23:50 +0200
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 00:00 +0200
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-10-05 23:39 +0000
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 12:18 +0200
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-06 12:22 +0200
              Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-10-05 15:51 -0700
          Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Robert Klemme <shortcutter@googlemail.com> - 2012-10-06 13:53 +0200
  Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-09 14:16 -0600
    Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 09:00 -0600
      Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-10 11:34 -0400
        Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 10:28 -0600
          Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 11:45 -0600
            Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Lew <lewbloch@gmail.com> - 2012-10-10 10:52 -0700
              Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 12:47 -0600
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-11 14:17 -0600
            Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-10 18:20 -0400
              Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-10 16:51 -0600
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-12 14:34 +0200
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jim Janney <jjanney@shell.xmission.com> - 2012-10-12 09:12 -0600
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-12 11:42 -0400
                Re: Glitch in Java Collections (No descendingMap in LinkedHashMap) Jan Burse <janburse@fastmail.fm> - 2012-10-12 21:02 +0200

csiph-web