jdk/src/share/classes/java/util/SortedSet.java
author psandoz
Wed, 17 Apr 2013 11:34:31 +0200
changeset 17168 b7d3500f2516
parent 16929 c984ae5655cb
child 19435 9d7530ff42cb
permissions -rw-r--r--
8011426: java.util collection Spliterator implementations Summary: Spliterator implementations for collection classes in java.util. Reviewed-by: mduigou, briangoetz Contributed-by: Doug Lea <dl@cs.oswego.edu>, Paul Sandoz <paul.sandoz@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * A {@link Set} that further provides a <i>total ordering</i> on its elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The elements are ordered using their {@linkplain Comparable natural
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * ordering}, or by a {@link Comparator} typically provided at sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * set creation time.  The set's iterator will traverse the set in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * ascending element order. Several additional operations are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * to take advantage of the ordering.  (This interface is the set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * analogue of {@link SortedMap}.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * interface (or be accepted by the specified comparator).  Furthermore, all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * the sorted set.  Attempts to violate this restriction will cause the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * offending method or constructor invocation to throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <tt>ClassCastException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>Note that the ordering maintained by a sorted set (whether or not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * explicit comparator is provided) must be <i>consistent with equals</i> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * precise definition of <i>consistent with equals</i>.)  This is so because
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * operation, but a sorted set performs all element comparisons using its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * deemed equal by this method are, from the standpoint of the sorted set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * ordering is inconsistent with equals; it just fails to obey the general
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * contract of the <tt>Set</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>All general-purpose sorted set implementation classes should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * provide four "standard" constructors: 1) A void (no arguments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * constructor, which creates an empty sorted set sorted according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the natural ordering of its elements.  2) A constructor with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * single argument of type <tt>Comparator</tt>, which creates an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * sorted set sorted according to the specified comparator.  3) A
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * constructor with a single argument of type <tt>Collection</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * which creates a new sorted set with the same elements as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * argument, sorted according to the natural ordering of the elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * which creates a new sorted set with the same elements and the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * ordering as the input sorted set.  There is no way to enforce this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * recommendation, as interfaces cannot contain constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>Note: several methods return subsets with restricted ranges.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Such ranges are <i>half-open</i>, that is, they include their low
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * endpoint but not their high endpoint (where applicable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * If you need a <i>closed range</i> (which includes both endpoints), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * the element type allows for calculation of the successor of a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * value, merely request the subrange from <tt>lowEndpoint</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * is a sorted set of strings.  The following idiom obtains a view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <tt>high</tt>, inclusive:<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * A similar technique can be used to generate an <i>open range</i> (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * contains neither endpoint).  The following idiom obtains a view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <tt>high</tt>, exclusive:<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @param <E> the type of elements maintained by this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @see Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see TreeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see SortedMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @see Comparable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @see Comparator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @see ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
public interface SortedSet<E> extends Set<E> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Returns the comparator used to order the elements in this set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * or <tt>null</tt> if this set uses the {@linkplain Comparable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * natural ordering} of its elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return the comparator used to order the elements in this set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *         or <tt>null</tt> if this set uses the natural ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *         of its elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    Comparator<? super E> comparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns a view of the portion of this set whose elements range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * equal, the returned set is empty.)  The returned set is backed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * by this set, so changes in the returned set are reflected in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * this set, and vice-versa.  The returned set supports all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * optional set operations that this set supports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * on an attempt to insert an element outside its range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @param fromElement low endpoint (inclusive) of the returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param toElement high endpoint (exclusive) of the returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return a view of the portion of this set whose elements range from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @throws ClassCastException if <tt>fromElement</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         <tt>toElement</tt> cannot be compared to one another using this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *         set's comparator (or, if the set has no comparator, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *         natural ordering).  Implementations may, but are not required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *         to, throw this exception if <tt>fromElement</tt> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *         <tt>toElement</tt> cannot be compared to elements currently in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *         the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @throws NullPointerException if <tt>fromElement</tt> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *         <tt>toElement</tt> is null and this set does not permit null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *         elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @throws IllegalArgumentException if <tt>fromElement</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *         greater than <tt>toElement</tt>; or if this set itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         has a restricted range, and <tt>fromElement</tt> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *         <tt>toElement</tt> lies outside the bounds of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    SortedSet<E> subSet(E fromElement, E toElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns a view of the portion of this set whose elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * strictly less than <tt>toElement</tt>.  The returned set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * backed by this set, so changes in the returned set are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * reflected in this set, and vice-versa.  The returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * supports all optional set operations that this set supports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * on an attempt to insert an element outside its range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param toElement high endpoint (exclusive) of the returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return a view of the portion of this set whose elements are strictly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *         less than <tt>toElement</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws ClassCastException if <tt>toElement</tt> is not compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *         with this set's comparator (or, if the set has no comparator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *         if <tt>toElement</tt> does not implement {@link Comparable}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *         Implementations may, but are not required to, throw this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *         exception if <tt>toElement</tt> cannot be compared to elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *         currently in the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @throws NullPointerException if <tt>toElement</tt> is null and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *         this set does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @throws IllegalArgumentException if this set itself has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *         restricted range, and <tt>toElement</tt> lies outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         bounds of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    SortedSet<E> headSet(E toElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Returns a view of the portion of this set whose elements are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * greater than or equal to <tt>fromElement</tt>.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * set is backed by this set, so changes in the returned set are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * reflected in this set, and vice-versa.  The returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * supports all optional set operations that this set supports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * on an attempt to insert an element outside its range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param fromElement low endpoint (inclusive) of the returned set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return a view of the portion of this set whose elements are greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         than or equal to <tt>fromElement</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @throws ClassCastException if <tt>fromElement</tt> is not compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *         with this set's comparator (or, if the set has no comparator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *         if <tt>fromElement</tt> does not implement {@link Comparable}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *         Implementations may, but are not required to, throw this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *         exception if <tt>fromElement</tt> cannot be compared to elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *         currently in the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @throws NullPointerException if <tt>fromElement</tt> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *         and this set does not permit null elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @throws IllegalArgumentException if this set itself has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *         restricted range, and <tt>fromElement</tt> lies outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *         bounds of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    SortedSet<E> tailSet(E fromElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Returns the first (lowest) element currently in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the first (lowest) element currently in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @throws NoSuchElementException if this set is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    E first();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns the last (highest) element currently in this set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return the last (highest) element currently in this set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @throws NoSuchElementException if this set is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    E last();
16929
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   222
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   223
    /**
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   224
     * Creates a {@code Spliterator} over the elements in this sorted set.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   225
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   226
     * <p>The {@code Spliterator} reports {@link Spliterator#SIZED},
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   227
     * {@link Spliterator#DISTINCT}, {@link Spliterator#SORTED} and
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   228
     * {@link Spliterator#ORDERED}.  Implementations should document the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   229
     * reporting of additional characteristic values.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   230
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   231
     * <p>The spliterator's comparator (see
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   232
     * {@link java.util.Spliterator#getComparator()}) must be {@code null} if
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   233
     * the sorted set's comparator (see {@link #comparator()}) is {@code null}.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   234
     * Otherwise, the spliterator's comparator must be the same as or impose the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   235
     * same total ordering as the sorted set's comparator.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   236
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   237
     * @implSpec
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   238
     * The default implementation creates a
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   239
     * <em><a href="Spliterator.html#binding">late-binding</a></em> spliterator
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   240
     * from the sorted set's {@code Iterator}.  The spliterator inherits the
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   241
     * <em>fail-fast</em> properties of the collection's iterator.  The
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   242
     * spliterator's comparator is the same as the sorted set's comparator.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   243
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   244
     * @implNote
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   245
     * The created {@code Spliterator} additionally reports
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   246
     * {@link Spliterator#SUBSIZED}.
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   247
     *
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   248
     * @return a {@code Spliterator} over the elements in this sorted set
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   249
     * @since 1.8
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   250
     */
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   251
    @Override
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   252
    default Spliterator<E> spliterator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   253
        return new Spliterators.IteratorSpliterator<E>(
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   254
                this, Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED) {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   255
            @Override
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   256
            public Comparator<? super E> getComparator() {
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   257
                return SortedSet.this.comparator();
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   258
            }
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   259
        };
c984ae5655cb 8010096: Initial java.util.Spliterator putback
briangoetz
parents: 5506
diff changeset
   260
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}