Top Description Inners Fields Constructors Methods
com.google.common.collect

public abstract Class ImmutableSortedSet<E>

extends ImmutableSortedSetFauxverideShim<E>
implements NavigableSet<E>, SortedIterable<E>
Class Inheritance
All Implemented Interfaces
com.google.common.collect.SortedIterable, java.lang.Iterable, java.util.NavigableSet, java.util.SortedSet, java.util.SequencedSet, java.util.Set, java.util.Collection, java.util.SequencedCollection
Known Direct Subclasses
com.google.common.collect.RegularImmutableSortedSet, com.google.common.collect.ContiguousSet, com.google.common.collect.DescendingImmutableSortedSet, com.google.common.collect.ImmutableRangeSet.AsSet
Annotations
@GwtCompatible
serializable:true
emulated:true
@SuppressWarnings:serial
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkNotNull, com.google.common.collect.ObjectArrays.checkElementsNotNull

A 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.

Authors
Jared Levy, Louis Wasserman
Since
2.0 (implements NavigableSet since 12.0)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public 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

Field Summary

Modifier and TypeField and Description
pack-priv final transient Comparator<? super E>
pack-priv transient ImmutableSortedSet<E>
pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv
ImmutableSortedSet(Comparator<? super E> comparator)

Method Summary

Modifier and TypeMethod and Description
public E
ceiling(E
the value to match
e
)

Implements java.util.NavigableSet.ceiling.

Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
public Comparator<? super E>
comparator()

Implements java.util.SortedSet.comparator, com.google.common.collect.SortedIterable.comparator.

Returns the comparator that orders the elements, which is Ordering#natural() when the natural ordering of the elements is used.
pack-priv static <E> ImmutableSortedSet<E>
construct(Comparator<? super E> comparator, int n, E... contents)

Constructs an ImmutableSortedSet from the first n elements of contents.

public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
copyOf(E[] elements)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.copyOf.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E> ImmutableSortedSet<E>
copyOf(Iterable<? extends E> elements)

Hides com.google.common.collect.ImmutableSet.copyOf.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E> ImmutableSortedSet<E>
copyOf(Collection<? extends E>
a Collection from which elements are drawn, must be non-null
elements
)

Hides com.google.common.collect.ImmutableSet.copyOf, java.util.Set.copyOf.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E> ImmutableSortedSet<E>
copyOf(Iterator<? extends E> elements)

Hides com.google.common.collect.ImmutableSet.copyOf.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E> ImmutableSortedSet<E>
copyOf(Comparator<? super E> comparator, Iterator<? extends E> elements)

Returns an immutable sorted set containing the given elements sorted by the given Comparator.

public static <E> ImmutableSortedSet<E>
copyOf(Comparator<? super E> comparator, Iterable<? extends E> elements)

Returns an immutable sorted set containing the given elements sorted by the given Comparator.

public static <E> ImmutableSortedSet<E>
copyOf(Comparator<? super E> comparator, Collection<? extends E> elements)

Returns an immutable sorted set containing the given elements sorted by the given Comparator.

public static <E> ImmutableSortedSet<E>
copyOfSorted(SortedSet<E> sortedSet)

Returns an immutable sorted set containing the elements of a sorted set, sorted by the same Comparator.

pack-priv abstract ImmutableSortedSet<E>
public abstract UnmodifiableIterator<E>
descendingIterator()

Redeclares java.util.NavigableSet.descendingIterator.

Returns an iterator over the elements in this set, in descending order.
public ImmutableSortedSet<E>
descendingSet()

Implements java.util.NavigableSet.descendingSet.

Returns a reverse order view of the elements contained in this set.
pack-priv static <E> RegularImmutableSortedSet<E>
emptySet(Comparator<? super E> comparator)

public E
first()

Implements java.util.SortedSet.first.

Returns the first (lowest) element currently in this set.
public E
floor(E
the value to match
e
)

Implements java.util.NavigableSet.floor.

Returns the greatest element in this set less than or equal to the given element, or null if there is no such element.
public ImmutableSortedSet<E>
headSet(E
high endpoint (exclusive) of the returned set
toElement
)

Implements java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are strictly less than toElement.
public ImmutableSortedSet<E>
headSet(E
high endpoint of the returned set
toElement
,
boolean
true if the high endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableSet.headSet.

Returns a view of the portion of this set whose elements are less than (or equal to, if inclusive is true) toElement.
pack-priv abstract ImmutableSortedSet<E>
headSetImpl(E toElement, boolean inclusive)

public E
higher(E
the value to match
e
)

Implements java.util.NavigableSet.higher.

Returns the least element in this set strictly greater than the given element, or null if there is no such element.
pack-priv abstract int
indexOf(Object target)

Returns the position of an element within the set, or -1 if not present.

public abstract UnmodifiableIterator<E>
public E
last()

Implements java.util.SortedSet.last.

Returns the last (highest) element currently in this set.
public E
lower(E
the value to match
e
)

Implements java.util.NavigableSet.lower.

Returns the greatest element in this set strictly less than the given element, or null if there is no such element.
public static <E extends Comparable<?>> ImmutableSortedSet.Builder<E>
naturalOrder()

Returns a builder that creates immutable sorted sets whose elements are ordered by their natural ordering.

public static <E> ImmutableSortedSet<E>
of()

Hides com.google.common.collect.ImmutableSet.of, java.util.Set.of.

Returns the empty immutable sorted set.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the single element
element
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing a single element.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the first element
e1
,
E
the second element
e2
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E extends Comparable<? super E>> ImmutableSortedSet<E>
of(E
the first element
e1
,
E
the second element
e2
,
E
the third element
e3
,
E
the fourth element
e4
,
E
the fifth element
e5
,
E
the sixth element
e6
,
E...
the seventh element
remaining
)

Hides com.google.common.collect.ImmutableSortedSetFauxverideShim.of, java.util.Set.of.

Returns an immutable sorted set containing the given elements sorted by their natural ordering.
public static <E> ImmutableSortedSet.Builder<E>
orderedBy(Comparator<E> comparator)

Returns a builder that creates immutable sorted sets with an explicit comparator.

public final E
pollFirst()

Implements java.util.NavigableSet.pollFirst.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the set unmodified.
public final E
pollLast()

Implements java.util.NavigableSet.pollLast.

Deprecated Unsupported operation.
Guaranteed to throw an exception and leave the set unmodified.
private void
public static <E extends Comparable<?>> ImmutableSortedSet.Builder<E>
reverseOrder()

Returns a builder that creates immutable sorted sets whose elements are ordered by the reverse of their natural ordering.

public Spliterator<E>
public ImmutableSortedSet<E>
subSet(E
low endpoint (inclusive) of the returned set
fromElement
,
E
high endpoint (exclusive) of the returned set
toElement
)

Implements java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement, inclusive, to toElement, exclusive.
public ImmutableSortedSet<E>
subSet(E
low endpoint of the returned set
fromElement
,
boolean
true if the low endpoint is to be included in the returned view
fromInclusive
,
E
high endpoint of the returned set
toElement
,
boolean
true if the high endpoint is to be included in the returned view
toInclusive
)

Implements java.util.NavigableSet.subSet.

Returns a view of the portion of this set whose elements range from fromElement to toElement.
pack-priv abstract ImmutableSortedSet<E>
subSetImpl(E fromElement, boolean fromInclusive, E toElement, boolean toInclusive)

public ImmutableSortedSet<E>
tailSet(E
low endpoint (inclusive) of the returned set
fromElement
)

Implements java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than or equal to fromElement.
public ImmutableSortedSet<E>
tailSet(E
low endpoint of the returned set
fromElement
,
boolean
true if the low endpoint is to be included in the returned view
inclusive
)

Implements java.util.NavigableSet.tailSet.

Returns a view of the portion of this set whose elements are greater than (or equal to, if inclusive is true) fromElement.
pack-priv abstract ImmutableSortedSet<E>
tailSetImpl(E fromElement, boolean inclusive)

public static <E> Collector<E, ?, ImmutableSortedSet<E>>
toImmutableSortedSet(Comparator<? super E> comparator)

Returns a Collector that accumulates the input elements into a new ImmutableSortedSet, ordered by the specified comparator.

pack-priv int
pack-priv static int
unsafeCompare(Comparator<?> comparator, Object a, Object b)

pack-priv Object
Inherited from com.google.common.collect.ImmutableSortedSetFauxverideShim:
builderbuilderWithExpectedSizetoImmutableSet