Class ImmutableSortedMultiset<E>
- java.lang.Object
- 
- java.util.AbstractCollection<E>
- 
- com.google.common.collect.ImmutableCollection<E>
- 
- com.google.common.collect.ImmutableMultiset<E>
- 
- com.google.common.collect.ImmutableSortedMultiset<E>
 
 
 
 
- 
- All Implemented Interfaces:
- Multiset<E>,- SortedMultiset<E>,- java.io.Serializable,- java.lang.Iterable<E>,- java.util.Collection<E>
 
 @GwtIncompatible public abstract class ImmutableSortedMultiset<E> extends ImmutableMultiset<E> implements SortedMultiset<E> ASortedMultisetwhose contents will never change, with many other important properties detailed atImmutableCollection.Warning: as with any sorted collection, you are strongly advised not to use a ComparatororComparabletype whose comparison behavior is inconsistent with equals. That is,a.compareTo(b)orcomparator.compare(a, b)should equal zero if and only ifa.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. - Since:
- 12.0
- Author:
- Louis Wasserman
- See Also:
- Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classImmutableSortedMultiset.Builder<E>A builder for creating immutable multiset instances, especiallypublic static finalmultisets ("constant multisets").- 
Nested classes/interfaces inherited from interface com.google.common.collect.MultisetMultiset.Entry<E extends @Nullable java.lang.Object>
 
- 
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <E> ImmutableSortedMultiset.Builder<E>builder()Deprecated.UsenaturalOrder(), which offers better type-safety.java.util.Comparator<? super E>comparator()Returns the comparator that orders this multiset, orOrdering.natural()if the natural ordering of the elements is used.static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<E>copyOf(E[] elements)Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E>copyOf(E[] elements)Deprecated.Pass parameters of typeComparableto usecopyOf(Comparable[]).static <E> ImmutableSortedMultiset<E>copyOf(java.lang.Iterable<? extends E> elements)Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E>copyOf(java.util.Comparator<? super E> comparator, java.lang.Iterable<? extends E> elements)Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.static <E> ImmutableSortedMultiset<E>copyOf(java.util.Comparator<? super E> comparator, java.util.Iterator<? extends E> elements)Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.static <E> ImmutableSortedMultiset<E>copyOf(java.util.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 sameComparator.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 thanupperBound, optionally includingupperBounditself.static <E extends java.lang.Comparable<?>>
 ImmutableSortedMultiset.Builder<E>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 java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<E>of(E element)Returns an immutable sorted multiset containing a single element.static <E> ImmutableSortedMultiset<E>of(E element)Deprecated.Pass a parameter of typeComparableto useof(Comparable).static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<E>of(E e1, E e2)Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E>of(E e1, E e2)Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable).static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<E>of(E e1, E e2, E e3)Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E>of(E e1, E e2, E e3)Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable).static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<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> ImmutableSortedMultiset<E>of(E e1, E e2, E e3, E e4)Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable).static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<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> ImmutableSortedMultiset<E>of(E e1, E e2, E e3, E e4, E e5)Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable, Comparable).static <E extends java.lang.Comparable<? super E>>
 ImmutableSortedMultiset<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<E>of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining)Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable, Comparable, Comparable, Comparable...).static <E> ImmutableSortedMultiset.Builder<E>orderedBy(java.util.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 java.lang.Comparable<?>>
 ImmutableSortedMultiset.Builder<E>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 betweenlowerBoundandupperBound.abstract ImmutableSortedMultiset<E>tailMultiset(E lowerBound, BoundType boundType)Returns a view of this multiset restricted to the elements greater thanlowerBound, optionally includinglowerBounditself.- 
Methods inherited from class com.google.common.collect.ImmutableMultisetadd, asList, contains, entrySet, equals, hashCode, iterator, remove, setCount, setCount, toString
 - 
Methods inherited from class com.google.common.collect.ImmutableCollectionadd, addAll, clear, remove, removeAll, retainAll, toArray, toArray
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.util.CollectionaddAll, clear, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
 - 
Methods inherited from interface com.google.common.collect.Multisetadd, add, contains, containsAll, count, equals, hashCode, remove, remove, removeAll, retainAll, setCount, setCount, size, toString
 - 
Methods inherited from interface com.google.common.collect.SortedMultisetentrySet, firstEntry, iterator, lastEntry
 
- 
 
- 
- 
- 
Method Detail- 
ofpublic static <E> ImmutableSortedMultiset<E> of() Returns the empty immutable sorted multiset.Performance note: the instance returned is a singleton. 
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<E> of(E element) Returns an immutable sorted multiset containing a single element.
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
- java.lang.NullPointerException- if any element is null
 
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
- java.lang.NullPointerException- if any element is null
 
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
- java.lang.NullPointerException- if any element is null
 
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<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.- Throws:
- java.lang.NullPointerException- if any element is null
 
 - 
ofpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<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.- Throws:
- java.lang.NullPointerException- if any element is null
 
 - 
copyOfpublic static <E extends java.lang.Comparable<? super E>> ImmutableSortedMultiset<E> copyOf(E[] elements) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
- java.lang.NullPointerException- if any of- elementsis null
 
 - 
copyOfpublic static <E> ImmutableSortedMultiset<E> copyOf(java.lang.Iterable<? extends E> elements) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering. To create a copy of aSortedMultisetthat preserves the comparator, callcopyOfSorted(com.google.common.collect.SortedMultiset<E>)instead. This method iterates overelementsat most once.Note that if sis aMultiset<String>, thenImmutableSortedMultiset.copyOf(s)returns anImmutableSortedMultiset<String>containing each of the strings ins, whileImmutableSortedMultiset.of(s)returns anImmutableSortedMultiset<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. - Throws:
- java.lang.ClassCastException- if the elements are not mutually comparable
- java.lang.NullPointerException- if any of- elementsis null
 
 - 
copyOfpublic static <E> ImmutableSortedMultiset<E> copyOf(java.util.Iterator<? extends E> elements) Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.This method is not type-safe, as it may be called on elements that are not mutually comparable. - Throws:
- java.lang.ClassCastException- if the elements are not mutually comparable
- java.lang.NullPointerException- if any of- elementsis null
 
 - 
copyOfpublic static <E> ImmutableSortedMultiset<E> copyOf(java.util.Comparator<? super E> comparator, java.util.Iterator<? extends E> elements) Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.- Throws:
- java.lang.NullPointerException- if- comparatoror any of- elementsis null
 
 - 
copyOfpublic static <E> ImmutableSortedMultiset<E> copyOf(java.util.Comparator<? super E> comparator, java.lang.Iterable<? extends E> elements) Returns an immutable sorted multiset containing the given elements sorted by the givenComparator. This method iterates overelementsat 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. - Throws:
- java.lang.NullPointerException- if- comparatoror any of- elementsis null
 
 - 
copyOfSortedpublic static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset) Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by the sameComparator. That behavior differs fromcopyOf(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 sortedMultisetis a synchronized or concurrent collection that is currently being modified by another thread.- Throws:
- java.lang.NullPointerException- if- sortedMultisetor any of its elements is null
 
 - 
comparatorpublic final java.util.Comparator<? super E> comparator() Description copied from interface:SortedMultisetReturns the comparator that orders this multiset, orOrdering.natural()if the natural ordering of the elements is used.- Specified by:
- comparatorin interface- SortedMultiset<E>
 
 - 
elementSetpublic abstract ImmutableSortedSet<E> elementSet() Description copied from interface:MultisetReturns the set of distinct elements contained in this multiset. The element set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. The order of the elements in the element set is unspecified.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().- Specified by:
- elementSetin interface- Multiset<E>
- Specified by:
- elementSetin interface- SortedMultiset<E>
- Specified by:
- elementSetin class- ImmutableMultiset<E>
- Returns:
- a view of the set of distinct elements in this multiset
 
 - 
descendingMultisetpublic ImmutableSortedMultiset<E> descendingMultiset() Description copied from interface:SortedMultisetReturns a descending view of this multiset. Modifications made to either map will be reflected in the other.- Specified by:
- descendingMultisetin interface- SortedMultiset<E>
 
 - 
pollFirstEntry@CanIgnoreReturnValue @Deprecated @CheckForNull public final Multiset.Entry<E> pollFirstEntry() Deprecated.Unsupported operation.Returns and removes the entry associated with the lowest element in this multiset, or returnsnullif this multiset is empty.This implementation is guaranteed to throw an UnsupportedOperationException.- Specified by:
- pollFirstEntryin interface- SortedMultiset<E>
- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
pollLastEntry@CanIgnoreReturnValue @Deprecated @CheckForNull public final Multiset.Entry<E> pollLastEntry() Deprecated.Unsupported operation.Returns and removes the entry associated with the greatest element in this multiset, or returnsnullif this multiset is empty.This implementation is guaranteed to throw an UnsupportedOperationException.- Specified by:
- pollLastEntryin interface- SortedMultiset<E>
- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
headMultisetpublic abstract ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) Description copied from interface:SortedMultisetReturns a view of this multiset restricted to the elements less thanupperBound, optionally includingupperBounditself. 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 IllegalArgumentExceptionon attempts to add elements outside its range.- Specified by:
- headMultisetin interface- SortedMultiset<E>
 
 - 
subMultisetpublic ImmutableSortedMultiset<E> subMultiset(E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) Description copied from interface:SortedMultisetReturns a view of this multiset restricted to the range betweenlowerBoundandupperBound. 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 IllegalArgumentExceptionon attempts to add elements outside its range.This method is equivalent to tailMultiset(lowerBound, lowerBoundType).headMultiset(upperBound, upperBoundType).- Specified by:
- subMultisetin interface- SortedMultiset<E>
 
 - 
tailMultisetpublic abstract ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) Description copied from interface:SortedMultisetReturns a view of this multiset restricted to the elements greater thanlowerBound, optionally includinglowerBounditself. 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 IllegalArgumentExceptionon attempts to add elements outside its range.- Specified by:
- tailMultisetin interface- SortedMultiset<E>
 
 - 
orderedBypublic static <E> ImmutableSortedMultiset.Builder<E> orderedBy(java.util.Comparator<E> comparator) Returns a builder that creates immutable sorted multisets with an explicit comparator. If the comparator has a more general type than the set being generated, such as creating aSortedMultiset<Integer>with aComparator<Number>, use theImmutableSortedMultiset.Builderconstructor instead.- Throws:
- java.lang.NullPointerException- if- comparatoris null
 
 - 
reverseOrderpublic static <E extends java.lang.Comparable<?>> ImmutableSortedMultiset.Builder<E> reverseOrder() Returns a builder that creates immutable sorted multisets whose elements are ordered by the reverse of their natural ordering.Note: the type parameter EextendsComparable<?>rather thanComparable<? super E>as a workaround for javac bug 6468354.
 - 
naturalOrderpublic static <E extends java.lang.Comparable<?>> ImmutableSortedMultiset.Builder<E> naturalOrder() Returns a builder that creates immutable sorted multisets whose elements are ordered by their natural ordering. The sorted multisets useOrdering.natural()as the comparator. This method provides more type-safety thanbuilder(), as it can be called only for classes that implementComparable.Note: the type parameter EextendsComparable<?>rather thanComparable<? super E>as a workaround for javac bug 6468354.
 - 
builder@Deprecated public static <E> ImmutableSortedMultiset.Builder<E> builder() Deprecated.UsenaturalOrder(), which offers better type-safety.Not supported. UsenaturalOrder(), which offers better type-safety, instead. This method exists only to hideImmutableMultiset.builder()from consumers ofImmutableSortedMultiset.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E element) Deprecated.Pass a parameter of typeComparableto useof(Comparable).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E e1, E e2) Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable, Comparable).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
of@Deprecated public static <E> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) Deprecated.Pass the parameters of typeComparableto useof(Comparable, Comparable, Comparable, Comparable, Comparable, Comparable, Comparable...).Not supported. You are attempting to create a multiset that may contain a non-Comparableelement. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 - 
copyOf@Deprecated public static <E> ImmutableSortedMultiset<E> copyOf(E[] elements) Deprecated.Pass parameters of typeComparableto usecopyOf(Comparable[]).Not supported. You are attempting to create a multiset that may contain non-Comparableelements. Proper calls will resolve to the version inImmutableSortedMultiset, not this dummy version.- Throws:
- java.lang.UnsupportedOperationException- always
 
 
- 
 
-