Class ImmutableMultiset<E>
- All Implemented Interfaces:
Multiset<E>
,Serializable
,Iterable<E>
,Collection<E>
- Direct Known Subclasses:
ImmutableSortedMultiset
Its iterator orders elements according to the first appearance of the element among the items passed to the factory method or builder. When the multiset contains multiple instances of an element, those instances are consecutive in the iteration order.
See the Guava User Guide article on immutable collections.
- Since:
- 2.0 (imported from Google Collections Library)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Deprecated.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 TypeMethodDescriptionfinal int
Deprecated.Unsupported operation.static <E> ImmutableMultiset.Builder
<E> builder()
Deprecated.Returns a new builder.boolean
Deprecated.Determines whether this multiset contains the specified element.boolean
containsAll
(Collection<?> targets) Deprecated.Returnstrue
if this multiset contains at least one occurrence of each element in the specified collection.static <E> ImmutableMultiset
<E> copyOf
(E[] elements) Deprecated.Returns an immutable multiset containing the given elements.static <E> ImmutableMultiset
<E> Deprecated.Returns an immutable multiset containing the given elements.static <E> ImmutableMultiset
<E> Deprecated.Returns an immutable multiset containing the given elements.entrySet()
Deprecated.Returns a view of the contents of this multiset, grouped intoMultiset.Entry
instances, each providing an element of the multiset and the count of that element.boolean
Deprecated.Compares the specified object with this multiset for equality.int
hashCode()
Deprecated.Returns the hash code for this multiset.iterator()
Deprecated.Returns an unmodifiable iterator across the elements in this collection.static <E> ImmutableMultiset
<E> of()
Deprecated.Returns the empty immutable multiset.static <E> ImmutableMultiset
<E> of
(E element) Deprecated.Returns an immutable multiset containing a single element.static <E> ImmutableMultiset
<E> of
(E e1, E e2) Deprecated.Returns an immutable multiset containing the given elements, in order.static <E> ImmutableMultiset
<E> of
(E e1, E e2, E e3) Deprecated.Returns an immutable multiset containing the given elements, in order.static <E> ImmutableMultiset
<E> of
(E e1, E e2, E e3, E e4) Deprecated.Returns an immutable multiset containing the given elements, in order.static <E> ImmutableMultiset
<E> of
(E e1, E e2, E e3, E e4, E e5) Deprecated.Returns an immutable multiset containing the given elements, in order.static <E> ImmutableMultiset
<E> of
(E e1, E e2, E e3, E e4, E e5, E e6, E... others) Deprecated.Returns an immutable multiset containing the given elements, in order.final int
Deprecated.Unsupported operation.final int
Deprecated.Unsupported operation.final boolean
Deprecated.Unsupported operation.toString()
Deprecated.Methods inherited from class com.google.common.collect.ImmutableCollection
add, addAll, asList, clear, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.util.AbstractCollection
isEmpty, size
Methods inherited from interface java.util.Collection
addAll, clear, isEmpty, parallelStream, removeIf, size, spliterator, stream, toArray, toArray, toArray
-
Method Details
-
of
Deprecated.Returns the empty immutable multiset. -
of
Deprecated.Returns an immutable multiset containing a single element.- Throws:
NullPointerException
- ifelement
is null- Since:
- 6.0 (source-compatible since 2.0)
-
of
Deprecated.Returns an immutable multiset containing the given elements, in order.- Throws:
NullPointerException
- if any element is null- Since:
- 6.0 (source-compatible since 2.0)
-
of
Deprecated.Returns an immutable multiset containing the given elements, in order.- Throws:
NullPointerException
- if any element is null- Since:
- 6.0 (source-compatible since 2.0)
-
of
Deprecated.Returns an immutable multiset containing the given elements, in order.- Throws:
NullPointerException
- if any element is null- Since:
- 6.0 (source-compatible since 2.0)
-
of
Deprecated.Returns an immutable multiset containing the given elements, in order.- Throws:
NullPointerException
- if any element is null- Since:
- 6.0 (source-compatible since 2.0)
-
of
Deprecated.Returns an immutable multiset containing the given elements, in order.- Throws:
NullPointerException
- if any element is null- Since:
- 6.0 (source-compatible since 2.0)
-
copyOf
Deprecated.Returns an immutable multiset containing the given elements.The multiset is ordered by the first occurrence of each element. For example,
ImmutableMultiset.copyOf([2, 3, 1, 3])
yields a multiset with elements in the order2, 3, 3, 1
.- Throws:
NullPointerException
- if any ofelements
is null- Since:
- 6.0
-
copyOf
Deprecated.Returns an immutable multiset containing the given elements.The multiset is ordered by the first occurrence of each element. For example,
ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3))
yields a multiset with elements in the order2, 3, 3, 1
.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.
Note: Despite what the method name suggests, if
elements
is anImmutableMultiset
, no copy will actually be performed, and the given multiset itself will be returned.- Throws:
NullPointerException
- if any ofelements
is null
-
copyOf
Deprecated.Returns an immutable multiset containing the given elements.The multiset is ordered by the first occurrence of each element. For example,
ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3).iterator())
yields a multiset with elements in the order2, 3, 3, 1
.- Throws:
NullPointerException
- if any ofelements
is null
-
iterator
Deprecated.Description copied from class:ImmutableCollection
Returns an unmodifiable iterator across the elements in this collection. -
contains
Deprecated.Description copied from interface:Multiset
Determines whether this multiset contains the specified element.This method refines
Collection.contains(java.lang.Object)
to further specify that it may not throw an exception in response toelement
being null or of the wrong type.- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceMultiset<E>
- Overrides:
contains
in classImmutableCollection<E>
- Parameters:
object
- the element to check for- Returns:
true
if this multiset contains at least one occurrence of the element
-
containsAll
Deprecated.Description copied from interface:Multiset
Returnstrue
if this multiset contains at least one occurrence of each element in the specified collection.This method refines
Collection.containsAll(java.util.Collection<?>)
to further specify that it may not throw an exception in response to any ofelements
being null or of the wrong type.Note: this method does not take into account the occurrence count of an element in the two collections; it may still return
true
even ifelements
contains several occurrences of an element and this multiset contains only one. This is no different than any other collection type likeList
, but it may be unexpected to the user of a multiset.- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceMultiset<E>
- Overrides:
containsAll
in classAbstractCollection<E>
- Parameters:
targets
- the collection of elements to be checked for containment in this multiset- Returns:
true
if this multiset contains at least one occurrence of each element contained inelements
-
add
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
add
in interfaceMultiset<E>
- Parameters:
element
- the element to add occurrences of; may be null only if explicitly allowed by the implementationoccurrences
- the number of occurrences of the element to add. May be zero, in which case no change will be made.- Returns:
- the count of the element before the operation; possibly zero
- Throws:
UnsupportedOperationException
- always
-
remove
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
remove
in interfaceMultiset<E>
- Parameters:
element
- the element to conditionally remove occurrences ofoccurrences
- the number of occurrences of the element to remove. May be zero, in which case no change will be made.- Returns:
- the count of the element before the operation; possibly zero
- Throws:
UnsupportedOperationException
- always
-
setCount
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
setCount
in interfaceMultiset<E>
- Parameters:
element
- the element to add or remove occurrences of; may be null only if explicitly allowed by the implementationcount
- the desired count of the element in this multiset- Returns:
- the count of the element before the operation; possibly zero
- Throws:
UnsupportedOperationException
- always
-
setCount
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
setCount
in interfaceMultiset<E>
- Parameters:
element
- the element to conditionally set the count of; may be null only if explicitly allowed by the implementationoldCount
- the expected present count of the element in this multisetnewCount
- the desired count of the element in this multiset- Returns:
true
if the condition for modification was met. This implies that the multiset was indeed modified, unlessoldCount == newCount
.- Throws:
UnsupportedOperationException
- always
-
equals
Deprecated.Description copied from interface:Multiset
Compares the specified object with this multiset for equality. Returnstrue
if the given object is also a multiset and contains equal elements with equal counts, regardless of order. -
hashCode
public int hashCode()Deprecated.Description copied from interface:Multiset
Returns the hash code for this multiset. This is defined as the sum of((element == null) ? 0 : element.hashCode()) ^ count(element)
over all distinct elements in the multiset. It follows that a multiset and its entry set always have the same hash code.
-
toString
Deprecated.Description copied from interface:Multiset
It is recommended, though not mandatory, that this method return the result of invoking
Multiset.toString()
on theMultiset.entrySet()
, yielding a result such as[a x 3, c, d x 2, e]
. -
entrySet
Deprecated.Description copied from interface:Multiset
Returns a view of the contents of this multiset, grouped intoMultiset.Entry
instances, each providing an element of the multiset and the count of that element. This set contains exactly one entry for each distinct element in the multiset (thus it always has the same size as theMultiset.elementSet()
). The order of the elements in the element set is unspecified.The entry set is backed by the same data as the multiset, so any change to either is immediately reflected in the other. However, multiset changes may or may not be reflected in any
Entry
instances already retrieved from the entry set (this is implementation-dependent). Furthermore, implementations are not required to support modifications to the entry set at all, and theEntry
instances themselves don't even have methods for modification. See the specific implementation class for more details on how its entry set handles modifications. -
builder
Deprecated.Returns a new builder. The generated builder is equivalent to the builder created by theImmutableMultiset.Builder
constructor.
-