ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/NavigableSet.java
(Generate patch)

Comparing jsr166/src/main/java/util/NavigableSet.java (file contents):
Revision 1.17 by jsr166, Thu Apr 20 21:55:42 2006 UTC vs.
Revision 1.32 by jsr166, Sat May 6 06:49:46 2017 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea and Josh Bloch with assistance from members of JCP
3   * JSR-166 Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   package java.util;
8  
9   /**
10   * A {@link SortedSet} extended with navigation methods reporting
11 < * closest matches for given search targets. Methods <tt>lower},
12 < * {@code floor}, {@code ceiling}, and {@code higher} return elements
11 > * closest matches for given search targets. Methods {@link #lower},
12 > * {@link #floor}, {@link #ceiling}, and {@link #higher} return elements
13   * respectively less than, less than or equal, greater than or equal,
14   * and greater than a given element, returning {@code null} if there
15 < * is no such element.  A {@code NavigableSet} may be accessed and
16 < * traversed in either ascending or descending order.  The {@code
17 < * descendingSet} method returns a view of the set with the senses of
18 < * all relational and directional methods inverted. The performance of
19 < * ascending operations and views is likely to be faster than that of
20 < * descending ones.  This interface additionally defines methods
21 < * {@code pollFirst} and {@code pollLast} that return and remove the
22 < * lowest and highest element, if one exists, else returning {@code
23 < * null}.  Methods {@code subSet}, {@code headSet},
24 < * and {@code tailSet} differ from the like-named {@code
25 < * SortedSet} methods in accepting additional arguments describing
26 < * whether lower and upper bounds are inclusive versus exclusive.
27 < * Subsets of any {@code NavigableSet} must implement the {@code
28 < * NavigableSet} interface.
15 > * is no such element.
16   *
17 < * <p> The return values of navigation methods may be ambiguous in
17 > * <p>A {@code NavigableSet} may be accessed and traversed in either
18 > * ascending or descending order.  The {@link #descendingSet} method
19 > * returns a view of the set with the senses of all relational and
20 > * directional methods inverted. The performance of ascending
21 > * operations and views is likely to be faster than that of descending
22 > * ones.  This interface additionally defines methods {@link
23 > * #pollFirst} and {@link #pollLast} that return and remove the lowest
24 > * and highest element, if one exists, else returning {@code null}.
25 > * Methods
26 > * {@link #subSet(Object, boolean, Object, boolean) subSet(E, boolean, E, boolean)},
27 > * {@link #headSet(Object, boolean) headSet(E, boolean)}, and
28 > * {@link #tailSet(Object, boolean) tailSet(E, boolean)}
29 > * differ from the like-named {@code SortedSet} methods in accepting
30 > * additional arguments describing whether lower and upper bounds are
31 > * inclusive versus exclusive.  Subsets of any {@code NavigableSet}
32 > * must implement the {@code NavigableSet} interface.
33 > *
34 > * <p>The return values of navigation methods may be ambiguous in
35   * implementations that permit {@code null} elements. However, even
36   * in this case the result can be disambiguated by checking
37   * {@code contains(null)}. To avoid such issues, implementations of
# Line 35 | Line 39 | package java.util;
39   * {@code null} elements. (Note that sorted sets of {@link
40   * Comparable} elements intrinsically do not permit {@code null}.)
41   *
42 + * <p>Methods
43 + * {@link #subSet(Object, Object) subSet(E, E)},
44 + * {@link #headSet(Object) headSet(E)}, and
45 + * {@link #tailSet(Object) tailSet(E)}
46 + * are specified to return {@code SortedSet} to allow existing
47 + * implementations of {@code SortedSet} to be compatibly retrofitted to
48 + * implement {@code NavigableSet}, but extensions and implementations
49 + * of this interface are encouraged to override these methods to return
50 + * {@code NavigableSet}.
51 + *
52   * <p>This interface is a member of the
53 < * <a href="{@docRoot}/../guide/collections/index.html">
53 > * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
54   * Java Collections Framework</a>.
55   *
56   * @author Doug Lea
# Line 125 | Line 139 | public interface NavigableSet<E> extends
139      Iterator<E> iterator();
140  
141      /**
142 <     * Returns a {@link NavigableSet} view of the elements contained in this
143 <     * set in descending order.  The descending set is backed by this set, so
144 <     * changes to the set are reflected in the descending set, and vice-versa.
145 <     * If either set is modified while an iteration over the other set is in
146 <     * in progress (except through the iterator's own {@code remove} operation),
147 <     * the results of the iteration are undefined.
142 >     * Returns a reverse order view of the elements contained in this set.
143 >     * The descending set is backed by this set, so changes to the set are
144 >     * reflected in the descending set, and vice-versa.  If either set is
145 >     * modified while an iteration over either set is in progress (except
146 >     * through the iterator's own {@code remove} operation), the results of
147 >     * the iteration are undefined.
148 >     *
149 >     * <p>The returned set has an ordering equivalent to
150 >     * {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}{@code (comparator())}.
151 >     * The expression {@code s.descendingSet().descendingSet()} returns a
152 >     * view of {@code s} essentially equivalent to {@code s}.
153       *
154 <     * @return a navigable set view of the mappings contained in this set,
136 <     *     sorted in descending order
154 >     * @return a reverse order view of this set
155       */
156      NavigableSet<E> descendingSet();
157  
158      /**
159       * Returns an iterator over the elements in this set, in descending order.
160 <     * Equivalent in effect to <tt>descendingSet().iterator()</tt>.
160 >     * Equivalent in effect to {@code descendingSet().iterator()}.
161       *
162       * @return an iterator over the elements in this set, in descending order
163       */
# Line 149 | Line 167 | public interface NavigableSet<E> extends
167       * Returns a view of the portion of this set whose elements range from
168       * {@code fromElement} to {@code toElement}.  If {@code fromElement} and
169       * {@code toElement} are equal, the returned set is empty unless {@code
170 <     * fromExclusive} and {@code toExclusive} are both true.  The returned set
170 >     * fromInclusive} and {@code toInclusive} are both true.  The returned set
171       * is backed by this set, so changes in the returned set are reflected in
172       * this set, and vice-versa.  The returned set supports all optional set
173       * operations that this set supports.
# Line 158 | Line 176 | public interface NavigableSet<E> extends
176       * on an attempt to insert an element outside its range.
177       *
178       * @param fromElement low endpoint of the returned set
179 <     * @param fromInclusive true if the low endpoint ({@code fromElement}) is
180 <     *        to be included in the returned view
179 >     * @param fromInclusive {@code true} if the low endpoint
180 >     *        is to be included in the returned view
181       * @param toElement high endpoint of the returned set
182 <     * @param toInclusive true if the high endpoint ({@code toElement}) is
183 <     *        to be included in the returned view
182 >     * @param toInclusive {@code true} if the high endpoint
183 >     *        is to be included in the returned view
184       * @return a view of the portion of this set whose elements range from
185       *         {@code fromElement}, inclusive, to {@code toElement}, exclusive
186       * @throws ClassCastException if {@code fromElement} and
# Line 194 | Line 212 | public interface NavigableSet<E> extends
212       * on an attempt to insert an element outside its range.
213       *
214       * @param toElement high endpoint of the returned set
215 <     * @param inclusive true if the high endpoint ({@code toElement}) is
216 <     *        to be included in the returned view
215 >     * @param inclusive {@code true} if the high endpoint
216 >     *        is to be included in the returned view
217       * @return a view of the portion of this set whose elements are less than
218       *         (or equal to, if {@code inclusive} is true) {@code toElement}
219       * @throws ClassCastException if {@code toElement} is not compatible
# Line 223 | Line 241 | public interface NavigableSet<E> extends
241       * on an attempt to insert an element outside its range.
242       *
243       * @param fromElement low endpoint of the returned set
244 <     * @param inclusive true if the low endpoint ({@code fromElement}) is
245 <     *        to be included in the returned view
244 >     * @param inclusive {@code true} if the low endpoint
245 >     *        is to be included in the returned view
246       * @return a view of the portion of this set whose elements are greater
247       *         than or equal to {@code fromElement}
248       * @throws ClassCastException if {@code fromElement} is not compatible
# Line 240 | Line 258 | public interface NavigableSet<E> extends
258       *         bounds of the range
259       */
260      NavigableSet<E> tailSet(E fromElement, boolean inclusive);
261 +
262 +    /**
263 +     * {@inheritDoc}
264 +     *
265 +     * <p>Equivalent to {@code subSet(fromElement, true, toElement, false)}.
266 +     *
267 +     * @throws ClassCastException       {@inheritDoc}
268 +     * @throws NullPointerException     {@inheritDoc}
269 +     * @throws IllegalArgumentException {@inheritDoc}
270 +     */
271 +    SortedSet<E> subSet(E fromElement, E toElement);
272 +
273 +    /**
274 +     * {@inheritDoc}
275 +     *
276 +     * <p>Equivalent to {@code headSet(toElement, false)}.
277 +     *
278 +     * @throws ClassCastException       {@inheritDoc}
279 +     * @throws NullPointerException     {@inheritDoc}
280 +     * @throws IllegalArgumentException {@inheritDoc}
281 +     */
282 +    SortedSet<E> headSet(E toElement);
283 +
284 +    /**
285 +     * {@inheritDoc}
286 +     *
287 +     * <p>Equivalent to {@code tailSet(fromElement, true)}.
288 +     *
289 +     * @throws ClassCastException       {@inheritDoc}
290 +     * @throws NullPointerException     {@inheritDoc}
291 +     * @throws IllegalArgumentException {@inheritDoc}
292 +     */
293 +    SortedSet<E> tailSet(E fromElement);
294   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines