@GwtCompatible(serializable=true, emulated=true) public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E> implements java.util.NavigableSet<E>, SortedIterable<E>
NavigableSet whose contents will never change, with many other important properties
detailed at ImmutableCollection.
Warning: as with any sorted collection, you are strongly advised not to use a Comparator or Comparable type whose comparison behavior is inconsistent with
equals. That is, a.compareTo(b) or comparator.compare(a, b) should equal zero
if and only if a.equals(b). If this advice is not followed, the resulting
collection will not correctly obey its specification.
See the Guava User Guide article on immutable collections.
NavigableSet since 12.0)| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableSortedSet.Builder<E>
A builder for creating immutable sorted set instances, especially
public static final sets ("constant sets"), with a given comparator. |
private static class |
ImmutableSortedSet.SerializedForm<E> |
ImmutableSet.Indexed<E>ImmutableCollection.ArrayBasedBuilder<E>| Modifier and Type | Field and Description |
|---|---|
(package private) java.util.Comparator<? super E> |
comparator |
(package private) ImmutableSortedSet<E> |
descendingSet |
MAX_TABLE_SIZE| Constructor and Description |
|---|
ImmutableSortedSet(java.util.Comparator<? super E> comparator) |
| Modifier and Type | Method and Description |
|---|---|
E |
ceiling(E e) |
java.util.Comparator<? super E> |
comparator()
Returns the comparator that orders the elements, which is
Ordering.natural() when the natural ordering of the
elements is used. |
(package private) static <E> ImmutableSortedSet<E> |
construct(java.util.Comparator<? super E> comparator,
int n,
E... contents)
Constructs an
ImmutableSortedSet from the first n elements of
contents. |
static <E> ImmutableSortedSet<E> |
copyOf(java.util.Collection<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E> ImmutableSortedSet<E> |
copyOf(java.util.Comparator<? super E> comparator,
java.util.Collection<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by
the given
Comparator. |
static <E> ImmutableSortedSet<E> |
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 given
Comparator. |
static <E> ImmutableSortedSet<E> |
copyOf(java.util.Comparator<? super E> comparator,
java.util.Iterator<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by
the given
Comparator. |
static <E extends java.lang.Comparable<? super E>> |
copyOf(E[] elements)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E> ImmutableSortedSet<E> |
copyOf(java.lang.Iterable<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E> ImmutableSortedSet<E> |
copyOf(java.util.Iterator<? extends E> elements)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E> ImmutableSortedSet<E> |
copyOfSorted(java.util.SortedSet<E> sortedSet)
Returns an immutable sorted set containing the elements of a sorted set,
sorted by the same
Comparator. |
(package private) ImmutableSortedSet<E> |
createDescendingSet() |
abstract UnmodifiableIterator<E> |
descendingIterator() |
ImmutableSortedSet<E> |
descendingSet() |
(package private) static <E> RegularImmutableSortedSet<E> |
emptySet(java.util.Comparator<? super E> comparator) |
E |
first() |
E |
floor(E e) |
ImmutableSortedSet<E> |
headSet(E toElement) |
ImmutableSortedSet<E> |
headSet(E toElement,
boolean inclusive) |
(package private) abstract ImmutableSortedSet<E> |
headSetImpl(E toElement,
boolean inclusive) |
E |
higher(E e) |
(package private) abstract int |
indexOf(java.lang.Object target)
Returns the position of an element within the set, or -1 if not present.
|
abstract UnmodifiableIterator<E> |
iterator()
Returns an unmodifiable iterator across the elements in this collection.
|
E |
last() |
E |
lower(E e) |
static <E extends java.lang.Comparable<?>> |
naturalOrder()
Returns a builder that creates immutable sorted sets whose elements are
ordered by their natural ordering.
|
static <E> ImmutableSortedSet<E> |
of()
Returns the empty immutable sorted set.
|
static <E extends java.lang.Comparable<? super E>> |
of(E element)
Returns an immutable sorted set containing a single element.
|
static <E extends java.lang.Comparable<? super E>> |
of(E e1,
E e2)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E extends java.lang.Comparable<? super E>> |
of(E e1,
E e2,
E e3)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E extends java.lang.Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E extends java.lang.Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4,
E e5)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E extends java.lang.Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E... remaining)
Returns an immutable sorted set containing the given elements sorted by
their natural ordering.
|
static <E> ImmutableSortedSet.Builder<E> |
orderedBy(java.util.Comparator<E> comparator)
Returns a builder that creates immutable sorted sets with an explicit
comparator.
|
E |
pollFirst()
Deprecated.
Unsupported operation.
|
E |
pollLast()
Deprecated.
Unsupported operation.
|
private void |
readObject(java.io.ObjectInputStream stream) |
static <E extends java.lang.Comparable<?>> |
reverseOrder()
Returns a builder that creates immutable sorted sets whose elements are
ordered by the reverse of their natural ordering.
|
ImmutableSortedSet<E> |
subSet(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive) |
ImmutableSortedSet<E> |
subSet(E fromElement,
E toElement) |
(package private) abstract ImmutableSortedSet<E> |
subSetImpl(E fromElement,
boolean fromInclusive,
E toElement,
boolean toInclusive) |
ImmutableSortedSet<E> |
tailSet(E fromElement) |
ImmutableSortedSet<E> |
tailSet(E fromElement,
boolean inclusive) |
(package private) abstract ImmutableSortedSet<E> |
tailSetImpl(E fromElement,
boolean inclusive) |
(package private) static int |
unsafeCompare(java.util.Comparator<?> comparator,
java.lang.Object a,
java.lang.Object b) |
(package private) int |
unsafeCompare(java.lang.Object a,
java.lang.Object b) |
(package private) java.lang.Object |
writeReplace() |
builderasList, chooseTableSize, createAsList, equals, hashCode, isHashCodeFastadd, addAll, clear, contains, copyIntoArray, isPartialView, remove, removeAll, retainAll, toArray, toArrayclone, finalize, getClass, notify, notifyAll, wait, wait, waitfinal transient java.util.Comparator<? super E> comparator
@GwtIncompatible transient ImmutableSortedSet<E> descendingSet
ImmutableSortedSet(java.util.Comparator<? super E> comparator)
static <E> RegularImmutableSortedSet<E> emptySet(java.util.Comparator<? super E> comparator)
public static <E> ImmutableSortedSet<E> of()
public static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E element)
public static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any element is nullpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2, E e3)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any element is nullpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any element is nullpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any element is nullpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any element is nullpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedSet<E> copyOf(E[] elements)
Comparable.compareTo(T), only the first one specified is included.java.lang.NullPointerException - if any of elements is nullpublic static <E> 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<E>) instead. This method iterates over elements at most
once.
Note that if s is a Set<String>, then ImmutableSortedSet.copyOf(s) returns an ImmutableSortedSet<String>
containing each of the strings in s, while ImmutableSortedSet.of(s) returns an ImmutableSortedSet<Set<String>> containing one element (the given set
itself).
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
This method is not type-safe, as it may be called on elements that are not mutually comparable.
java.lang.ClassCastException - if the elements are not mutually comparablejava.lang.NullPointerException - if any of elements is nullpublic static <E> ImmutableSortedSet<E> copyOf(java.util.Collection<? 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<E>) instead. This method iterates over elements
at most once.
Note that if s is a Set<String>, then
ImmutableSortedSet.copyOf(s) returns an
ImmutableSortedSet<String> containing each of the strings in
s, while ImmutableSortedSet.of(s) returns an
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.
This method is not type-safe, as it may be called on elements that are not mutually comparable.
This method is safe to use even when elements is a synchronized
or concurrent collection that is currently being modified by another
thread.
java.lang.ClassCastException - if the elements are not mutually comparablejava.lang.NullPointerException - if any of elements is nullpublic static <E> ImmutableSortedSet<E> copyOf(java.util.Iterator<? extends E> elements)
compareTo(), only the first one specified is included.
This method is not type-safe, as it may be called on elements that are not mutually comparable.
java.lang.ClassCastException - if the elements are not mutually comparablejava.lang.NullPointerException - if any of elements is nullpublic static <E> ImmutableSortedSet<E> copyOf(java.util.Comparator<? super E> comparator, java.util.Iterator<? extends E> elements)
Comparator. When multiple elements are equivalent
according to compareTo(), only the first one specified is
included.java.lang.NullPointerException - if comparator or any of
elements is nullpublic static <E> ImmutableSortedSet<E> copyOf(java.util.Comparator<? super E> comparator, java.lang.Iterable<? extends E> elements)
Comparator. When multiple elements are equivalent
according to compare(), only the first one specified is
included. This method iterates over elements at most once.
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
java.lang.NullPointerException - if comparator or any of elements is nullpublic static <E> ImmutableSortedSet<E> copyOf(java.util.Comparator<? super E> comparator, java.util.Collection<? extends E> elements)
Comparator. When multiple elements are equivalent
according to compareTo(), only the first one specified is
included.
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
This method is safe to use even when elements is a synchronized
or concurrent collection that is currently being modified by another
thread.
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.
Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.
This method is safe to use even when sortedSet is a synchronized
or concurrent collection that is currently being modified by another
thread.
java.lang.NullPointerException - if sortedSet or any of its elements
is nullstatic <E> ImmutableSortedSet<E> construct(java.util.Comparator<? super E> comparator, int n, E... contents)
ImmutableSortedSet from the first n elements of
contents. If k is the size of the returned ImmutableSortedSet, then
the sorted unique elements are in the first k positions of contents, and
contents[i] == null for k <= i < n.
If k == contents.length, then contents may no longer be safe for
modification.
java.lang.NullPointerException - if any of the first n elements of contents is
nullpublic static <E> ImmutableSortedSet.Builder<E> orderedBy(java.util.Comparator<E> comparator)
SortedSet<Integer> with a
Comparator<Number>, use the ImmutableSortedSet.Builder constructor instead.java.lang.NullPointerException - if comparator is nullpublic static <E extends java.lang.Comparable<?>> ImmutableSortedSet.Builder<E> reverseOrder()
public static <E extends java.lang.Comparable<?>> ImmutableSortedSet.Builder<E> naturalOrder()
Ordering.natural() as the comparator. This method provides more
type-safety than ImmutableSortedSetFauxverideShim.builder(), as it can be called only for classes
that implement Comparable.int unsafeCompare(java.lang.Object a,
java.lang.Object b)
static int unsafeCompare(java.util.Comparator<?> comparator,
java.lang.Object a,
java.lang.Object b)
public java.util.Comparator<? super E> comparator()
Ordering.natural() 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 SortedIterable<E>comparator in interface java.util.SortedSet<E>public abstract UnmodifiableIterator<E> iterator()
ImmutableCollectioniterator in interface SortedIterable<E>iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in interface java.util.NavigableSet<E>iterator in interface java.util.Set<E>iterator in class ImmutableSet<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.
@GwtIncompatible public ImmutableSortedSet<E> headSet(E toElement, boolean inclusive)
headSet in interface java.util.NavigableSet<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 fromElement. 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.
@GwtIncompatible public ImmutableSortedSet<E> subSet(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
subSet in interface java.util.NavigableSet<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.
@GwtIncompatible public ImmutableSortedSet<E> tailSet(E fromElement, boolean inclusive)
tailSet in interface java.util.NavigableSet<E>abstract ImmutableSortedSet<E> headSetImpl(E toElement, boolean inclusive)
abstract ImmutableSortedSet<E> subSetImpl(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)
abstract ImmutableSortedSet<E> tailSetImpl(E fromElement, boolean inclusive)
@GwtIncompatible public E lower(E e)
lower in interface java.util.NavigableSet<E>@GwtIncompatible public E floor(E e)
floor in interface java.util.NavigableSet<E>@GwtIncompatible public E ceiling(E e)
ceiling in interface java.util.NavigableSet<E>@GwtIncompatible public E higher(E e)
higher in interface java.util.NavigableSet<E>@Deprecated @GwtIncompatible public final E pollFirst()
pollFirst in interface java.util.NavigableSet<E>java.lang.UnsupportedOperationException - always@Deprecated @GwtIncompatible public final E pollLast()
pollLast in interface java.util.NavigableSet<E>java.lang.UnsupportedOperationException - always@GwtIncompatible public ImmutableSortedSet<E> descendingSet()
descendingSet in interface java.util.NavigableSet<E>@GwtIncompatible ImmutableSortedSet<E> createDescendingSet()
@GwtIncompatible public abstract UnmodifiableIterator<E> descendingIterator()
descendingIterator in interface java.util.NavigableSet<E>abstract int indexOf(@Nullable
java.lang.Object target)
private void readObject(java.io.ObjectInputStream stream)
throws java.io.InvalidObjectException
java.io.InvalidObjectExceptionjava.lang.Object writeReplace()
writeReplace in class ImmutableSet<E>