JDK-4848853 : (coll) Modify LinkedHashMap and LinkedHashSet to include first() and last()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux,windows_2000
  • CPU: x86
  • Submitted: 2003-04-15
  • Updated: 2016-11-29
Related Reports
Duplicate :  
Duplicate :  
Description
eldes 

Name: rmT116609			Date: 04/15/2003


A DESCRIPTION OF THE REQUEST :
In working with the LinkedHashMap class a bit recently, I think I've found a few additional convenience methods that could prove useful. The following is a list:

1. A method to get the first node in the list.  After a quick glance at the code, this seems like it would simply involve accessing the 'header' entry.
2. A method to get the last, or eldest entry in the list.  If I'm not mistaken, this seems like it would be the 'header.before' entry.
3. A method to support reverse iteration.  Since it is a doubly-linked list, once again, easy modification.
4. A method, given a key, to start iteration at that key's point in the list.

JUSTIFICATION :
1. Once again, if I'm correct, the only way to get the last (eldest) entry is to traverse the whole list via the iterator.
2. Reverse iteration would be even more complex.
3. Starting iteration given a particular key would involve a sequential search in traversing the list.
(Review ID: 184177) 
======================================================================

Comments
EVALUATION It is worth investigating whether retrofitting LinkedHashSet to implement the new Deque interface, as was done with LinkedList, would be easy to do.
05-08-2005

EVALUATION All of fancy (ordered) maps and sets (TreeMap/Set, LinkedHashMap/Set) are somewhat lacking in "navigation ability." It would be straightforward to add these operations, but somewhat in conflict with the Collection Framework's "interface-based" philosophy. If there is sufficient demand, we may do it anyway. ###@###.### 2003-06-19
19-06-2003