|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.collect.ImmutableCollection<E>
com.google.common.collect.ImmutableSortedSet<E>
public abstract class ImmutableSortedSet<E>
An immutable SortedSet that stores its elements in a sorted array.
Some instances are ordered by an explicit comparator, while others follow the
natural sort ordering of their elements. Either way, null elements are not
supported.
Unlike Collections.unmodifiableSortedSet(java.util.SortedSet, which is a view
of a separate collection that can still change, an instance of ImmutableSortedSet contains its own private data and will never
change. This class is convenient for public static final sets
("constant sets") and also lets you easily make a "defensive copy" of a set
provided to your class by a caller.
The sets returned by headSet(E), tailSet(E), and
subSet(E, E) methods share the same array as the original set, preventing
that array from being garbage collected. If this is a concern, the data may
be copied into a correctly-sized array by calling copyOfSorted(java.util.SortedSet.
Note on element equivalence: The ImmutableCollection.contains(Object),
ImmutableCollection.containsAll(Collection), and Object.equals(Object)
implementations must check whether a provided object is equivalent to an
element in the collection. Unlike most collections, an
ImmutableSortedSet doesn't use Object.equals(java.lang.Object) to determine if
two elements are equivalent. Instead, with an explicit comparator, the
following relation determines whether elements x and y are
equivalent:
{(x, y) | comparator.compare(x, y) == 0}
With natural ordering of elements, the following relation determines whether two elements are equivalent:
{(x, y) | x.compareTo(y) == 0}
Warning: Like most sets, an ImmutableSortedSet will not
function correctly if an element is modified after being placed in the set.
For this reason, and to avoid general confusion, it is strongly recommended
to place only immutable objects into this collection.
Note: Although this class is not final, it cannot be subclassed as it has no public or protected constructors. Thus, instances of this type are guaranteed to be immutable.
ImmutableSet,
Serialized Form| Method Summary | ||
|---|---|---|
java.util.Comparator<? super E> |
comparator()
Returns the comparator that orders the elements, which is Comparators.naturalOrder() when the natural ordering of the
elements is used. |
|
static
|
copyOf(java.util.Comparator<? super E> comparator,
java.lang.Iterable<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by the provided comparator. |
|
static
|
copyOf(java.lang.Iterable<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by their natural ordering. |
|
static
|
copyOfSorted(java.util.SortedSet<E> sortedSet)
Returns an immutable sorted set containing the elements of a sorted set, sorted by the same Comparator. |
|
ImmutableSortedSet<E> |
headSet(E toElement)
|
|
static
|
of()
Returns the empty immutable sorted set. |
|
static
|
of(java.util.Comparator<? super E> comparator,
E... elements)
Returns an immutable sorted set containing the given elements sorted by the provided comparator. |
|
static
|
of(E... elements)
Returns an immutable sorted set containing the given elements sorted by their natural ordering. |
|
ImmutableSortedSet<E> |
subSet(E fromElement,
E toElement)
|
|
ImmutableSortedSet<E> |
tailSet(E fromElement)
|
|
| Methods inherited from class com.google.common.collect.ImmutableCollection |
|---|
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.SortedSet |
|---|
first, last |
| Methods inherited from interface java.util.Set |
|---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
| Method Detail |
|---|
public static <E extends java.lang.Comparable> ImmutableSortedSet<E> of()
The type specification is <E extends Comparable>, instead of the
more specific <E extends Comparable<? super E>>, to support
classes defined without generics.
public static <E extends java.lang.Comparable> ImmutableSortedSet<E> of(E... elements)
Comparable.compareTo(T), only the first one specified is included.
The type specification is <E extends Comparable>, instead of the
more specific <E extends Comparable<? super E>>, to support
classes defined without generics.
java.lang.NullPointerException - if any of elements is null
public static <E> ImmutableSortedSet<E> of(java.util.Comparator<? super E> comparator,
E... elements)
java.lang.NullPointerException - if comparator or any of
elements is nullpublic static <E extends java.lang.Comparable> ImmutableSortedSet<E> copyOf(java.lang.Iterable<? extends E> elements)
compareTo(), only the first one specified is included. To create a
copy of a SortedSet that preserves the comparator, call
copyOfSorted(java.util.SortedSet) instead.
Note that if s is a Set<String>, then
ImmutableSortedSet.copyOf(s) returns a
ImmutableSortedSet<String> containing each of the strings in
s, while ImmutableSortedSet.of(s) returns a
ImmutableSortedSet<Set<String>> containing one element (the given
set itself).
Note: Despite what the method name suggests, if elements
is an ImmutableSortedSet, it may be returned instead of a copy.
The type specification is <E extends Comparable>, instead of the
more specific <E extends Comparable<? super E>>, to support
classes defined without generics.
java.lang.NullPointerException - if any of elements is null
public static <E> ImmutableSortedSet<E> copyOf(java.util.Comparator<? super E> comparator,
java.lang.Iterable<? extends E> elements)
Note: Despite what the method name suggests, if elements
is an ImmutableSortedSet, it may be returned instead of a copy.
java.lang.NullPointerException - if comparator or any of
elements is nullpublic static <E> ImmutableSortedSet<E> copyOfSorted(java.util.SortedSet<E> sortedSet)
Comparator. That behavior differs from
copyOf(Iterable), which always uses the natural ordering of the
elements.
Note: Despite what the method name suggests, if sortedSet
is an ImmutableSortedSet, it may be returned instead of a copy.
java.lang.NullPointerException - if any of elements is nullpublic java.util.Comparator<? super E> comparator()
Comparators.naturalOrder() when the natural ordering of the
elements is used. Note that its behavior is not consistent with
SortedSet.comparator(), which returns null to indicate
natural ordering.
comparator in interface java.util.SortedSet<E>public ImmutableSortedSet<E> headSet(E toElement)
This method returns a serializable ImmutableSortedSet.
The SortedSet.headSet(E) documentation states that a subset of a
subset throws an IllegalArgumentException if passed a
toElement greater than an earlier toElement. However, this
method doesn't throw an exception in that situation, but instead keeps the
original toElement.
headSet in interface java.util.SortedSet<E>
public ImmutableSortedSet<E> subSet(E fromElement,
E toElement)
This method returns a serializable ImmutableSortedSet.
The SortedSet.subSet(E, E) documentation states that a subset of a
subset throws an IllegalArgumentException if passed a
fromElement smaller than an earlier toElement. However,
this method doesn't throw an exception in that situation, but instead keeps
the original fromElement. Similarly, this method keeps the
original toElement, instead of throwing an exception, if passed a
toElement greater than an earlier toElement.
subSet in interface java.util.SortedSet<E>public ImmutableSortedSet<E> tailSet(E fromElement)
This method returns a serializable ImmutableSortedSet.
The SortedSet.tailSet(E) documentation states that a subset of a
subset throws an IllegalArgumentException if passed a
fromElement smaller than an earlier fromElement. However,
this method doesn't throw an exception in that situation, but instead keeps
the original fromElement.
tailSet in interface java.util.SortedSet<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||