jaroslav@1258: /* jaroslav@1258: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@1258: * jaroslav@1258: * This code is free software; you can redistribute it and/or modify it jaroslav@1258: * under the terms of the GNU General Public License version 2 only, as jaroslav@1258: * published by the Free Software Foundation. Oracle designates this jaroslav@1258: * particular file as subject to the "Classpath" exception as provided jaroslav@1258: * by Oracle in the LICENSE file that accompanied this code. jaroslav@1258: * jaroslav@1258: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@1258: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@1258: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@1258: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@1258: * accompanied this code). jaroslav@1258: * jaroslav@1258: * You should have received a copy of the GNU General Public License version jaroslav@1258: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@1258: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@1258: * jaroslav@1258: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@1258: * or visit www.oracle.com if you need additional information or have any jaroslav@1258: * questions. jaroslav@1258: */ jaroslav@1258: jaroslav@1258: /* jaroslav@1258: * This file is available under and governed by the GNU General Public jaroslav@1258: * License version 2 only, as published by the Free Software Foundation. jaroslav@1258: * However, the following notice accompanied the original version of this jaroslav@1258: * file: jaroslav@1258: * jaroslav@1258: * Written by Doug Lea and Josh Bloch with assistance from members of JCP jaroslav@1258: * JSR-166 Expert Group and released to the public domain, as explained at jaroslav@1258: * http://creativecommons.org/publicdomain/zero/1.0/ jaroslav@1258: */ jaroslav@1258: jaroslav@1258: package java.util; jaroslav@1258: jaroslav@1258: /** jaroslav@1258: * A {@link SortedMap} extended with navigation methods returning the jaroslav@1258: * closest matches for given search targets. Methods jaroslav@1258: * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry}, jaroslav@1258: * and {@code higherEntry} return {@code Map.Entry} objects jaroslav@1258: * associated with keys respectively less than, less than or equal, jaroslav@1258: * greater than or equal, and greater than a given key, returning jaroslav@1258: * {@code null} if there is no such key. Similarly, methods jaroslav@1258: * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and jaroslav@1258: * {@code higherKey} return only the associated keys. All of these jaroslav@1258: * methods are designed for locating, not traversing entries. jaroslav@1258: * jaroslav@1258: *
A {@code NavigableMap} may be accessed and traversed in either jaroslav@1258: * ascending or descending key order. The {@code descendingMap} jaroslav@1258: * method returns a view of the map with the senses of all relational jaroslav@1258: * and directional methods inverted. The performance of ascending jaroslav@1258: * operations and views is likely to be faster than that of descending jaroslav@1258: * ones. Methods {@code subMap}, {@code headMap}, jaroslav@1258: * and {@code tailMap} differ from the like-named {@code jaroslav@1258: * SortedMap} methods in accepting additional arguments describing jaroslav@1258: * whether lower and upper bounds are inclusive versus exclusive. jaroslav@1258: * Submaps of any {@code NavigableMap} must implement the {@code jaroslav@1258: * NavigableMap} interface. jaroslav@1258: * jaroslav@1258: *
This interface additionally defines methods {@code firstEntry}, jaroslav@1258: * {@code pollFirstEntry}, {@code lastEntry}, and jaroslav@1258: * {@code pollLastEntry} that return and/or remove the least and jaroslav@1258: * greatest mappings, if any exist, else returning {@code null}. jaroslav@1258: * jaroslav@1258: *
Implementations of entry-returning methods are expected to jaroslav@1258: * return {@code Map.Entry} pairs representing snapshots of mappings jaroslav@1258: * at the time they were produced, and thus generally do not jaroslav@1258: * support the optional {@code Entry.setValue} method. Note however jaroslav@1258: * that it is possible to change mappings in the associated map using jaroslav@1258: * method {@code put}. jaroslav@1258: * jaroslav@1258: *
Methods jaroslav@1258: * {@link #subMap(Object, Object) subMap(K, K)}, jaroslav@1258: * {@link #headMap(Object) headMap(K)}, and jaroslav@1258: * {@link #tailMap(Object) tailMap(K)} jaroslav@1258: * are specified to return {@code SortedMap} to allow existing jaroslav@1258: * implementations of {@code SortedMap} to be compatibly retrofitted to jaroslav@1258: * implement {@code NavigableMap}, but extensions and implementations jaroslav@1258: * of this interface are encouraged to override these methods to return jaroslav@1258: * {@code NavigableMap}. Similarly, jaroslav@1258: * {@link #keySet()} can be overriden to return {@code NavigableSet}. jaroslav@1258: * jaroslav@1258: *
This interface is a member of the
jaroslav@1258: *
jaroslav@1258: * Java Collections Framework.
jaroslav@1258: *
jaroslav@1258: * @author Doug Lea
jaroslav@1258: * @author Josh Bloch
jaroslav@1258: * @param The returned map has an ordering equivalent to
jaroslav@1258: * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator()).
jaroslav@1258: * The expression {@code m.descendingMap().descendingMap()} returns a
jaroslav@1258: * view of {@code m} essentially equivalent to {@code m}.
jaroslav@1258: *
jaroslav@1258: * @return a reverse order view of this map
jaroslav@1258: */
jaroslav@1258: NavigableMap The returned map will throw an {@code IllegalArgumentException}
jaroslav@1258: * on an attempt to insert a key outside of its range, or to construct a
jaroslav@1258: * submap either of whose endpoints lie outside its range.
jaroslav@1258: *
jaroslav@1258: * @param fromKey low endpoint of the keys in the returned map
jaroslav@1258: * @param fromInclusive {@code true} if the low endpoint
jaroslav@1258: * is to be included in the returned view
jaroslav@1258: * @param toKey high endpoint of the keys in the returned map
jaroslav@1258: * @param toInclusive {@code true} if the high endpoint
jaroslav@1258: * is to be included in the returned view
jaroslav@1258: * @return a view of the portion of this map whose keys range from
jaroslav@1258: * {@code fromKey} to {@code toKey}
jaroslav@1258: * @throws ClassCastException if {@code fromKey} and {@code toKey}
jaroslav@1258: * cannot be compared to one another using this map's comparator
jaroslav@1258: * (or, if the map has no comparator, using natural ordering).
jaroslav@1258: * Implementations may, but are not required to, throw this
jaroslav@1258: * exception if {@code fromKey} or {@code toKey}
jaroslav@1258: * cannot be compared to keys currently in the map.
jaroslav@1258: * @throws NullPointerException if {@code fromKey} or {@code toKey}
jaroslav@1258: * is null and this map does not permit null keys
jaroslav@1258: * @throws IllegalArgumentException if {@code fromKey} is greater than
jaroslav@1258: * {@code toKey}; or if this map itself has a restricted
jaroslav@1258: * range, and {@code fromKey} or {@code toKey} lies
jaroslav@1258: * outside the bounds of the range
jaroslav@1258: */
jaroslav@1258: NavigableMap The returned map will throw an {@code IllegalArgumentException}
jaroslav@1258: * on an attempt to insert a key outside its range.
jaroslav@1258: *
jaroslav@1258: * @param toKey high endpoint of the keys in the returned map
jaroslav@1258: * @param inclusive {@code true} if the high endpoint
jaroslav@1258: * is to be included in the returned view
jaroslav@1258: * @return a view of the portion of this map whose keys are less than
jaroslav@1258: * (or equal to, if {@code inclusive} is true) {@code toKey}
jaroslav@1258: * @throws ClassCastException if {@code toKey} is not compatible
jaroslav@1258: * with this map's comparator (or, if the map has no comparator,
jaroslav@1258: * if {@code toKey} does not implement {@link Comparable}).
jaroslav@1258: * Implementations may, but are not required to, throw this
jaroslav@1258: * exception if {@code toKey} cannot be compared to keys
jaroslav@1258: * currently in the map.
jaroslav@1258: * @throws NullPointerException if {@code toKey} is null
jaroslav@1258: * and this map does not permit null keys
jaroslav@1258: * @throws IllegalArgumentException if this map itself has a
jaroslav@1258: * restricted range, and {@code toKey} lies outside the
jaroslav@1258: * bounds of the range
jaroslav@1258: */
jaroslav@1258: NavigableMap The returned map will throw an {@code IllegalArgumentException}
jaroslav@1258: * on an attempt to insert a key outside its range.
jaroslav@1258: *
jaroslav@1258: * @param fromKey low endpoint of the keys in the returned map
jaroslav@1258: * @param inclusive {@code true} if the low endpoint
jaroslav@1258: * is to be included in the returned view
jaroslav@1258: * @return a view of the portion of this map whose keys are greater than
jaroslav@1258: * (or equal to, if {@code inclusive} is true) {@code fromKey}
jaroslav@1258: * @throws ClassCastException if {@code fromKey} is not compatible
jaroslav@1258: * with this map's comparator (or, if the map has no comparator,
jaroslav@1258: * if {@code fromKey} does not implement {@link Comparable}).
jaroslav@1258: * Implementations may, but are not required to, throw this
jaroslav@1258: * exception if {@code fromKey} cannot be compared to keys
jaroslav@1258: * currently in the map.
jaroslav@1258: * @throws NullPointerException if {@code fromKey} is null
jaroslav@1258: * and this map does not permit null keys
jaroslav@1258: * @throws IllegalArgumentException if this map itself has a
jaroslav@1258: * restricted range, and {@code fromKey} lies outside the
jaroslav@1258: * bounds of the range
jaroslav@1258: */
jaroslav@1258: NavigableMap Equivalent to {@code subMap(fromKey, true, toKey, false)}.
jaroslav@1258: *
jaroslav@1258: * @throws ClassCastException {@inheritDoc}
jaroslav@1258: * @throws NullPointerException {@inheritDoc}
jaroslav@1258: * @throws IllegalArgumentException {@inheritDoc}
jaroslav@1258: */
jaroslav@1258: SortedMap Equivalent to {@code headMap(toKey, false)}.
jaroslav@1258: *
jaroslav@1258: * @throws ClassCastException {@inheritDoc}
jaroslav@1258: * @throws NullPointerException {@inheritDoc}
jaroslav@1258: * @throws IllegalArgumentException {@inheritDoc}
jaroslav@1258: */
jaroslav@1258: SortedMap Equivalent to {@code tailMap(fromKey, true)}.
jaroslav@1258: *
jaroslav@1258: * @throws ClassCastException {@inheritDoc}
jaroslav@1258: * @throws NullPointerException {@inheritDoc}
jaroslav@1258: * @throws IllegalArgumentException {@inheritDoc}
jaroslav@1258: */
jaroslav@1258: SortedMap