@GwtIncompatible public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E> implements SortedMultiset<E>
SortedMultiset
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.
Modifier and Type | Class and Description |
---|---|
static class |
ImmutableSortedMultiset.Builder<E>
A builder for creating immutable multiset instances, especially
public static final
multisets ("constant multisets"). |
Multiset.Entry<E>
Modifier and Type | Method and Description |
---|---|
static <E> ImmutableSortedMultiset.Builder<E> |
builder()
Deprecated.
Use
naturalOrder() , which offers better type-safety. |
Comparator<? super E> |
comparator()
Returns the comparator that orders this multiset, or
Ordering.natural() if the natural
ordering of the elements is used. |
static <E> ImmutableSortedMultiset<E> |
copyOf(Comparator<? super E> comparator,
Iterable<? extends E> elements)
Returns an immutable sorted multiset containing the given elements sorted by the given
Comparator . |
static <E> ImmutableSortedMultiset<E> |
copyOf(Comparator<? super E> comparator,
Iterator<? extends E> elements)
Returns an immutable sorted multiset containing the given elements sorted by the given
Comparator . |
static <E extends Comparable<? super E>> |
copyOf(E[] elements)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E> ImmutableSortedMultiset<E> |
copyOf(Iterable<? extends E> elements)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E> ImmutableSortedMultiset<E> |
copyOf(Iterator<? extends E> elements)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E> ImmutableSortedMultiset<E> |
copyOfSorted(SortedMultiset<E> sortedMultiset)
Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by
the same
Comparator . |
ImmutableSortedMultiset<E> |
descendingMultiset()
Returns a descending view of this multiset.
|
abstract ImmutableSortedSet<E> |
elementSet()
Returns the set of distinct elements contained in this multiset.
|
abstract ImmutableSortedMultiset<E> |
headMultiset(E upperBound,
BoundType boundType)
Returns a view of this multiset restricted to the elements less than
upperBound ,
optionally including upperBound itself. |
static <E extends Comparable<?>> |
naturalOrder()
Returns a builder that creates immutable sorted multisets whose elements are ordered by their
natural ordering.
|
static <E> ImmutableSortedMultiset<E> |
of()
Returns the empty immutable sorted multiset.
|
static <E extends Comparable<? super E>> |
of(E element)
Returns an immutable sorted multiset containing a single element.
|
static <E extends Comparable<? super E>> |
of(E e1,
E e2)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E extends Comparable<? super E>> |
of(E e1,
E e2,
E e3)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E extends Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E extends Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4,
E e5)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E extends Comparable<? super E>> |
of(E e1,
E e2,
E e3,
E e4,
E e5,
E e6,
E... remaining)
Returns an immutable sorted multiset containing the given elements sorted by their natural
ordering.
|
static <E> ImmutableSortedMultiset.Builder<E> |
orderedBy(Comparator<E> comparator)
Returns a builder that creates immutable sorted multisets with an explicit comparator.
|
Multiset.Entry<E> |
pollFirstEntry()
Deprecated.
Unsupported operation.
|
Multiset.Entry<E> |
pollLastEntry()
Deprecated.
Unsupported operation.
|
static <E extends Comparable<?>> |
reverseOrder()
Returns a builder that creates immutable sorted multisets whose elements are ordered by the
reverse of their natural ordering.
|
ImmutableSortedMultiset<E> |
subMultiset(E lowerBound,
BoundType lowerBoundType,
E upperBound,
BoundType upperBoundType)
Returns a view of this multiset restricted to the range between
lowerBound and upperBound . |
abstract ImmutableSortedMultiset<E> |
tailMultiset(E lowerBound,
BoundType boundType)
Returns a view of this multiset restricted to the elements greater than
lowerBound ,
optionally including lowerBound itself. |
static <E> Collector<E,?,ImmutableMultiset<E>> |
toImmutableMultiset()
Deprecated.
|
static <T,E> Collector<T,?,ImmutableMultiset<E>> |
toImmutableMultiset(Function<? super T,? extends E> elementFunction,
ToIntFunction<? super T> countFunction)
Deprecated.
|
static <E> Collector<E,?,ImmutableSortedMultiset<E>> |
toImmutableSortedMultiset(Comparator<? super E> comparator)
Returns a
Collector that accumulates the input elements into a new ImmutableMultiset . |
static <T,E> Collector<T,?,ImmutableSortedMultiset<E>> |
toImmutableSortedMultiset(Comparator<? super E> comparator,
Function<? super T,? extends E> elementFunction,
ToIntFunction<? super T> countFunction)
Returns a
Collector that accumulates elements into an ImmutableSortedMultiset
whose elements are the result of applying elementFunction to the inputs, with counts
equal to the result of applying countFunction to the inputs. |
add, asList, contains, entrySet, equals, hashCode, iterator, remove, setCount, setCount, toString
add, addAll, clear, remove, removeAll, removeIf, retainAll, spliterator, toArray, toArray
containsAll, isEmpty, size
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
entrySet, firstEntry, iterator, lastEntry
add, add, contains, containsAll, count, equals, forEach, forEachEntry, hashCode, remove, remove, removeAll, retainAll, setCount, setCount, size, spliterator, toString
addAll, clear, isEmpty, parallelStream, removeIf, stream, toArray, toArray
@Beta public static <E> Collector<E,?,ImmutableSortedMultiset<E>> toImmutableSortedMultiset(Comparator<? super E> comparator)
Collector
that accumulates the input elements into a new ImmutableMultiset
. Elements are sorted by the specified comparator.
Warning: comparator
should be consistent with equals
as
explained in the Comparator
documentation.
public static <T,E> Collector<T,?,ImmutableSortedMultiset<E>> toImmutableSortedMultiset(Comparator<? super E> comparator, Function<? super T,? extends E> elementFunction, ToIntFunction<? super T> countFunction)
Collector
that accumulates elements into an ImmutableSortedMultiset
whose elements are the result of applying elementFunction
to the inputs, with counts
equal to the result of applying countFunction
to the inputs.
If the mapped elements contain duplicates (according to comparator
), the first
occurrence in encounter order appears in the resulting multiset, with count equal to the sum of
the outputs of countFunction.applyAsInt(t)
for each t
mapped to that element.
public static <E> ImmutableSortedMultiset<E> of()
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E element)
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2)
NullPointerException
- if any element is nullpublic static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3)
NullPointerException
- if any element is nullpublic static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4)
NullPointerException
- if any element is nullpublic static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5)
NullPointerException
- if any element is nullpublic static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining)
NullPointerException
- if any element is nullpublic static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> copyOf(E[] elements)
NullPointerException
- if any of elements
is nullpublic static <E> ImmutableSortedMultiset<E> copyOf(Iterable<? extends E> elements)
SortedMultiset
that preserves the comparator, call
copyOfSorted(com.google.common.collect.SortedMultiset<E>)
instead. This method iterates over elements
at most once.
Note that if s
is a Multiset<String>
, then ImmutableSortedMultiset.copyOf(s)
returns an ImmutableSortedMultiset<String>
containing each of the strings in s
, while ImmutableSortedMultiset.of(s)
returns an ImmutableSortedMultiset<Multiset<String>>
containing one element (the given
multiset 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.
ClassCastException
- if the elements are not mutually comparableNullPointerException
- if any of elements
is nullpublic static <E> ImmutableSortedMultiset<E> copyOf(Iterator<? extends E> elements)
This method is not type-safe, as it may be called on elements that are not mutually comparable.
ClassCastException
- if the elements are not mutually comparableNullPointerException
- if any of elements
is nullpublic static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterator<? extends E> elements)
Comparator
.NullPointerException
- if comparator
or any of elements
is nullpublic static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterable<? extends E> elements)
Comparator
. 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.
NullPointerException
- if comparator
or any of elements
is nullpublic static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset)
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 sortedMultiset
is a synchronized or concurrent
collection that is currently being modified by another thread.
NullPointerException
- if sortedMultiset
or any of its elements is nullpublic final Comparator<? super E> comparator()
SortedMultiset
Ordering.natural()
if the natural
ordering of the elements is used.comparator
in interface SortedMultiset<E>
public abstract ImmutableSortedSet<E> elementSet()
Multiset
If the element set supports any removal operations, these necessarily cause all occurrences of the removed element(s) to be removed from the multiset. Implementations are not expected to support the add operations, although this is possible.
A common use for the element set is to find the number of distinct elements in the multiset:
elementSet().size()
.
elementSet
in interface Multiset<E>
elementSet
in interface SortedMultiset<E>
elementSet
in class ImmutableMultiset<E>
public ImmutableSortedMultiset<E> descendingMultiset()
SortedMultiset
descendingMultiset
in interface SortedMultiset<E>
@CanIgnoreReturnValue @Deprecated public final Multiset.Entry<E> pollFirstEntry()
null
if this multiset is empty.
This implementation is guaranteed to throw an UnsupportedOperationException
.
pollFirstEntry
in interface SortedMultiset<E>
UnsupportedOperationException
- always@CanIgnoreReturnValue @Deprecated public final Multiset.Entry<E> pollLastEntry()
null
if this multiset is empty.
This implementation is guaranteed to throw an UnsupportedOperationException
.
pollLastEntry
in interface SortedMultiset<E>
UnsupportedOperationException
- alwayspublic abstract ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType)
SortedMultiset
upperBound
,
optionally including upperBound
itself. The returned multiset is a view of this
multiset, so changes to one will be reflected in the other. The returned multiset supports all
operations that this multiset supports.
The returned multiset will throw an IllegalArgumentException
on attempts to add
elements outside its range.
headMultiset
in interface SortedMultiset<E>
public ImmutableSortedMultiset<E> subMultiset(E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType)
SortedMultiset
lowerBound
and upperBound
. The returned multiset is a view of this multiset, so changes to one will be
reflected in the other. The returned multiset supports all operations that this multiset
supports.
The returned multiset will throw an IllegalArgumentException
on attempts to add
elements outside its range.
This method is equivalent to tailMultiset(lowerBound,
lowerBoundType).headMultiset(upperBound, upperBoundType)
.
subMultiset
in interface SortedMultiset<E>
public abstract ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType)
SortedMultiset
lowerBound
,
optionally including lowerBound
itself. The returned multiset is a view of this
multiset, so changes to one will be reflected in the other. The returned multiset supports all
operations that this multiset supports.
The returned multiset will throw an IllegalArgumentException
on attempts to add
elements outside its range.
tailMultiset
in interface SortedMultiset<E>
public static <E> ImmutableSortedMultiset.Builder<E> orderedBy(Comparator<E> comparator)
SortedMultiset<Integer>
with a Comparator<Number>
, use the ImmutableSortedMultiset.Builder
constructor
instead.NullPointerException
- if comparator
is nullpublic static <E extends Comparable<?>> ImmutableSortedMultiset.Builder<E> reverseOrder()
Note: the type parameter E
extends Comparable<?>
rather than Comparable<? super E>
as a workaround for javac bug 6468354.
public static <E extends Comparable<?>> ImmutableSortedMultiset.Builder<E> naturalOrder()
Ordering.natural()
as the comparator. This
method provides more type-safety than builder()
, as it can be called only for classes
that implement Comparable
.
Note: the type parameter E
extends Comparable<?>
rather than Comparable<? super E>
as a workaround for javac bug 6468354.
@Deprecated public static <E> Collector<E,?,ImmutableMultiset<E>> toImmutableMultiset()
toImmutableSortedMultiset(java.util.Comparator<? super E>)
.toImmutableSortedMultiset(java.util.Comparator<? super E>)
instead. This
method exists only to hide ImmutableMultiset.toImmutableMultiset()
from consumers of
ImmutableSortedMultiset
.UnsupportedOperationException
- always@Deprecated public static <T,E> Collector<T,?,ImmutableMultiset<E>> toImmutableMultiset(Function<? super T,? extends E> elementFunction, ToIntFunction<? super T> countFunction)
toImmutableSortedMultiset(java.util.Comparator<? super E>)
.toImmutableSortedMultiset(java.util.Comparator<? super E>)
instead. This
method exists only to hide ImmutableMultiset.toImmutableMultiset()
from consumers of
ImmutableSortedMultiset
.UnsupportedOperationException
- always@Deprecated public static <E> ImmutableSortedMultiset.Builder<E> builder()
naturalOrder()
, which offers better type-safety.naturalOrder()
, which offers better
type-safety, instead. This method exists only to hide ImmutableMultiset.builder()
from
consumers of ImmutableSortedMultiset
.UnsupportedOperationException
- alwaysCopyright © 2010–2018. All rights reserved.