United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4294891 : (coll) Add "next/previous" to both SortedMap and SortedSet

Details
Type:
Enhancement
Submit Date:
1999-11-27
Status:
Resolved
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
windows_nt
Sub-Component:
java.util:collections
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.2.0
Fixed Versions:

Related Reports

Sub Tasks

Description

Name: krT82822			Date: 11/27/99


orig synopsis:  "Incomplete interface in SortedMap and SortedSet"

java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)

Missing successor and predecessor methods.

package java.util;
public interface SortedXXX
{
    //...

    public Object successor (Object element);
    public Object predecessor (Object element);
}

-----------

(or "next" and "previous"?)
(Review ID: 98297) 
======================================================================

                                    

Comments
EVALUATION

   It is not, generally speaking, feasible to add methods to interfaces after they've been released.  We could consider adding these methods to TreeMap/TreeSet, but not to SortedMap/SortedSet.  The reporter's suggested workaround for successor is fine.  The suggested workaround for predecessor does not work, as collections do not, in general, support the clone operation.  Further, it would be far too expensive (O(n), with a high constant factor, for what should be an O(log(n)) operation).  A better workaround has been added.

joshua.bloch@Eng 2000-04-14

The submitter's suggstion will be satisfied with the new
lower/higher/floor/ceiling methods added to NavigableMap and NavigableSet,
and their implementation in Tree{Map,Set} and ConcurrentSkipList{Map,Set}
###@###.### 2005-05-10 02:46:29 GMT
                                     
2005-05-10
WORK AROUND



Name: krT82822			Date: 11/27/99


    predecessor = headSet(element).last();

    SortedSet tail = (SortedSet)tailSet(element);
    successor = tail.first();
    if (successor.equals(element)) {
        Iterator i = tail.iterator();
        i.next();  // skip first element
        successor = i.next();
    }

joshua.bloch@Eng 2000-04-14
                                     
2000-04-14



Hardware and Software, Engineered to Work Together