--- jsr166/src/main/java/util/NavigableMap.java 2006/04/21 03:53:57 1.17
+++ jsr166/src/main/java/util/NavigableMap.java 2013/02/09 21:35:06 1.27
@@ -1,7 +1,7 @@
/*
* Written by Doug Lea and Josh Bloch with assistance from members of JCP
* JSR-166 Expert Group and released to the public domain, as explained at
- * http://creativecommons.org/licenses/publicdomain
+ * http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util;
@@ -9,13 +9,13 @@ package java.util;
/**
* A {@link SortedMap} extended with navigation methods returning the
* closest matches for given search targets. Methods
- * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry},
- * and {@code higherEntry} return {@code Map.Entry} objects
+ * {@link #lowerEntry}, {@link #floorEntry}, {@link #ceilingEntry},
+ * and {@link #higherEntry} return {@code Map.Entry} objects
* associated with keys respectively less than, less than or equal,
* greater than or equal, and greater than a given key, returning
* {@code null} if there is no such key. Similarly, methods
- * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and
- * {@code higherKey} return only the associated keys. All of these
+ * {@link #lowerKey}, {@link #floorKey}, {@link #ceilingKey}, and
+ * {@link #higherKey} return only the associated keys. All of these
* methods are designed for locating, not traversing entries.
*
*
A {@code NavigableMap} may be accessed and traversed in either
@@ -30,20 +30,31 @@ package java.util;
* Submaps of any {@code NavigableMap} must implement the {@code
* NavigableMap} interface.
*
- *
This interface additionally defines methods {@code firstEntry},
- * {@code pollFirstEntry}, {@code lastEntry}, and
- * {@code pollLastEntry} that return and/or remove the least and
+ *
This interface additionally defines methods {@link #firstEntry},
+ * {@link #pollFirstEntry}, {@link #lastEntry}, and
+ * {@link #pollLastEntry} that return and/or remove the least and
* greatest mappings, if any exist, else returning {@code null}.
*
- *
Implementations of entry-returning methods are expected to
+ *
Implementations of entry-returning methods are expected to
* return {@code Map.Entry} pairs representing snapshots of mappings
* at the time they were produced, and thus generally do not
* support the optional {@code Entry.setValue} method. Note however
* that it is possible to change mappings in the associated map using
* method {@code put}.
*
+ *
Methods
+ * {@link #subMap(Object, Object) subMap(K, K)},
+ * {@link #headMap(Object) headMap(K)}, and
+ * {@link #tailMap(Object) tailMap(K)}
+ * are specified to return {@code SortedMap} to allow existing
+ * implementations of {@code SortedMap} to be compatibly retrofitted to
+ * implement {@code NavigableMap}, but extensions and implementations
+ * of this interface are encouraged to override these methods to return
+ * {@code NavigableMap}. Similarly,
+ * {@link #keySet()} can be overridden to return {@code NavigableSet}.
+ *
*
This interface is a member of the
- *
+ *
* Java Collections Framework.
*
* @author Doug Lea
@@ -206,50 +217,51 @@ public interface NavigableMap exten
Map.Entry pollLastEntry();
/**
- * Returns a {@link NavigableMap} view of the mappings contained in this
- * map in descending order. The descending map is backed by this map, so
- * changes to the map are reflected in the descending map, and vice-versa.
- * If either map is modified while an iteration over a collection view of
- * the other map is in progress (except through the iterator's own
- * {@code remove} operation), the results of the iteration are undefined.
+ * Returns a reverse order view of the mappings contained in this map.
+ * The descending map is backed by this map, so changes to the map are
+ * reflected in the descending map, and vice-versa. If either map is
+ * modified while an iteration over a collection view of either map
+ * is in progress (except through the iterator's own {@code remove}
+ * operation), the results of the iteration are undefined.
+ *
+ * The returned map has an ordering equivalent to
+ * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator()).
+ * The expression {@code m.descendingMap().descendingMap()} returns a
+ * view of {@code m} essentially equivalent to {@code m}.
*
- * @return a navigable map view of the mappings contained in this map,
- * sorted in descending order
+ * @return a reverse order view of this map
*/
NavigableMap descendingMap();
/**
- * Returns a navigable set view of the keys contained in this navigable
- * map. The set is backed by the map, so changes to the map are reflected
- * in the set, and vice-versa. If the map is modified while an iteration
- * over the set is in progress (except through the iterator's own
- * {@code remove} operation), the results of the iteration are undefined.
- * The set supports element removal, which removes the corresponding
- * mapping from the map, via the {@code Iterator.remove},
- * {@code Set.remove}, {@code removeAll} {@code retainAll}, and
- * {@code clear} operations. It does not support the {@code add} or
- * {@code addAll} operations.
+ * Returns a {@link NavigableSet} view of the keys contained in this map.
+ * The set's iterator returns the keys in ascending order.
+ * The set is backed by the map, so changes to the map are reflected in
+ * the set, and vice-versa. If the map is modified while an iteration
+ * over the set is in progress (except through the iterator's own {@code
+ * remove} operation), the results of the iteration are undefined. The
+ * set supports element removal, which removes the corresponding mapping
+ * from the map, via the {@code Iterator.remove}, {@code Set.remove},
+ * {@code removeAll}, {@code retainAll}, and {@code clear} operations.
+ * It does not support the {@code add} or {@code addAll} operations.
*
- * @return a navigable set view of the keys contained in this navigable map
+ * @return a navigable set view of the keys in this map
*/
NavigableSet navigableKeySet();
/**
- * Returns a {@link NavigableSet} view of the keys contained in this map.
+ * Returns a reverse order {@link NavigableSet} view of the keys contained in this map.
* The set's iterator returns the keys in descending order.
- * The set is backed by the map, so changes to the map are
- * reflected in the set, and vice-versa. If the map is modified
- * while an iteration over the set is in progress (except through
- * the iterator's own remove operation), the results of
- * the iteration are undefined. The set supports element removal,
- * which removes the corresponding mapping from the map, via the
- * Iterator.remove, Set.remove,
- * removeAll, retainAll, and clear
- * operations. It does not support the add or addAll
- * operations.
+ * The set is backed by the map, so changes to the map are reflected in
+ * the set, and vice-versa. If the map is modified while an iteration
+ * over the set is in progress (except through the iterator's own {@code
+ * remove} operation), the results of the iteration are undefined. The
+ * set supports element removal, which removes the corresponding mapping
+ * from the map, via the {@code Iterator.remove}, {@code Set.remove},
+ * {@code removeAll}, {@code retainAll}, and {@code clear} operations.
+ * It does not support the {@code add} or {@code addAll} operations.
*
- * @return a set view of the keys contained in this map, sorted in
- * descending order
+ * @return a reverse order navigable set view of the keys in this map
*/
NavigableSet descendingKeySet();
@@ -267,11 +279,11 @@ public interface NavigableMap exten
* submap either of whose endpoints lie outside its range.
*
* @param fromKey low endpoint of the keys in the returned map
- * @param fromInclusive true if the low endpoint ({@code fromKey}) is
- * to be included in the returned view
+ * @param fromInclusive {@code true} if the low endpoint
+ * is to be included in the returned view
* @param toKey high endpoint of the keys in the returned map
- * @param toInclusive true if the high endpoint ({@code toKey}) is
- * to be included in the returned view
+ * @param toInclusive {@code true} if the high endpoint
+ * is to be included in the returned view
* @return a view of the portion of this map whose keys range from
* {@code fromKey} to {@code toKey}
* @throws ClassCastException if {@code fromKey} and {@code toKey}
@@ -301,8 +313,8 @@ public interface NavigableMap exten
* on an attempt to insert a key outside its range.
*
* @param toKey high endpoint of the keys in the returned map
- * @param inclusive true if the high endpoint ({@code toKey}) is
- * to be included in the returned view
+ * @param inclusive {@code true} if the high endpoint
+ * is to be included in the returned view
* @return a view of the portion of this map whose keys are less than
* (or equal to, if {@code inclusive} is true) {@code toKey}
* @throws ClassCastException if {@code toKey} is not compatible
@@ -330,8 +342,8 @@ public interface NavigableMap exten
* on an attempt to insert a key outside its range.
*
* @param fromKey low endpoint of the keys in the returned map
- * @param inclusive true if the low endpoint ({@code fromKey}) is
- * to be included in the returned view
+ * @param inclusive {@code true} if the low endpoint
+ * is to be included in the returned view
* @return a view of the portion of this map whose keys are greater than
* (or equal to, if {@code inclusive} is true) {@code fromKey}
* @throws ClassCastException if {@code fromKey} is not compatible
@@ -347,4 +359,37 @@ public interface NavigableMap exten
* bounds of the range
*/
NavigableMap tailMap(K fromKey, boolean inclusive);
+
+ /**
+ * {@inheritDoc}
+ *
+ * Equivalent to {@code subMap(fromKey, true, toKey, false)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
+ */
+ SortedMap subMap(K fromKey, K toKey);
+
+ /**
+ * {@inheritDoc}
+ *
+ * Equivalent to {@code headMap(toKey, false)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
+ */
+ SortedMap headMap(K toKey);
+
+ /**
+ * {@inheritDoc}
+ *
+ * Equivalent to {@code tailMap(fromKey, true)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
+ */
+ SortedMap tailMap(K fromKey);
}