Interface MultiSet<E>
- Type Parameters:
- E- the type held in the multiset
- All Superinterfaces:
- Collection<E>,- Iterable<E>
- All Known Implementing Classes:
- AbstractMapMultiSet,- AbstractMultiSet,- AbstractMultiSetDecorator,- HashMultiSet,- PredicatedMultiSet,- SynchronizedMultiSet,- UnmodifiableMultiSet
 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}.
 
- Since:
- 4.1
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAn unmodifiable entry for an element and its occurrence as contained in a MultiSet.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanAdds one copy of the specified object to the MultiSet.intAdds a number of occurrences of the specified object to the MultiSet.booleancontainsAll(Collection<?> coll) Returnstrueif the MultiSet contains at least one occurrence for each element contained in the given collection.entrySet()Returns aSetof all entries contained in the MultiSet.booleanCompares this MultiSet to another object.intGets the number of occurrences of the given object currently in the MultiSet.inthashCode()Gets a hash code for the MultiSet compatible with the definition of equals.iterator()Returns anIteratorover the entire set of members, including copies due to cardinality.booleanRemoves one occurrence of the given object from the MultiSet.intRemoves a number of occurrences of the specified object from the MultiSet.booleanremoveAll(Collection<?> coll) Remove all occurrences of all elements from this MultiSet represented in the given collection.booleanretainAll(Collection<?> coll) Remove any elements of this MultiSet that are not contained in the given collection.intSets the number of occurrences of the specified object in the MultiSet to the given count.intsize()Returns the total number of items in the MultiSet.Returns aSetof unique elements in the MultiSet.Methods inherited from interface java.util.CollectionaddAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
- 
Method Details- 
addAdds one copy of the specified object to the MultiSet.If the object is already in the uniqueSet()then increment its count as reported bygetCount(Object). Otherwise, add it to theuniqueSet()and report its count as 1.- Specified by:
- addin interface- Collection<E>
- Parameters:
- object- the object to add
- Returns:
- truealways, as the size of the MultiSet is increased in any case
 
- 
addAdds a number of occurrences of the specified object to the MultiSet.If the object is already in the uniqueSet()then increment its count as reported bygetCount(Object). Otherwise, add it to theuniqueSet()and report its count asoccurrences.- Parameters:
- object- the object to add
- occurrences- the number of occurrences to add, may be zero, in which case no change is made to the multiset
- Returns:
- the number of occurrences of the object in the multiset before this operation; possibly zero
- Throws:
- IllegalArgumentException- if occurrences is negative
 
- 
containsAllReturnstrueif the MultiSet contains at least one occurrence for each element contained in the given collection.- Specified by:
- containsAllin interface- Collection<E>
- Parameters:
- coll- the collection to check against
- Returns:
- trueif the MultiSet contains all the collection
 
- 
entrySetSet<MultiSet.Entry<E>> entrySet()Returns aSetof 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. - Returns:
- the Set of MultiSet entries
 
- 
equalsCompares this MultiSet to another object.This MultiSet equals another object if it is also a MultiSet that contains the same number of occurrences of the same elements. - Specified by:
- equalsin interface- Collection<E>
- Overrides:
- equalsin class- Object
- Parameters:
- obj- the object to compare to
- Returns:
- true if equal
 
- 
getCount
- 
hashCodeint hashCode()Gets a hash code for the MultiSet compatible with the definition of equals. The hash code is defined as the sum total of a hash code for each element. The per element hash code is defined as(e==null ? 0 : e.hashCode()) ^ noOccurrences).- Specified by:
- hashCodein interface- Collection<E>
- Overrides:
- hashCodein class- Object
- Returns:
- the hash code of the MultiSet
 
- 
iteratorReturns anIteratorover the entire set of members, including copies due to cardinality. This iterator is fail-fast and will not tolerate concurrent modifications.
- 
removeRemoves one occurrence of the given object from the MultiSet.If the number of occurrences after this operation is reduced to zero, the object will be removed from the uniqueSet().- Specified by:
- removein interface- Collection<E>
- Parameters:
- object- the object to remove
- Returns:
- trueif this call changed the collection
 
- 
removeRemoves a number of occurrences of the specified object from the MultiSet.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. - Parameters:
- object- the object to remove
- occurrences- the number of occurrences to remove, may be zero, in which case no change is made to the multiset
- Returns:
- the number of occurrences of the object in the multiset before the operation; possibly zero
- Throws:
- IllegalArgumentException- if occurrences is negative
 
- 
removeAllRemove all occurrences of all elements from this MultiSet represented in the given collection.- Specified by:
- removeAllin interface- Collection<E>
- Parameters:
- coll- the collection of elements to remove
- Returns:
- trueif this call changed the multiset
 
- 
retainAllRemove any elements of this MultiSet that are not contained in the given collection.- Specified by:
- retainAllin interface- Collection<E>
- Parameters:
- coll- the collection of elements to retain
- Returns:
- trueif this call changed the multiset
 
- 
setCountSets the number of occurrences of the specified object in the MultiSet to the given count.If the provided count is zero, the object will be removed from the uniqueSet().- Parameters:
- object- the object to update
- count- the number of occurrences of the object
- Returns:
- the number of occurrences of the object before this operation, zero if the object was not contained in the multiset
- Throws:
- IllegalArgumentException- if count is negative
 
- 
sizeint size()Returns the total number of items in the MultiSet.- Specified by:
- sizein interface- Collection<E>
- Returns:
- the total size of the multiset
 
- 
uniqueSetReturns aSetof 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. - Returns:
- the Set of unique MultiSet elements
 
 
-