Warning
The methods of ForwardingMultiset forward indiscriminately to
the methods of the delegate. For example, overriding add(Object, int) alone will
not change the behavior of add(Object), which can lead to unexpected behavior. In
this case, you should override add(Object) as well, either providing your own
implementation, or delegating to the provided standardAdd method.
default method warning: This class does not forward calls to default methods. Instead, it inherits their default implementations. When those implementations
invoke methods, they invoke methods on the ForwardingMultiset.
The standard methods and any collection views they return are not guaranteed to be
thread-safe, even when all of the methods that they depend on are thread-safe.
| Modifier and Type | Class and Description |
|---|---|
| protected class | ForwardingMultiset.StandardElementSet
A sensible implementation of |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| 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 int | count(Object
the element to count occurrences of element)Implements com. |
| protected abstract Multiset | delegate()
Implements abstract com. |
| public Set | elementSet()
Implements com. |
| public Set | entrySet()
Implements com. Multiset.Entry instances,
each providing an element of the multiset and the count of that element.
|
| public boolean | equals(Object
object to be compared for equality with this collection object)Overrides java. Implements com. |
| public int | hashCode()
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 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.
|
| protected boolean | |
| protected boolean | standardAddAll(Collection<? extends E> elementsToAdd)
Overrides com. addAll(Collection) in terms of add(Object) and
add(Object, int).
|
| protected void | standardClear()
Overrides com. clear in terms of the iterator method of entrySet.
|
| protected boolean | standardContains(Object object)
Overrides com. contains in terms of count.
|
| protected int | standardCount(Object object)
A sensible, albeit inefficient, definition of |
| protected boolean | standardEquals(Object object)
A sensible, albeit inefficient, definition of |
| protected int | |
| protected Iterator | |
| protected boolean | standardRemove(Object element)
Overrides com. remove(Object) in terms of remove(Object, int).
|
| protected boolean | standardRemoveAll(Collection<?> elementsToRemove)
Overrides com. removeAll in terms of the removeAll method of elementSet.
|
| protected boolean | standardRetainAll(Collection<?> elementsToRetain)
Overrides com. retainAll in terms of the retainAll method of elementSet.
|
| protected int | standardSetCount(E element, int count)
A sensible definition of |
| protected boolean | standardSetCount(E element, int oldCount, int newCount)
A sensible definition of |
| protected int | |
| protected String | standardToString()
Overrides com. toString as entrySet().toString() .
|
| ForwardingMultiset | back to summary |
|---|---|
| protected ForwardingMultiset() Constructor for use by subclasses. | |
| 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
| |
| count | back to summary |
|---|---|
| public int count(Object element) Implements com. Doc from com. Returns the number of occurrences of an element in this multiset (the count of the
element). Note that for an Note the utility method | |
| delegate | back to summary |
|---|---|
| protected abstract Multiset Implements abstract com. Doc from com. Returns the backing delegate instance that methods are forwarded to. Abstract subclasses
generally override this method with an abstract method that has a more specific return type,
such as
| |
| 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:
| |
| 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 boolean equals(Object object) Overrides java. Implements com. Doc from com. Compares the specified object with this multiset for equality. Returns
| |
| hashCode | back to summary |
|---|---|
| public 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.
| |
| 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
| |
| 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
| |
| standardAdd | back to summary |
|---|---|
| protected boolean standardAdd(E element) A sensible definition of
| |
| standardAddAll | back to summary |
|---|---|
| protected boolean standardAddAll(Collection<? extends E> elementsToAdd) Overrides com. A sensible definition of
| |
| standardClear | back to summary |
|---|---|
| protected void standardClear() Overrides com. A sensible definition of
| |
| standardContains | back to summary |
|---|---|
| protected boolean standardContains(Object object) Overrides com. A sensible definition of
| |
| standardCount | back to summary |
|---|---|
| protected int standardCount(Object object) A sensible, albeit inefficient, definition of
| |
| standardEquals | back to summary |
|---|---|
| protected boolean standardEquals(Object object) A sensible, albeit inefficient, definition of
| |
| standardHashCode | back to summary |
|---|---|
| protected int standardHashCode() A sensible definition of
| |
| standardIterator | back to summary |
|---|---|
| protected Iterator A sensible definition of
| |
| standardRemove | back to summary |
|---|---|
| protected boolean standardRemove(Object element) Overrides com. A sensible definition of
| |
| standardRemoveAll | back to summary |
|---|---|
| protected boolean standardRemoveAll(Collection<?> elementsToRemove) Overrides com. A sensible definition of
| |
| standardRetainAll | back to summary |
|---|---|
| protected boolean standardRetainAll(Collection<?> elementsToRetain) Overrides com. A sensible definition of
| |
| standardSetCount | back to summary |
|---|---|
| protected int standardSetCount(E element, int count) A sensible definition of
| |
| standardSetCount | back to summary |
|---|---|
| protected boolean standardSetCount(E element, int oldCount, int newCount) A sensible definition of
| |
| standardSize | back to summary |
|---|---|
| protected int standardSize() A sensible, albeit inefficient, definition of
| |
| standardToString | back to summary |
|---|---|
| protected String standardToString() Overrides com. A sensible definition of
| |
Multiset#elementSet in terms of the following methods:
ForwardingMultiset#clear, ForwardingMultiset#contains, ForwardingMultiset#containsAll, ForwardingMultiset#count, ForwardingMultiset#isEmpty, the Set#size and Set#iterator methods of ForwardingMultiset#entrySet, and ForwardingMultiset#remove(Object, int). In many
situations, you may wish to override ForwardingMultiset#elementSet to forward to this
implementation or a subclass thereof.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Iterator | iterator()
Implements abstract com. Implements java. |
| pack-priv Multiset |
| StandardElementSet | back to summary |
|---|---|
| public StandardElementSet() Constructor for use by subclasses. | |
| 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.
| |