151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/*
2fee325d834eb37a26761e849c9becd7b9b4d3a12Tobias Thierer * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it
651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as
751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation.  Oracle designates this
851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided
951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code.
1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT
1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that
1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code).
1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version
1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation,
1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any
2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions.
2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.util;
2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/**
2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * A {@link Map} that further provides a <em>total ordering</em> on its keys.
3051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * The map is ordered according to the {@linkplain Comparable natural
3151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ordering} of its keys, or by a {@link Comparator} typically
3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * provided at sorted map creation time.  This order is reflected when
3351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * iterating over the sorted map's collection views (returned by the
3451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code entrySet}, {@code keySet} and {@code values} methods).
3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Several additional operations are provided to take advantage of the
3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ordering.  (This interface is the map analogue of {@link SortedSet}.)
3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>All keys inserted into a sorted map must implement the {@code Comparable}
3951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * interface (or be accepted by the specified comparator).  Furthermore, all
4051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * such keys must be <em>mutually comparable</em>: {@code k1.compareTo(k2)} (or
4151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code comparator.compare(k1, k2)}) must not throw a
4251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code ClassCastException} for any keys {@code k1} and {@code k2} in
4351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the sorted map.  Attempts to violate this restriction will cause the
4451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * offending method or constructor invocation to throw a
4551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code ClassCastException}.
4651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
4751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>Note that the ordering maintained by a sorted map (whether or not an
4851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * explicit comparator is provided) must be <em>consistent with equals</em> if
4951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the sorted map is to correctly implement the {@code Map} interface.  (See
5051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the {@code Comparable} interface or {@code Comparator} interface for a
5151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * precise definition of <em>consistent with equals</em>.)  This is so because
5251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the {@code Map} interface is defined in terms of the {@code equals}
5351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * operation, but a sorted map performs all key comparisons using its
5451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code compareTo} (or {@code compare}) method, so two keys that are
5551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * deemed equal by this method are, from the standpoint of the sorted map,
5651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * equal.  The behavior of a tree map <em>is</em> well-defined even if its
5751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ordering is inconsistent with equals; it just fails to obey the general
5851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * contract of the {@code Map} interface.
5951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
6051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>All general-purpose sorted map implementation classes should provide four
6151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * "standard" constructors. It is not possible to enforce this recommendation
6251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * though as required constructors cannot be specified by interfaces. The
6351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * expected "standard" constructors for all sorted map implementations are:
6451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <ol>
6551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   <li>A void (no arguments) constructor, which creates an empty sorted map
6651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   sorted according to the natural ordering of its keys.</li>
6751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   <li>A constructor with a single argument of type {@code Comparator}, which
6851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   creates an empty sorted map sorted according to the specified comparator.</li>
6951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   <li>A constructor with a single argument of type {@code Map}, which creates
7051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   a new map with the same key-value mappings as its argument, sorted
7151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   according to the keys' natural ordering.</li>
7251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   <li>A constructor with a single argument of type {@code SortedMap}, which
7351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   creates a new sorted map with the same key-value mappings and the same
7451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   ordering as the input sorted map.</li>
7551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * </ol>
7651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
7751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p><strong>Note</strong>: several methods return submaps with restricted key
7851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ranges. Such ranges are <em>half-open</em>, that is, they include their low
7951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * endpoint but not their high endpoint (where applicable).  If you need a
8051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <em>closed range</em> (which includes both endpoints), and the key type
8151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * allows for calculation of the successor of a given key, merely request
8251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * the subrange from {@code lowEndpoint} to
8351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code successor(highEndpoint)}.  For example, suppose that {@code m}
8451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * is a map whose keys are strings.  The following idiom obtains a view
8551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * containing all of the key-value mappings in {@code m} whose keys are
8651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * between {@code low} and {@code high}, inclusive:<pre>
8751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   SortedMap&lt;String, V&gt; sub = m.subMap(low, high+"\0");</pre>
8851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
8951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * A similar technique can be used to generate an <em>open range</em>
9051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * (which contains neither endpoint).  The following idiom obtains a
9151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * view containing all of the key-value mappings in {@code m} whose keys
9251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * are between {@code low} and {@code high}, exclusive:<pre>
9351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *   SortedMap&lt;String, V&gt; sub = m.subMap(low+"\0", high);</pre>
9451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
9551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>This interface is a member of the
96309f9df28350e15445b9135e8b710fa2b34b5dc1Yi Kong * <a href="{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/collections/index.html">
9751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Java Collections Framework</a>.
9851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
9951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param <K> the type of keys maintained by this map
10051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @param <V> the type of mapped values
10151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
10251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author  Josh Bloch
10351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Map
10451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see TreeMap
10551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see SortedSet
10651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Comparator
10751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Comparable
10851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see Collection
10951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @see ClassCastException
11051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since 1.2
11151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
11251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
11351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic interface SortedMap<K,V> extends Map<K,V> {
11451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
11551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the comparator used to order the keys in this map, or
11651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code null} if this map uses the {@linkplain Comparable
11751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * natural ordering} of its keys.
11851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
11951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the comparator used to order the keys in this map,
12051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         or {@code null} if this map uses the natural ordering
12151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         of its keys
12251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
12351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    Comparator<? super K> comparator();
12451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
12551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
12651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a view of the portion of this map whose keys range from
12751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code fromKey}, inclusive, to {@code toKey}, exclusive.  (If
12851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code fromKey} and {@code toKey} are equal, the returned map
12951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is empty.)  The returned map is backed by this map, so changes
13051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * in the returned map are reflected in this map, and vice-versa.
13151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The returned map supports all optional map operations that this
13251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * map supports.
13351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
13451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>The returned map will throw an {@code IllegalArgumentException}
13551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * on an attempt to insert a key outside its range.
13651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
13751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param fromKey low endpoint (inclusive) of the keys in the returned map
13851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param toKey high endpoint (exclusive) of the keys in the returned map
13951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a view of the portion of this map whose keys range from
14051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         {@code fromKey}, inclusive, to {@code toKey}, exclusive
14151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws ClassCastException if {@code fromKey} and {@code toKey}
14251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         cannot be compared to one another using this map's comparator
14351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         (or, if the map has no comparator, using natural ordering).
14451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         Implementations may, but are not required to, throw this
14551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         exception if {@code fromKey} or {@code toKey}
14651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         cannot be compared to keys currently in the map.
14751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NullPointerException if {@code fromKey} or {@code toKey}
14851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         is null and this map does not permit null keys
14951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws IllegalArgumentException if {@code fromKey} is greater than
15051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         {@code toKey}; or if this map itself has a restricted
15151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         range, and {@code fromKey} or {@code toKey} lies
15251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         outside the bounds of the range
15351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
15451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    SortedMap<K,V> subMap(K fromKey, K toKey);
15551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
15651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
15751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a view of the portion of this map whose keys are
15851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * strictly less than {@code toKey}.  The returned map is backed
15951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * by this map, so changes in the returned map are reflected in
16051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * this map, and vice-versa.  The returned map supports all
16151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * optional map operations that this map supports.
16251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
16351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>The returned map will throw an {@code IllegalArgumentException}
16451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * on an attempt to insert a key outside its range.
16551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
16651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param toKey high endpoint (exclusive) of the keys in the returned map
16751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a view of the portion of this map whose keys are strictly
16851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         less than {@code toKey}
16951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws ClassCastException if {@code toKey} is not compatible
17051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         with this map's comparator (or, if the map has no comparator,
17151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         if {@code toKey} does not implement {@link Comparable}).
17251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         Implementations may, but are not required to, throw this
17351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         exception if {@code toKey} cannot be compared to keys
17451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         currently in the map.
17551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NullPointerException if {@code toKey} is null and
17651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         this map does not permit null keys
17751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws IllegalArgumentException if this map itself has a
17851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         restricted range, and {@code toKey} lies outside the
17951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         bounds of the range
18051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
18151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    SortedMap<K,V> headMap(K toKey);
18251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
18351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
18451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a view of the portion of this map whose keys are
18551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * greater than or equal to {@code fromKey}.  The returned map is
18651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * backed by this map, so changes in the returned map are
18751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * reflected in this map, and vice-versa.  The returned map
18851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * supports all optional map operations that this map supports.
18951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
19051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>The returned map will throw an {@code IllegalArgumentException}
19151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * on an attempt to insert a key outside its range.
19251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
19351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param fromKey low endpoint (inclusive) of the keys in the returned map
19451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a view of the portion of this map whose keys are greater
19551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         than or equal to {@code fromKey}
19651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws ClassCastException if {@code fromKey} is not compatible
19751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         with this map's comparator (or, if the map has no comparator,
19851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         if {@code fromKey} does not implement {@link Comparable}).
19951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         Implementations may, but are not required to, throw this
20051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         exception if {@code fromKey} cannot be compared to keys
20151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         currently in the map.
20251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NullPointerException if {@code fromKey} is null and
20351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         this map does not permit null keys
20451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws IllegalArgumentException if this map itself has a
20551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         restricted range, and {@code fromKey} lies outside the
20651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         bounds of the range
20751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
20851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    SortedMap<K,V> tailMap(K fromKey);
20951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
21051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
21151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the first (lowest) key currently in this map.
21251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
21351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the first (lowest) key currently in this map
21451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NoSuchElementException if this map is empty
21551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
21651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    K firstKey();
21751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
21851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
21951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the last (highest) key currently in this map.
22051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
22151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the last (highest) key currently in this map
22251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NoSuchElementException if this map is empty
22351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
22451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    K lastKey();
22551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
22651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
22751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a {@link Set} view of the keys contained in this map.
22851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The set's iterator returns the keys in ascending order.
22951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The set is backed by the map, so changes to the map are
23051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * reflected in the set, and vice-versa.  If the map is modified
23151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * while an iteration over the set is in progress (except through
23251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the iterator's own {@code remove} operation), the results of
23351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the iteration are undefined.  The set supports element removal,
23451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * which removes the corresponding mapping from the map, via the
23551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code Iterator.remove}, {@code Set.remove},
23651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code removeAll}, {@code retainAll}, and {@code clear}
23751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * operations.  It does not support the {@code add} or {@code addAll}
23851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * operations.
23951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
24051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a set view of the keys contained in this map, sorted in
24151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         ascending order
24251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
24351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    Set<K> keySet();
24451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
24551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
24651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a {@link Collection} view of the values contained in this map.
24751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The collection's iterator returns the values in ascending order
24851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * of the corresponding keys.
24951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The collection is backed by the map, so changes to the map are
25051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * reflected in the collection, and vice-versa.  If the map is
25151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * modified while an iteration over the collection is in progress
25251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * (except through the iterator's own {@code remove} operation),
25351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the results of the iteration are undefined.  The collection
25451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * supports element removal, which removes the corresponding
25551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mapping from the map, via the {@code Iterator.remove},
25651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code Collection.remove}, {@code removeAll},
25751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code retainAll} and {@code clear} operations.  It does not
25851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * support the {@code add} or {@code addAll} operations.
25951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
26051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a collection view of the values contained in this map,
26151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         sorted in ascending key order
26251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
26351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    Collection<V> values();
26451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
26551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
26651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a {@link Set} view of the mappings contained in this map.
26751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The set's iterator returns the entries in ascending key order.
26851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The set is backed by the map, so changes to the map are
26951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * reflected in the set, and vice-versa.  If the map is modified
27051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * while an iteration over the set is in progress (except through
27151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the iterator's own {@code remove} operation, or through the
27251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code setValue} operation on a map entry returned by the
27351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * iterator) the results of the iteration are undefined.  The set
27451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * supports element removal, which removes the corresponding
27551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mapping from the map, via the {@code Iterator.remove},
27651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code Set.remove}, {@code removeAll}, {@code retainAll} and
27751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code clear} operations.  It does not support the
27851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code add} or {@code addAll} operations.
27951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a set view of the mappings contained in this map,
28151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *         sorted in ascending key order
28251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
28351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    Set<Map.Entry<K, V>> entrySet();
28451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski}
285