JDK-4294891 : (coll) Add "next/previous" to both SortedMap and SortedSet
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-11-27
  • Updated: 2012-10-08
  • 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
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
10-05-2005

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
14-04-2000