[all packages] [package java.util] [class hierarchy] [index]

public interface java.util.SortedSet<A>

(source file: SortedSet.java)
java.lang.Object
   |
   +----java.util.SortedSet<A>

The pure class interface.
public interface SortedSet<A>
  implements Set<A>
A Set that further guarantees that it will be in ascending element order, sorted according to the natural sort method of its elements (see Comparable), or by a Comparator provided at SortedSet creation time. Several additional operations are provided to take advantage of the ordering. (This interface is the Set analogue of SortedMap.)

All elements inserted into an SortedSet must implement the Comparable interface. Furthermore, all such elements must be mutually comparable: k1.compareTo(k2) must not throw a typeMismatchException for any elements k1 and k2 in the TreeSet. Attempts to violate this restriction will cause the offending method or constructor invocation to throw a ClassCastException.

All general-purpose SortedSet implementation classes should provide four "standard" constructors: 1) A void (no arguments) constructor, which creates an empty SortedSet sorted according to the natural sort method of its elements. 2) A constructor with a single argument of type Comparator, which creates an empty SortedSet sorted according to the specified Comparator. 3) A constructor with a single argument of type Collection, which creates a new Set with the same elements as its argument, sorted according to the elements' natural sort method. 4) A constructor with a single argument of type SortedSet, which creates a new SortedSet with the same elements and the same ordering as the input SortedSet. There is no way to enforce this recommendation (as interfaces cannot contain constructors) but the JDK implementation (TreeSet) complies.

See also:
Set, TreeSet, SortedMap, Collection, ClassCastException

Methods

O comparator()
Returns the Comparator associated with this SortedSet, or null if it uses its elements'
O first()
Returns the first (lowest) element currently in this SortedSet.
O headSet(A)
Returns a view of the portion of this SortedSet whose elements are strictly less than
O last()
Returns the last (highest) element currently in this SortedSet.
O subSet(A, A)
Returns a view of the portion of this SortedSet whose elements range from fromElement,
O tailSet(A)
Returns a view of the portion of this SortedSet whose elements are greater than or equal

Methods

O comparator
public abstract Comparator<A> comparator();
Returns the Comparator associated with this SortedSet, or null if it uses its elements' natural sort method.

Returns:
the Comparator associated with this SortedSet, or null if it uses its elements' natural sort method.

O subSet

public abstract SortedSet<A> subSet(A fromElement,
                                    A toElement);
Returns a view of the portion of this SortedSet whose elements range from fromElement, inclusive, to toElement, exclusive. The returned SortedSet is backed by this SortedSet, so changes in the returned SortedSet are reflected in this SortedSet, and vice-versa. The returned Set supports all optional Set operations. The Set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.

Parameters:
fromElement - low endpoint (inclusive) of the subSet.
toElement - high endpoint (exclusive) of the subSet.
Returns:
a view of the specified range within this SortedSet.
Throws:
ClassCastException -fromElement or toElement cannot be compared with the elements currently in the SortedSet.
NullPointerException -fromElement or toElement is null and this SortedSet does not tolerate null elements.
IllegalArgumentException -fromElement is greater than toElement.

O headSet

public abstract SortedSet<A> headSet(A toElement);
Returns a view of the portion of this SortedSet whose elements are strictly less than toElement. The returned SortedSet is backed by this SortedSet, so changes in the returned SortedSet are reflected in this SortedSet, and vice-versa. The returned Set supports all optional Set operations.

The Set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.

Parameters:
toElement - high endpoint (exclusive) of the headSet.
Returns:
a view of the specified initial range of this SortedSet.
Throws:
ClassCastException -toElement cannot be compared with the elements currently in the SortedSet.
NullPointerException -toElement is null and this SortedSet does not tolerate null elements.

O tailSet

public abstract SortedSet<A> tailSet(A fromElement);
Returns a view of the portion of this SortedSet whose elements are greater than or equal to fromElement. The returned SortedSet is backed by this SortedSet, so changes in the returned SortedSet are reflected in this SortedSet, and vice-versa. The returned Set supports all optional Set operations. The Set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.

Parameters:
toElement - high endpoint (exclusive) of the tailSet.
Returns:
a view of the specified final range of this SortedSet.
Throws:
ClassCastException -toElement cannot be compared with the elements currently in the SortedSet.
NullPointerException -fromElement is null and this SortedSet does not tolerate null elements.

O first

public abstract A first();
Returns the first (lowest) element currently in this SortedSet.

Returns:
the first (lowest) element currently in this SortedSet.
Throws:
NoSuchElementException -Set is empty.

O last

public abstract A last();
Returns the last (highest) element currently in this SortedSet.

Returns:
the last (highest) element currently in this SortedSet.
Throws:
NoSuchElementException -Set is empty.


[all packages] [package java.util] [class hierarchy] [index]
java.util.SortedSet.html