E
- the type held in the multisetpublic interface MultiSet<E>
extends java.util.Collection<E>
Suppose you have a MultiSet that contains {a, a, b, c}
.
Calling getCount(Object)
on a
would return 2, while
calling uniqueSet()
would return {a, b, c}
.
Modifier and Type | Interface and Description |
---|---|
static interface |
MultiSet.Entry<E>
An unmodifiable entry for an element and its occurrence as contained in a MultiSet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E object)
Adds one copy of the specified object to the MultiSet.
|
int |
add(E object,
int occurrences)
Adds a number of occurrences of the specified object to the MultiSet.
|
boolean |
containsAll(java.util.Collection<?> coll)
Returns
true if the MultiSet contains at least one
occurrence for each element contained in the given collection. |
java.util.Set<MultiSet.Entry<E>> |
entrySet()
Returns a
Set of all entries contained in the MultiSet. |
boolean |
equals(java.lang.Object obj)
Compares this MultiSet to another object.
|
int |
getCount(java.lang.Object object)
Returns the number of occurrences of the given object currently
in the MultiSet.
|
int |
hashCode()
Gets a hash code for the MultiSet compatible with the definition of equals.
|
java.util.Iterator<E> |
iterator()
Returns an
Iterator over the entire set of members,
including copies due to cardinality. |
boolean |
remove(java.lang.Object object)
Removes one occurrence of the given object from the MultiSet.
|
int |
remove(java.lang.Object object,
int occurrences)
Removes a number of occurrences of the specified object from the MultiSet.
|
boolean |
removeAll(java.util.Collection<?> coll)
Remove all occurrences of all elements from this MultiSet represented
in the given collection.
|
boolean |
retainAll(java.util.Collection<?> coll)
Remove any elements of this MultiSet that are not contained in the
given collection.
|
int |
setCount(E object,
int count)
Sets the number of occurrences of the specified object in the MultiSet
to the given count.
|
int |
size()
Returns the total number of items in the MultiSet.
|
java.util.Set<E> |
uniqueSet()
Returns a
Set of unique elements in the MultiSet. |
int getCount(java.lang.Object object)
object
- the object to search forint setCount(E object, int count)
If the provided count is zero, the object will be removed from the
uniqueSet()
.
object
- the object to updatecount
- the number of occurrences of the objectjava.lang.IllegalArgumentException
- if count is negativeboolean add(E object)
If the object is already in the uniqueSet()
then increment its
count as reported by getCount(Object)
. Otherwise add it to the
uniqueSet()
and report its count as 1.
add
in interface java.util.Collection<E>
object
- the object to addtrue
always, as the size of the MultiSet is increased
in any caseint add(E object, int occurrences)
If the object is already in the uniqueSet()
then increment its
count as reported by getCount(Object)
. Otherwise add it to the
uniqueSet()
and report its count as occurrences
.
object
- the object to addoccurrences
- the number of occurrences to add, may be zero,
in which case no change is made to the multisetjava.lang.IllegalArgumentException
- if occurrences is negativeboolean remove(java.lang.Object object)
If the number of occurrences after this operations is reduced
to zero, the object will be removed from the uniqueSet()
.
remove
in interface java.util.Collection<E>
object
- the object to removetrue
if this call changed the collectionint remove(java.lang.Object object, int occurrences)
If the number of occurrences to remove is greater than the actual number of occurrences in the multiset, the object will be removed from the multiset.
object
- the object to removeoccurrences
- the number of occurrences to remove, may be zero,
in which case no change is made to the multisetjava.lang.IllegalArgumentException
- if occurrences is negativejava.util.Set<E> uniqueSet()
Set
of unique elements in the MultiSet.
Uniqueness constraints are the same as those in Set
.
The returned set is backed by this multiset, so any change to either is immediately reflected in the other. Only removal operations are supported, in which case all occurrences of the element are removed from the backing multiset.
java.util.Set<MultiSet.Entry<E>> entrySet()
Set
of all entries contained in the MultiSet.
The returned set is backed by this multiset, so any change to either is immediately reflected in the other.
java.util.Iterator<E> iterator()
Iterator
over the entire set of members,
including copies due to cardinality. This iterator is fail-fast
and will not tolerate concurrent modifications.int size()
size
in interface java.util.Collection<E>
boolean containsAll(java.util.Collection<?> coll)
true
if the MultiSet contains at least one
occurrence for each element contained in the given collection.containsAll
in interface java.util.Collection<E>
coll
- the collection to check againsttrue
if the MultiSet contains all the collectionboolean removeAll(java.util.Collection<?> coll)
removeAll
in interface java.util.Collection<E>
coll
- the collection of elements to removetrue
if this call changed the multisetboolean retainAll(java.util.Collection<?> coll)
retainAll
in interface java.util.Collection<E>
coll
- the collection of elements to retaintrue
if this call changed the multisetboolean equals(java.lang.Object obj)
This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements.
equals
in interface java.util.Collection<E>
equals
in class java.lang.Object
obj
- the object to compare toint hashCode()
(e==null ? 0 : e.hashCode()) ^ noOccurances)
.hashCode
in interface java.util.Collection<E>
hashCode
in class java.lang.Object
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"