Multiset interface. A new multiset
implementation can be created easily by extending this class and implementing the Multiset#entrySet() method, plus optionally overriding add(Object, int) and remove(Object, int) to enable modifications to the multiset.
The count and size implementations all iterate across the set returned by
Multiset#entrySet(), as do many methods acting on the set returned by elementSet(). Override those methods for better performance.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv class | |
| pack-priv class |
| Modifier and Type | Field and Description |
|---|---|
| private transient Set | |
| private transient Set |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public final boolean | add(E
the element to add one occurrence of; may be null only if explicitly allowed by
the implementation element)Overrides java. Implements com. |
| public int | add(E
the element to add occurrences of; may be null only if explicitly allowed by the
implementation element, int the number of occurrences of the element to add. May be zero, in which case
no change will be made. occurrences)Implements com. |
| public final boolean | addAll(Collection<? extends E>
collection containing elements to be added to this collection elementsToAdd)Overrides java. Implements java. |
| public abstract void | clear()
Redeclares java. Overrides java. |
| public boolean | contains(Object
the element to check for element)Overrides java. Implements com. |
| pack-priv Set | createElementSet()
Creates a new instance of this multiset's element set, which will be returned by |
| pack-priv Set | |
| pack-priv abstract int | |
| pack-priv abstract Iterator | |
| public Set | elementSet()
Implements com. |
| pack-priv abstract Iterator | |
| public Set | entrySet()
Implements com. Multiset.Entry instances,
each providing an element of the multiset and the count of that element.
|
| public final boolean | equals(Object
object to be compared for equality with this collection object)Overrides java. Implements com. |
| public final int | hashCode()
Overrides java. Implements com. |
| public boolean | isEmpty()
Overrides java. Implements java. true if this collection contains no elements.
|
| public final boolean | remove(Object
the element to remove one occurrence of element)Overrides java. Implements com. |
| public int | remove(Object
the element to conditionally remove occurrences of element, int the number of occurrences of the element to remove. May be zero, in which
case no change will be made. occurrences)Implements com. |
| public final boolean | removeAll(Collection<?>
collection containing elements to be removed from this collection elementsToRemove)Overrides java. Implements com. |
| public final boolean | retainAll(Collection<?>
collection containing elements to be retained in this collection elementsToRetain)Overrides java. Implements com. |
| public int | setCount(E
the element to add or remove occurrences of; may be null only if explicitly
allowed by the implementation element, int the desired count of the element in this multiset count)Implements com. |
| public boolean | setCount(E
the element to conditionally set the count of; may be null only if explicitly
allowed by the implementation element, int the expected present count of the element in this multiset oldCount, int the desired count of the element in this multiset newCount)Implements com. setCount(Object, int), provided that the element has the expected current count.
|
| public final String | toString()
Overrides java. Implements com. It is recommended, though not mandatory, that this method return the result of invoking
|
| elementSet | back to summary |
|---|---|
| private transient Set<E> elementSet
| |
| entrySet | back to summary |
|---|---|
| private transient Set<Multiset. | |
| AbstractMultiset | back to summary |
|---|---|
| pack-priv AbstractMultiset() | |
| add | back to summary |
|---|---|
| public final boolean add(E element) Overrides java. Implements com. Doc from com. Adds a single occurrence of the specified element to this multiset. This method refines To both add the element and obtain the previous count of that element, use
| |
| add | back to summary |
|---|---|
| public int add(E element, int occurrences) Implements com. Doc from com. Adds a number of occurrences of an element to this multiset. Note that if
| |
| addAll | back to summary |
|---|---|
| public final boolean addAll(Collection<? extends E> elementsToAdd) Overrides java. Implements java. Doc from java. Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order. This implementation is highly efficient when
| |
| clear | back to summary |
|---|---|
| public abstract void clear() Redeclares java. Overrides java. Doc from java. Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object element) Overrides java. Implements com. Doc from com. Determines whether this multiset contains the specified element. This method refines | |
| createElementSet | back to summary |
|---|---|
| pack-priv Set Creates a new instance of this multiset's element set, which will be returned by | |
| createEntrySet | back to summary |
|---|---|
| pack-priv Set | |
| distinctElements | back to summary |
|---|---|
| pack-priv abstract int distinctElements() | |
| elementIterator | back to summary |
|---|---|
| pack-priv abstract Iterator | |
| elementSet | back to summary |
|---|---|
| public Set Implements com. Doc from com. Returns 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:
| |
| entryIterator | back to summary |
|---|---|
| pack-priv abstract Iterator | |
| entrySet | back to summary |
|---|---|
| public Set Implements com. Doc from com. Returns a view of the contents of this multiset, grouped into 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 | |
| equals | back to summary |
|---|---|
| public final boolean equals(Object object) Overrides java. Implements com. Doc from com. Compares the specified object with this multiset for equality. Returns This implementation returns
| |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Overrides java. Implements com. Doc from com. Returns the hash code for this multiset. This is defined as the sum of
over all distinct elements in the multiset. It follows that a multiset and its entry set always have the same hash code. This implementation returns the hash code of
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Overrides java. Implements java. Doc from java. Returns
| |
| remove | back to summary |
|---|---|
| public final boolean remove(Object element) Overrides java. Implements com. Doc from com. Removes a single occurrence of the specified element from this multiset, if present. This method refines To both remove the element and obtain the previous count of that element, use
| |
| remove | back to summary |
|---|---|
| public int remove(Object element, int occurrences) Implements com. Doc from com. Removes a number of occurrences of the specified element from this multiset. If the multiset
contains fewer than this number of occurrences to begin with, all occurrences will be removed.
Note that if
| |
| removeAll | back to summary |
|---|---|
| public final boolean removeAll(Collection<?> elementsToRemove) Overrides java. Implements com. Doc from com. Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection. Note This method ignores how often any element might appear in This method refines
| |
| retainAll | back to summary |
|---|---|
| public final boolean retainAll(Collection<?> elementsToRetain) Overrides java. Implements com. Doc from com. Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection. Note This method ignores how often any element might appear in This method refines
| |
| setCount | back to summary |
|---|---|
| public int setCount(E element, int count) Implements com. Doc from com. Adds or removes the necessary occurrences of an element such that the element attains the desired count.
| |
| setCount | back to summary |
|---|---|
| public boolean setCount(E element, int oldCount, int newCount) Implements com. Doc from com. Conditionally sets the count of an element to a new value, as described in
| |
| toString | back to summary |
|---|---|
| public final String toString() Overrides java. Implements com. Doc from com.
It is recommended, though not mandatory, that this method return the result of invoking
This implementation returns the result of invoking
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Iterator | iterator()
Implements abstract com. Implements java. |
| pack-priv Multiset |
| ElementSet | back to summary |
|---|---|
| pack-priv ElementSet() | |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract com. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| multiset | back to summary |
|---|---|
| pack-priv Multiset Implements abstract com.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Iterator | iterator()
Implements abstract java. Implements java. |
| pack-priv Multiset | |
| public int | size()
Implements abstract java. Implements java. |
| EntrySet | back to summary |
|---|---|
| pack-priv EntrySet() | |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| multiset | back to summary |
|---|---|
| pack-priv Multiset Implements abstract com.
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |