--- jsr166/src/main/java/util/TreeSet.java 2005/03/06 12:06:17 1.2 +++ jsr166/src/main/java/util/TreeSet.java 2005/03/29 15:00:48 1.4 @@ -255,7 +255,7 @@ public class TreeSet * * @throws ClassCastException if the elements provided cannot be compared * with the elements currently in the set. - * @throws NullPointerException of the specified collection is + * @throws NullPointerException if the specified collection is * null or if any element is null and this map * uses natural ordering, or its comparator does not tolerate * null keys. @@ -278,39 +278,40 @@ public class TreeSet } /** - * Returns a view of the portion of this set whose elements range from - * fromElement, inclusive, to toElement, exclusive. (If - * fromElement and toElement are equal, the returned - * sorted set is empty.) The returned sorted set is backed by this set, - * so changes in the returned sorted set are reflected in this set, and - * vice-versa. The returned sorted set supports all optional Set - * operations.

+ * Returns a view of the portion of this set whose elements range + * from fromElement, inclusive, to toElement, + * exclusive. (If fromElement and toElement are + * equal, the returned navigable set is empty.) The returned + * navigable set is backed by this set, so changes in the returned + * navigable set are reflected in this set, and vice-versa. The + * returned navigable set supports all optional Set operations.

* - * The sorted set returned by this method will throw an + * The navigable set returned by this method will throw an * IllegalArgumentException if the user attempts to insert an * element outside the specified range.

* - * Note: this method always returns a half-open range (which - * includes its low endpoint but not its high endpoint). If you need a - * closed range (which includes both endpoints), and the element - * type allows for calculation of the successor of a specified value, - * merely request the subrange from lowEndpoint to - * successor(highEndpoint). For example, suppose that s - * is a sorted set of strings. The following idiom obtains a view - * containing all of the strings in s from low to - * high, inclusive:

-     *     NavigableSet sub = s.subSet(low, high+"\0");
+     * Note: this method always returns a half-open range
+     * (which includes its low endpoint but not its high endpoint).
+     * If you need a closed range (which includes both
+     * endpoints), and the element type allows for calculation of the
+     * successor of a specified value, merely request the subrange
+     * from lowEndpoint to successor(highEndpoint).
+     * For example, suppose that s is a navigable set of
+     * strings.  The following idiom obtains a view containing all of
+     * the strings in s from low to high,
+     * inclusive: 
+     * 
 NavigableSet sub = s.navigableSubSet(low, high+"\0");
      * 
* * A similar technique can be used to generate an open range (which * contains neither endpoint). The following idiom obtains a view * containing all of the strings in s from low to * high, exclusive:
-     *     NavigableSet sub = s.subSet(low+"\0", high);
+     *     NavigableSet sub = s.navigableSubSet(low+"\0", high);
      * 
* - * @param fromElement low endpoint (inclusive) of the subSet. - * @param toElement high endpoint (exclusive) of the subSet. + * @param fromElement low endpoint (inclusive) of the range. + * @param toElement high endpoint (exclusive) of the range. * @return a view of the portion of this set whose elements range from * fromElement, inclusive, to toElement, * exclusive. @@ -325,67 +326,69 @@ public class TreeSet * order, or its comparator does not tolerate null * elements. */ - public NavigableSet subSet(E fromElement, E toElement) { - return new TreeSet(m.subMap(fromElement, toElement)); + public NavigableSet navigableSubSet(E fromElement, E toElement) { + return new TreeSet(m.navigableSubMap(fromElement, toElement)); } /** - * Returns a view of the portion of this set whose elements are strictly - * less than toElement. The returned sorted set is backed by - * this set, so changes in the returned sorted set are reflected in this - * set, and vice-versa. The returned sorted set supports all optional set - * operations.

- * - * The sorted set returned by this method will throw an - * IllegalArgumentException if the user attempts to insert an - * element greater than or equal to toElement.

- * - * Note: this method always returns a view that does not contain its - * (high) endpoint. If you need a view that does contain this endpoint, - * and the element type allows for calculation of the successor of a - * specified value, merely request a headSet bounded by - * successor(highEndpoint). For example, suppose that s - * is a sorted set of strings. The following idiom obtains a view - * containing all of the strings in s that are less than or equal - * to high:

 NavigableSet head = s.headSet(high+"\0");
+ * Returns a view of the portion of this set whose elements are + * strictly less than toElement. The returned navigable + * set is backed by this set, so changes in the returned navigable + * set are reflected in this set, and vice-versa. The returned + * navigable set supports all optional set operations.

+ * + * The navigable set returned by this method will throw an + * IllegalArgumentException if the user attempts to + * insert an element greater than or equal to + * toElement.

+ * + * Note: this method always returns a view that does not contain + * its (high) endpoint. If you need a view that does contain this + * endpoint, and the element type allows for calculation of the + * successor of a specified value, merely request a headSet + * bounded by successor(highEndpoint). For example, + * suppose that s is a navigable set of strings. The + * following idiom obtains a view containing all of the strings in + * s that are less than or equal to high: + *

 NavigableSet head = s.navigableHeadSet(high+"\0");
* * @param toElement high endpoint (exclusive) of the headSet. * @return a view of the portion of this set whose elements are strictly - * less than toElement. + * less than toElement. * @throws ClassCastException if toElement is not compatible * with this set's comparator (or, if the set has no comparator, * if toElement does not implement Comparable). - * @throws IllegalArgumentException if this set is itself a subSet, - * headSet, or tailSet, and toElement is not within the - * specified range of the subSet, headSet, or tailSet. + * @throws IllegalArgumentException if this set is itself a subset, + * and toElement is not within the + * specified range of the subset. * @throws NullPointerException if toElement is null and * this set uses natural ordering, or its comparator does * not tolerate null elements. */ - public NavigableSet headSet(E toElement) { - return new TreeSet(m.headMap(toElement)); + public NavigableSet navigableHeadSet(E toElement) { + return new TreeSet(m.navigableHeadMap(toElement)); } /** * Returns a view of the portion of this set whose elements are - * greater than or equal to fromElement. The returned sorted set - * is backed by this set, so changes in the returned sorted set are - * reflected in this set, and vice-versa. The returned sorted set - * supports all optional set operations.

+ * greater than or equal to fromElement. The returned + * navigable set is backed by this set, so changes in the returned + * navigable set are reflected in this set, and vice-versa. The + * returned navigable set supports all optional set operations.

* - * The sorted set returned by this method will throw an + * The navigable set returned by this method will throw an * IllegalArgumentException if the user attempts to insert an * element less than fromElement. * * Note: this method always returns a view that contains its (low) - * endpoint. If you need a view that does not contain this endpoint, and - * the element type allows for calculation of the successor of a specified - * value, merely request a tailSet bounded by - * successor(lowEndpoint). For example, suppose that s - * is a sorted set of strings. The following idiom obtains a view - * containing all of the strings in s that are strictly greater - * than low:

-     *     NavigableSet tail = s.tailSet(low+"\0");
+     * endpoint.  If you need a view that does not contain this
+     * endpoint, and the element type allows for calculation of the
+     * successor of a specified value, merely request a tailSet
+     * bounded by successor(lowEndpoint).  For example,
+     * suppose that s is a navigable set of strings.  The
+     * following idiom obtains a view containing all of the strings in
+     * s that are strictly greater than low:
+     * 
  NavigableSet tail = s.navigableTailSet(low+"\0");
      * 
* * @param fromElement low endpoint (inclusive) of the tailSet. @@ -394,15 +397,80 @@ public class TreeSet * @throws ClassCastException if fromElement is not compatible * with this set's comparator (or, if the set has no comparator, * if fromElement does not implement Comparable). + * @throws IllegalArgumentException if this set is itself a subset, + * and fromElement is not within the + * specified range of the subset. + * @throws NullPointerException if fromElement is null + * and this set uses natural ordering, or its comparator does + * not tolerate null elements. + */ + public NavigableSet navigableTailSet(E fromElement) { + return new TreeSet(m.navigableTailMap(fromElement)); + } + + + /** + * Equivalent to navigableSubSet but with a return + * type conforming to the SortedSet interface. + * @param fromElement low endpoint (inclusive) of the range. + * @param toElement high endpoint (exclusive) of the range. + * @return a view of the portion of this set whose elements range from + * fromElement, inclusive, to toElement, + * exclusive. + * @throws ClassCastException if fromElement and + * toElement cannot be compared to one another using + * this set's comparator (or, if the set has no comparator, + * using natural ordering). + * @throws IllegalArgumentException if fromElement is greater than + * toElement. + * @throws NullPointerException if fromElement or + * toElement is null and this set uses natural + * order, or its comparator does not tolerate null + * elements. + */ + public SortedSet subSet(E fromElement, E toElement) { + return new TreeSet(m.navigableSubMap(fromElement, toElement)); + } + + /** + * Equivalent to navigableHeadSet but with a return + * type conforming to the SortedSet interface. + * + * @param toElement high endpoint (exclusive) of the headSet. + * @return a view of the portion of this set whose elements are strictly + * less than toElement. + * @throws ClassCastException if toElement is not compatible + * with this set's comparator (or, if the set has no comparator, + * if toElement does not implement Comparable). * @throws IllegalArgumentException if this set is itself a subSet, - * headSet, or tailSet, and fromElement is not within the - * specified range of the subSet, headSet, or tailSet. + * and toElement is not within the + * specified range of the subset. + * @throws NullPointerException if toElement is null and + * this set uses natural ordering, or its comparator does + * not tolerate null elements. + */ + public SortedSet headSet(E toElement) { + return new TreeSet(m.navigableHeadMap(toElement)); + } + + /** + * Equivalent to navigableTailSet but with a return + * type conforming to the SortedSet interface. + * @param fromElement low endpoint (inclusive) of the tailSet. + * @return a view of the portion of this set whose elements are + * greater than or equal to fromElement. + * @throws ClassCastException if fromElement is not compatible + * with this set's comparator (or, if the set has no comparator, + * if fromElement does not implement Comparable). + * @throws IllegalArgumentException if this set is itself a subset, + * and fromElement is not within the + * specified range of the subset. * @throws NullPointerException if fromElement is null * and this set uses natural ordering, or its comparator does * not tolerate null elements. */ - public NavigableSet tailSet(E fromElement) { - return new TreeSet(m.tailMap(fromElement)); + public SortedSet tailSet(E fromElement) { + return new TreeSet(m.navigableTailMap(fromElement)); } /**