@GwtCompatible(serializable=true, emulated=true) public abstract class ImmutableMultiset<E> extends ImmutableCollection<E> implements Multiset <E>
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
ImmutableMultiset
A builder for creating immutable multiset instances, especially
public static final multisets ("constant multisets").
|
Multiset.Entry <E> | Modifier and Type | Method and Description |
|---|---|
int |
add(E element, int occurrences)
Deprecated.
Unsupported operation.
|
static <E> ImmutableMultiset |
builder()
Returns a new builder.
|
boolean |
contains(Object
Determines whether this multiset contains the specified element.
|
boolean |
containsAll(Collection
Returns
true if this multiset contains at least one occurrence of each element in the specified collection.
|
static <E> ImmutableMultiset |
copyOf(E[] elements)
Returns an immutable multiset containing the given elements.
|
static <E> ImmutableMultiset |
copyOf(Iterable
Returns an immutable multiset containing the given elements.
|
static <E> ImmutableMultiset |
copyOf(Iterator
Returns an immutable multiset containing the given elements.
|
ImmutableSet |
entrySet()
Returns a view of the contents of this multiset, grouped into
Multiset.Entry instances, each providing an element of the multiset and the count of that element.
|
boolean |
equals(Object
Compares the specified object with this multiset for equality.
|
int |
hashCode()
Returns the hash code for this multiset.
|
UnmodifiableIterator |
iterator()
Returns an unmodifiable iterator across the elements in this collection.
|
static <E> ImmutableMultiset |
of()
Returns the empty immutable multiset.
|
static <E> ImmutableMultiset |
of(E element)
Returns an immutable multiset containing a single element.
|
static <E> ImmutableMultiset |
of(E e1, E e2)
Returns an immutable multiset containing the given elements, in order.
|
static <E> ImmutableMultiset |
of(E e1, E e2, E e3)
Returns an immutable multiset containing the given elements, in order.
|
static <E> ImmutableMultiset |
of(E e1, E e2, E e3, E e4)
Returns an immutable multiset containing the given elements, in order.
|
static <E> ImmutableMultiset |
of(E e1, E e2, E e3, E e4, E e5)
Returns an immutable multiset containing the given elements, in order.
|
static <E> ImmutableMultiset |
of(E e1, E e2, E e3, E e4, E e5, E e6, E... others)
Returns an immutable multiset containing the given elements, in order.
|
int |
remove(Object
Deprecated.
Unsupported operation.
|
int |
setCount(E element, int count)
Deprecated.
Unsupported operation.
|
boolean |
setCount(E element, int oldCount, int newCount)
Deprecated.
Unsupported operation.
|
String |
toString()
|
add, addAll, asList, clear, remove, removeAll, retainAll, toArray, toArrayisEmpty, sizeclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, count, elementSet, remove, removeAll, retainAlladdAll, clear, isEmpty, parallelStream, removeIf, size, spliterator, stream, toArray, toArraypublic static <E> ImmutableMultiset<E> of()
public static <E> ImmutableMultiset<E> of(E element)
NullPointerException - if
element is null
public static <E> ImmutableMultiset<E> of(E e1, E e2)
NullPointerException - if any element is null
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3)
NullPointerException - if any element is null
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3, E e4)
NullPointerException - if any element is null
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3, E e4, E e5)
NullPointerException - if any element is null
public static <E> ImmutableMultiset<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... others)
NullPointerException - if any element is null
public static <E> ImmutableMultiset<E> copyOf(E[] 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 order 2, 3, 3, 1.
NullPointerException - if any of
elements is null
public static <E> ImmutableMultiset<E> copyOf(Iterable <? extends E> 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 order 2, 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 an ImmutableMultiset, no copy will actually be performed, and the given multiset itself will be returned.
NullPointerException - if any of
elements is null
public static <E> ImmutableMultiset<E> copyOf(Iterator <? extends E> 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 order 2, 3, 3, 1.
NullPointerException - if any of
elements is null
public UnmodifiableIterator<E> iterator()
ImmutableCollection
public boolean contains(Objectobject)
Multiset
This method refines Collection to further specify that it may not throw an exception in response to element being null or of the wrong type.
contains in interface
Multiset<E>
contains in interface
Collection<E>
contains in class
ImmutableCollection<E>
object - the element to check for
true if this multiset contains at least one occurrence of the element
public boolean containsAll(Collection<?> targets)
Multiset
true if this multiset contains at least one occurrence of each element in the specified collection.
This method refines Collection to further specify that it may not throw an exception in response to any of elements 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 if elements contains several occurrences of an element and this multiset contains only one. This is no different than any other collection type like List, but it may be unexpected to the user of a multiset.
containsAll in interface
Multiset<E>
containsAll in interface
Collection<E>
containsAll in class
AbstractCollection<E>
targets - the collection of elements to be checked for containment in this multiset
true if this multiset contains at least one occurrence of each element contained in
elements
@Deprecated public final int add(E element, int occurrences)
add in interface
Multiset<E>
element - the element to add occurrences of; may be null only if explicitly allowed by the implementation
occurrences - the number of occurrences of the element to add. May be zero, in which case no change will be made.
UnsupportedOperationException - always
@Deprecated public final int remove(Objectelement, int occurrences)
remove in interface
Multiset<E>
element - the element to conditionally remove occurrences of
occurrences - the number of occurrences of the element to remove. May be zero, in which case no change will be made.
UnsupportedOperationException - always
@Deprecated public final int setCount(E element, int count)
setCount in interface
Multiset<E>
element - the element to add or remove occurrences of; may be null only if explicitly allowed by the implementation
count - the desired count of the element in this multiset
UnsupportedOperationException - always
@Deprecated public final boolean setCount(E element, int oldCount, int newCount)
setCount in interface
Multiset<E>
element - the element to conditionally set the count of; may be null only if explicitly allowed by the implementation
oldCount - the expected present count of the element in this multiset
newCount - the desired count of the element in this multiset
true if the condition for modification was met. This implies that the multiset was indeed modified, unless
oldCount == newCount.
UnsupportedOperationException - always
public boolean equals(Objectobject)
Multiset
true if the given object is also a multiset and contains equal elements with equal counts, regardless of order.
public int hashCode()
Multiset
((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.
public StringtoString()
Multiset
It is recommended, though not mandatory, that this method return the result of invoking Multiset on the Multiset, yielding a result such as [a x 3, c, d x 2, e].
public ImmutableSet<Multiset .Entry <E>> entrySet()
Multiset
Multiset.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 the
Multiset.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 the Entry instances themselves don't even have methods for modification. See the specific implementation class for more details on how its entry set handles modifications.
public static <E> ImmutableMultiset.Builder <E> builder()
ImmutableMultiset.Builder constructor.