JDK-4155650 : (coll) Sorted Collection Classes with bidirectional navigation
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 1998-07-08
  • Updated: 2017-05-16
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description

Name: rm29839			Date: 07/08/98


I am trying to do some interpolation, at Reuters.

A clean implementation is to use the 

map.get( key ) 

to return an interpolated value, if the real value does not exist.

However in doing this I would like to access 
n-keys either side of the key I am requesting. 

The current SortMap interface only allows me to get at the value either side of the key value (using headMap.lastKey() & 
tailMap.firstKey() ).

This is inadequate for some kinds of interpolation where I need several keys either side of the key in question.

As a general solution to this problem it seems reasonable that Sorted classes should return a ListIterator as well as an iterator.
(Review ID: 34731)
======================================================================

Comments
EVALUATION It is easy to get multiple entries *following* a given key, merely by iterating over tailMap(k).entrySet(). It is more difficult to get multiple keys preceding a given key. (You're stuck doing the headMap(k).lastKey() trick repeatedly, which is ugly and not very efficient.) We initially did provide a List view of SortedMap (actually TreeMap), but backed away from this as it required implementers to support "rank operations" (i.e., positional access to SortedMap entries). This is a significant burden for many Map implementations, including Red-Black trees. It would be nice if we could provide iteration without providing positional access, but the current interfaces don't make this easy. I'll continue to think about this problem, in the hope that it can be addressed prior to FCS. joshua.bloch@Eng 1998-07-21 Bidirectional navigation will be addressed by the Navigable* interfaces, the higher/lower/ceiling/floor methods, the descending iterator methods, implemented in TreeMap and TreeSet and the new ConcurrentSkipList* classes, coming with the integration of JSR166x. ###@###.### 2005-05-10 02:34:56 GMT
10-05-2005

WORK AROUND Name: rm29839 Date: 07/08/98 Add a method to sorted collection classes public ListIterator listIterator(); as well as public ListIterator listIterator( Object key ); where the list iterator will start at (or before)the key. ======================================================================
08-09-2004