emul/compact/src/main/java/java/util/SortedSet.java
brancharithmetic
changeset 774 42bc1e89134d
parent 755 5652acd48509
parent 773 406faa8bc64f
child 778 6f8683517f1f
     1.1 --- a/emul/compact/src/main/java/java/util/SortedSet.java	Mon Feb 25 19:00:08 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,222 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.  Oracle designates this
    1.11 - * particular file as subject to the "Classpath" exception as provided
    1.12 - * by Oracle in the LICENSE file that accompanied this code.
    1.13 - *
    1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 - * version 2 for more details (a copy is included in the LICENSE file that
    1.18 - * accompanied this code).
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License version
    1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 - *
    1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 - * or visit www.oracle.com if you need additional information or have any
    1.26 - * questions.
    1.27 - */
    1.28 -
    1.29 -package java.util;
    1.30 -
    1.31 -/**
    1.32 - * A {@link Set} that further provides a <i>total ordering</i> on its elements.
    1.33 - * The elements are ordered using their {@linkplain Comparable natural
    1.34 - * ordering}, or by a {@link Comparator} typically provided at sorted
    1.35 - * set creation time.  The set's iterator will traverse the set in
    1.36 - * ascending element order. Several additional operations are provided
    1.37 - * to take advantage of the ordering.  (This interface is the set
    1.38 - * analogue of {@link SortedMap}.)
    1.39 - *
    1.40 - * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
    1.41 - * interface (or be accepted by the specified comparator).  Furthermore, all
    1.42 - * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
    1.43 - * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
    1.44 - * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
    1.45 - * the sorted set.  Attempts to violate this restriction will cause the
    1.46 - * offending method or constructor invocation to throw a
    1.47 - * <tt>ClassCastException</tt>.
    1.48 - *
    1.49 - * <p>Note that the ordering maintained by a sorted set (whether or not an
    1.50 - * explicit comparator is provided) must be <i>consistent with equals</i> if
    1.51 - * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
    1.52 - * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
    1.53 - * precise definition of <i>consistent with equals</i>.)  This is so because
    1.54 - * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
    1.55 - * operation, but a sorted set performs all element comparisons using its
    1.56 - * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
    1.57 - * deemed equal by this method are, from the standpoint of the sorted set,
    1.58 - * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
    1.59 - * ordering is inconsistent with equals; it just fails to obey the general
    1.60 - * contract of the <tt>Set</tt> interface.
    1.61 - *
    1.62 - * <p>All general-purpose sorted set implementation classes should
    1.63 - * provide four "standard" constructors: 1) A void (no arguments)
    1.64 - * constructor, which creates an empty sorted set sorted according to
    1.65 - * the natural ordering of its elements.  2) A constructor with a
    1.66 - * single argument of type <tt>Comparator</tt>, which creates an empty
    1.67 - * sorted set sorted according to the specified comparator.  3) A
    1.68 - * constructor with a single argument of type <tt>Collection</tt>,
    1.69 - * which creates a new sorted set with the same elements as its
    1.70 - * argument, sorted according to the natural ordering of the elements.
    1.71 - * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
    1.72 - * which creates a new sorted set with the same elements and the same
    1.73 - * ordering as the input sorted set.  There is no way to enforce this
    1.74 - * recommendation, as interfaces cannot contain constructors.
    1.75 - *
    1.76 - * <p>Note: several methods return subsets with restricted ranges.
    1.77 - * Such ranges are <i>half-open</i>, that is, they include their low
    1.78 - * endpoint but not their high endpoint (where applicable).
    1.79 - * If you need a <i>closed range</i> (which includes both endpoints), and
    1.80 - * the element type allows for calculation of the successor of a given
    1.81 - * value, merely request the subrange from <tt>lowEndpoint</tt> to
    1.82 - * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
    1.83 - * is a sorted set of strings.  The following idiom obtains a view
    1.84 - * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
    1.85 - * <tt>high</tt>, inclusive:<pre>
    1.86 - *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
    1.87 - *
    1.88 - * A similar technique can be used to generate an <i>open range</i> (which
    1.89 - * contains neither endpoint).  The following idiom obtains a view
    1.90 - * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
    1.91 - * <tt>high</tt>, exclusive:<pre>
    1.92 - *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
    1.93 - *
    1.94 - * <p>This interface is a member of the
    1.95 - * <a href="{@docRoot}/../technotes/guides/collections/index.html">
    1.96 - * Java Collections Framework</a>.
    1.97 - *
    1.98 - * @param <E> the type of elements maintained by this set
    1.99 - *
   1.100 - * @author  Josh Bloch
   1.101 - * @see Set
   1.102 - * @see TreeSet
   1.103 - * @see SortedMap
   1.104 - * @see Collection
   1.105 - * @see Comparable
   1.106 - * @see Comparator
   1.107 - * @see ClassCastException
   1.108 - * @since 1.2
   1.109 - */
   1.110 -
   1.111 -public interface SortedSet<E> extends Set<E> {
   1.112 -    /**
   1.113 -     * Returns the comparator used to order the elements in this set,
   1.114 -     * or <tt>null</tt> if this set uses the {@linkplain Comparable
   1.115 -     * natural ordering} of its elements.
   1.116 -     *
   1.117 -     * @return the comparator used to order the elements in this set,
   1.118 -     *         or <tt>null</tt> if this set uses the natural ordering
   1.119 -     *         of its elements
   1.120 -     */
   1.121 -    Comparator<? super E> comparator();
   1.122 -
   1.123 -    /**
   1.124 -     * Returns a view of the portion of this set whose elements range
   1.125 -     * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
   1.126 -     * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
   1.127 -     * equal, the returned set is empty.)  The returned set is backed
   1.128 -     * by this set, so changes in the returned set are reflected in
   1.129 -     * this set, and vice-versa.  The returned set supports all
   1.130 -     * optional set operations that this set supports.
   1.131 -     *
   1.132 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
   1.133 -     * on an attempt to insert an element outside its range.
   1.134 -     *
   1.135 -     * @param fromElement low endpoint (inclusive) of the returned set
   1.136 -     * @param toElement high endpoint (exclusive) of the returned set
   1.137 -     * @return a view of the portion of this set whose elements range from
   1.138 -     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
   1.139 -     * @throws ClassCastException if <tt>fromElement</tt> and
   1.140 -     *         <tt>toElement</tt> cannot be compared to one another using this
   1.141 -     *         set's comparator (or, if the set has no comparator, using
   1.142 -     *         natural ordering).  Implementations may, but are not required
   1.143 -     *         to, throw this exception if <tt>fromElement</tt> or
   1.144 -     *         <tt>toElement</tt> cannot be compared to elements currently in
   1.145 -     *         the set.
   1.146 -     * @throws NullPointerException if <tt>fromElement</tt> or
   1.147 -     *         <tt>toElement</tt> is null and this set does not permit null
   1.148 -     *         elements
   1.149 -     * @throws IllegalArgumentException if <tt>fromElement</tt> is
   1.150 -     *         greater than <tt>toElement</tt>; or if this set itself
   1.151 -     *         has a restricted range, and <tt>fromElement</tt> or
   1.152 -     *         <tt>toElement</tt> lies outside the bounds of the range
   1.153 -     */
   1.154 -    SortedSet<E> subSet(E fromElement, E toElement);
   1.155 -
   1.156 -    /**
   1.157 -     * Returns a view of the portion of this set whose elements are
   1.158 -     * strictly less than <tt>toElement</tt>.  The returned set is
   1.159 -     * backed by this set, so changes in the returned set are
   1.160 -     * reflected in this set, and vice-versa.  The returned set
   1.161 -     * supports all optional set operations that this set supports.
   1.162 -     *
   1.163 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
   1.164 -     * on an attempt to insert an element outside its range.
   1.165 -     *
   1.166 -     * @param toElement high endpoint (exclusive) of the returned set
   1.167 -     * @return a view of the portion of this set whose elements are strictly
   1.168 -     *         less than <tt>toElement</tt>
   1.169 -     * @throws ClassCastException if <tt>toElement</tt> is not compatible
   1.170 -     *         with this set's comparator (or, if the set has no comparator,
   1.171 -     *         if <tt>toElement</tt> does not implement {@link Comparable}).
   1.172 -     *         Implementations may, but are not required to, throw this
   1.173 -     *         exception if <tt>toElement</tt> cannot be compared to elements
   1.174 -     *         currently in the set.
   1.175 -     * @throws NullPointerException if <tt>toElement</tt> is null and
   1.176 -     *         this set does not permit null elements
   1.177 -     * @throws IllegalArgumentException if this set itself has a
   1.178 -     *         restricted range, and <tt>toElement</tt> lies outside the
   1.179 -     *         bounds of the range
   1.180 -     */
   1.181 -    SortedSet<E> headSet(E toElement);
   1.182 -
   1.183 -    /**
   1.184 -     * Returns a view of the portion of this set whose elements are
   1.185 -     * greater than or equal to <tt>fromElement</tt>.  The returned
   1.186 -     * set is backed by this set, so changes in the returned set are
   1.187 -     * reflected in this set, and vice-versa.  The returned set
   1.188 -     * supports all optional set operations that this set supports.
   1.189 -     *
   1.190 -     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
   1.191 -     * on an attempt to insert an element outside its range.
   1.192 -     *
   1.193 -     * @param fromElement low endpoint (inclusive) of the returned set
   1.194 -     * @return a view of the portion of this set whose elements are greater
   1.195 -     *         than or equal to <tt>fromElement</tt>
   1.196 -     * @throws ClassCastException if <tt>fromElement</tt> is not compatible
   1.197 -     *         with this set's comparator (or, if the set has no comparator,
   1.198 -     *         if <tt>fromElement</tt> does not implement {@link Comparable}).
   1.199 -     *         Implementations may, but are not required to, throw this
   1.200 -     *         exception if <tt>fromElement</tt> cannot be compared to elements
   1.201 -     *         currently in the set.
   1.202 -     * @throws NullPointerException if <tt>fromElement</tt> is null
   1.203 -     *         and this set does not permit null elements
   1.204 -     * @throws IllegalArgumentException if this set itself has a
   1.205 -     *         restricted range, and <tt>fromElement</tt> lies outside the
   1.206 -     *         bounds of the range
   1.207 -     */
   1.208 -    SortedSet<E> tailSet(E fromElement);
   1.209 -
   1.210 -    /**
   1.211 -     * Returns the first (lowest) element currently in this set.
   1.212 -     *
   1.213 -     * @return the first (lowest) element currently in this set
   1.214 -     * @throws NoSuchElementException if this set is empty
   1.215 -     */
   1.216 -    E first();
   1.217 -
   1.218 -    /**
   1.219 -     * Returns the last (highest) element currently in this set.
   1.220 -     *
   1.221 -     * @return the last (highest) element currently in this set
   1.222 -     * @throws NoSuchElementException if this set is empty
   1.223 -     */
   1.224 -    E last();
   1.225 -}