Class ImmutableSortedMultiset<E>
- All Implemented Interfaces:
Multiset<E>,SortedMultiset<E>,Serializable,Iterable<E>,Collection<E>
SortedMultiset 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 Multisets.unmodifiableSortedMultiset(com.google.common.collect.SortedMultiset<E>), which is a view of a separate
collection that can still change, an instance of ImmutableSortedMultiset contains its
own private data and will never change. This class is convenient for public static
final multisets ("constant multisets") and also lets you easily make a "defensive copy" of a
set provided to your class by a caller.
The multisets returned by the headMultiset(E, com.google.common.collect.BoundType), tailMultiset(E, com.google.common.collect.BoundType), and
subMultiset(E, com.google.common.collect.BoundType, E, com.google.common.collect.BoundType) methods share the same array as the original multiset, 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(com.google.common.collect.SortedMultiset<E>).
Note on element equivalence: The ImmutableMultiset.contains(Object),
ImmutableMultiset.containsAll(Collection), and ImmutableMultiset.equals(Object) implementations must check whether
a provided object is equivalent to an element in the collection. Unlike most collections, an
ImmutableSortedMultiset 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 multisets, an ImmutableSortedMultiset will not function
correctly if an element is modified after being placed in the multiset. 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.
See the Guava User Guide article on immutable collections.
- Since:
- 12.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDeprecated.The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023Nested classes/interfaces inherited from interface com.google.common.collect.Multiset
Multiset.Entry<E> -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ImmutableSortedMultiset.Builder<E> builder()Deprecated.UsenaturalOrder(), which offers better type-safety.final Comparator<? super E> Deprecated.Returns the comparator that orders this multiset, orOrdering.natural()if the natural ordering of the elements is used.static <E extends Comparable<? super E>>
ImmutableSortedMultiset<E> copyOf(E[] elements) Deprecated.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> Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterable<? extends E> elements) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterator<? extends E> elements) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.static <E> ImmutableSortedMultiset<E> Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset) Deprecated.Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by the sameComparator.Deprecated.Returns a descending view of this multiset.abstract ImmutableSortedSet<E> Deprecated.Returns aNavigableSetview of the distinct elements in this multiset.abstract ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) Deprecated.Returns a view of this multiset restricted to the elements less thanupperBound, optionally includingupperBounditself.static <E extends Comparable<E>>
ImmutableSortedMultiset.Builder<E> Deprecated.Returns a builder that creates immutable sorted multisets whose elements are ordered by their natural ordering.static <E> ImmutableSortedMultiset<E> of()Deprecated.Returns the empty immutable sorted multiset.static <E extends Comparable<? super E>>
ImmutableSortedMultiset<E> of(E element) Deprecated.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 Comparable<? super E>>
ImmutableSortedMultiset<E> of(E e1, E e2) Deprecated.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 Comparable<? super E>>
ImmutableSortedMultiset<E> of(E e1, E e2, E e3) Deprecated.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 Comparable<? super E>>
ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) Deprecated.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 Comparable<? super E>>
ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) Deprecated.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 Comparable<? super E>>
ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) Deprecated.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(Comparator<E> comparator) Deprecated.Returns a builder that creates immutable sorted multisets with an explicit comparator.final Multiset.Entry<E> Deprecated.Unsupported operation.final Multiset.Entry<E> Deprecated.Unsupported operation.static <E extends Comparable<E>>
ImmutableSortedMultiset.Builder<E> Deprecated.Returns a builder that creates immutable sorted multisets whose elements are ordered by the reverse of their natural ordering.subMultiset(E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) Deprecated.Returns a view of this multiset restricted to the range betweenlowerBoundandupperBound.abstract ImmutableSortedMultiset<E> tailMultiset(E lowerBound, BoundType boundType) Deprecated.Returns a view of this multiset restricted to the elements greater thanlowerBound, optionally includinglowerBounditself.Methods inherited from class com.google.common.collect.ImmutableMultiset
add, contains, containsAll, entrySet, equals, hashCode, iterator, remove, setCount, setCount, toStringMethods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, asList, clear, remove, removeAll, retainAll, toArray, toArrayMethods inherited from class java.util.AbstractCollection
isEmpty, sizeMethods inherited from interface java.util.Collection
addAll, clear, isEmpty, parallelStream, removeIf, size, spliterator, stream, toArray, toArray, toArrayMethods inherited from interface com.google.common.collect.Multiset
add, add, contains, containsAll, count, entrySet, equals, hashCode, remove, remove, removeAll, retainAll, setCount, setCount, toStringMethods inherited from interface com.google.common.collect.SortedMultiset
firstEntry, iterator, lastEntry
-
Method Details
-
of
Deprecated.Returns the empty immutable sorted multiset. -
of
Deprecated.Returns an immutable sorted multiset containing a single element. -
of
Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any element is null
-
of
Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any element is null
-
of
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any element is null
-
of
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any element is null
-
of
public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any element is null
-
copyOf
Deprecated.Returns an immutable sorted multiset containing the given elements sorted by their natural ordering.- Throws:
NullPointerException- if any ofelementsis null
-
copyOf
Deprecated.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:
ClassCastException- if the elements are not mutually comparableNullPointerException- if any ofelementsis null
-
copyOf
Deprecated.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:
ClassCastException- if the elements are not mutually comparableNullPointerException- if any ofelementsis null
-
copyOf
public static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterator<? extends E> elements) Deprecated.Returns an immutable sorted multiset containing the given elements sorted by the givenComparator.- Throws:
NullPointerException- ifcomparatoror any ofelementsis null
-
copyOf
public static <E> ImmutableSortedMultiset<E> copyOf(Comparator<? super E> comparator, Iterable<? extends E> elements) Deprecated.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:
NullPointerException- ifcomparatoror any ofelementsis null
-
copyOfSorted
Deprecated.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:
NullPointerException- ifsortedMultisetor any of its elements is null
-
comparator
Deprecated.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 interfaceSortedMultiset<E>
-
elementSet
Deprecated.Description copied from interface:SortedMultisetReturns aNavigableSetview of the distinct elements in this multiset.- Specified by:
elementSetin interfaceMultiset<E>- Specified by:
elementSetin interfaceSortedMultiset<E>- Returns:
- a view of the set of distinct elements in this multiset
-
descendingMultiset
Deprecated.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 interfaceSortedMultiset<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 interfaceSortedMultiset<E>- Throws:
UnsupportedOperationException- always
-
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 interfaceSortedMultiset<E>- Throws:
UnsupportedOperationException- always
-
headMultiset
Deprecated.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 interfaceSortedMultiset<E>
-
subMultiset
public ImmutableSortedMultiset<E> subMultiset(E lowerBound, BoundType lowerBoundType, E upperBound, BoundType upperBoundType) Deprecated.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 interfaceSortedMultiset<E>
-
tailMultiset
Deprecated.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 interfaceSortedMultiset<E>
-
orderedBy
Deprecated.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:
NullPointerException- ifcomparatoris null
-
reverseOrder
Deprecated.Returns a builder that creates immutable sorted multisets whose elements are ordered by the reverse of their natural ordering.Note: the type parameter
EextendsComparable<E>rather thanComparable<? super E>as a workaround for javac bug 6468354. -
naturalOrder
Deprecated.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<E>rather thanComparable<? super E>as a workaround for javac bug 6468354. -
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:
UnsupportedOperationException- always
-
of
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:
UnsupportedOperationException- always
-
of
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:
UnsupportedOperationException- always
-
of
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:
UnsupportedOperationException- always
-
of
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:
UnsupportedOperationException- always
-
of
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:
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:
UnsupportedOperationException- always
-
copyOf
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:
UnsupportedOperationException- always
-