United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4155650 (coll) Sorted Collection Classes with bidirectional navigation
JDK-4155650 : (coll) Sorted Collection Classes with bidirectional navigation

Details
Type:
Enhancement
Submit Date:
1998-07-08
Status:
Resolved
Updated Date:
2012-12-19
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
generic
Sub-Component:
java.util:collections
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0
Fixed Versions:

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

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
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.
======================================================================
                                     
2004-09-08
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
                                     
2005-05-10



Hardware and Software, Engineered to Work Together