Class AbstractMapMultiSet<E>
- Type Parameters:
- E- the type held in the multiset.
- All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- MultiSet<E>
- Direct Known Subclasses:
- HashMultiSet
MultiSet interface to simplify the
 creation of subclass implementations.
 Subclasses specify a Map implementation to use as the internal storage. The map will be used to map multiset elements to a number; the number represents the number of occurrences of that element in the multiset.
- Since:
- 4.1
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classInner class EntrySetIterator.protected static classInner class MultiSetEntry.protected static classMutable integer class for storing the data.protected static classInner class UniqueSetIterator.Nested classes/interfaces inherited from class org.apache.commons.collections4.multiset.AbstractMultiSetAbstractMultiSet.AbstractEntry<E>, AbstractMultiSet.EntrySet<E>, AbstractMultiSet.UniqueSet<E>Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSetMultiSet.Entry<E>
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedConstructor needed for subclass serialization.protectedConstructor that assigns the specified Map as the backing store.
- 
Method SummaryModifier and TypeMethodDescriptionintAdds a number of occurrences of the specified object to the MultiSet.voidclear()Clears the multiset by clearing the underlying map.booleanDetermines if the multiset contains the given element by checking if the underlying map contains the element as a key.protected Iterator<MultiSet.Entry<E>> Creates an entry set iterator.Creates a unique set iterator.protected voidReads the multiset in using a custom routine.protected voidWrites the multiset out using a custom routine.booleanCompares this MultiSet to another object.intGets the number of occurrence of the given element in this multiset by looking up its count in the underlying map.protected Map<E, AbstractMapMultiSet.MutableInteger> getMap()Gets the map that backs this multiset.inthashCode()Gets a hash code for the MultiSet compatible with the definition of equals.booleanisEmpty()Returns true if the underlying map is empty.iterator()Gets an iterator over the multiset elements.intRemoves a number of occurrences of the specified object from the MultiSet.protected voidSets the map being wrapped.intsize()Returns the number of elements in this multiset.Object[]toArray()Returns an array of all of this multiset's elements.<T> T[]toArray(T[] array) Returns an array of all of this multiset's elements.protected intReturns the number of unique elements in this multiset.Methods inherited from class org.apache.commons.collections4.multiset.AbstractMultiSetadd, createEntrySet, createUniqueSet, entrySet, remove, removeAll, setCount, toString, uniqueSetMethods inherited from class java.util.AbstractCollectionaddAll, containsAll, retainAllMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionaddAll, parallelStream, removeIf, spliterator, streamMethods inherited from interface org.apache.commons.collections4.MultiSetcontainsAll, retainAll
- 
Constructor Details- 
AbstractMapMultiSetprotected AbstractMapMultiSet()Constructor needed for subclass serialization.
- 
AbstractMapMultiSetConstructor that assigns the specified Map as the backing store. The map must be empty and non-null.- Parameters:
- map- the map to assign
 
 
- 
- 
Method Details- 
addDescription copied from interface:MultiSetAdds a number of occurrences of the specified object to the MultiSet.If the object is already in the MultiSet.uniqueSet()then increment its count as reported byMultiSet.getCount(Object). Otherwise, add it to theMultiSet.uniqueSet()and report its count asoccurrences.- Specified by:
- addin interface- MultiSet<E>
- Overrides:
- addin class- AbstractMultiSet<E>
- 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
 
- 
clearClears the multiset by clearing the underlying map.- Specified by:
- clearin interface- Collection<E>
- Overrides:
- clearin class- AbstractMultiSet<E>
 
- 
containsDetermines if the multiset contains the given element by checking if the underlying map contains the element as a key.- Specified by:
- containsin interface- Collection<E>
- Overrides:
- containsin class- AbstractMultiSet<E>
- Parameters:
- object- the object to search for
- Returns:
- true if the multiset contains the given element
 
- 
createEntrySetIteratorDescription copied from class:AbstractMultiSetCreates an entry set iterator. Subclasses can override this to return iterators with different properties.- Specified by:
- createEntrySetIteratorin class- AbstractMultiSet<E>
- Returns:
- the entrySet iterator
 
- 
createUniqueSetIteratorDescription copied from class:AbstractMultiSetCreates a unique set iterator. Subclasses can override this to return iterators with different properties.- Overrides:
- createUniqueSetIteratorin class- AbstractMultiSet<E>
- Returns:
- the uniqueSet iterator
 
- 
doReadObjectReads the multiset in using a custom routine.- Overrides:
- doReadObjectin class- AbstractMultiSet<E>
- Parameters:
- in- the input stream
- Throws:
- IOException- any of the usual I/O related exceptions
- ClassNotFoundException- if the stream contains an object which class cannot be loaded
- ClassCastException- if the stream does not contain the correct objects
 
- 
doWriteObjectWrites the multiset out using a custom routine.- Overrides:
- doWriteObjectin class- AbstractMultiSet<E>
- Parameters:
- out- the output stream
- Throws:
- IOException- any of the usual I/O related exceptions
 
- 
equalsDescription copied from interface:MultiSetCompares 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>
- Specified by:
- equalsin interface- MultiSet<E>
- Overrides:
- equalsin class- AbstractMultiSet<E>
- Parameters:
- object- the object to compare to
- Returns:
- true if equal
 
- 
getCountGets the number of occurrence of the given element in this multiset by looking up its count in the underlying map.
- 
getMapGets the map that backs this multiset. Not intended for interactive use outside of subclasses.- Returns:
- the map being used by the MultiSet
 
- 
hashCodeDescription copied from interface:MultiSetGets 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>
- Specified by:
- hashCodein interface- MultiSet<E>
- Overrides:
- hashCodein class- AbstractMultiSet<E>
- Returns:
- the hash code of the MultiSet
 
- 
isEmptyReturns true if the underlying map is empty.- Specified by:
- isEmptyin interface- Collection<E>
- Overrides:
- isEmptyin class- AbstractCollection<E>
- Returns:
- true if multiset is empty
 
- 
iteratorGets an iterator over the multiset elements. Elements present in the MultiSet more than once will be returned repeatedly.
- 
removeDescription copied from interface:MultiSetRemoves 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. - Specified by:
- removein interface- MultiSet<E>
- Overrides:
- removein class- AbstractMultiSet<E>
- 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
 
- 
setMapSets the map being wrapped.Note: this method should only be used during deserialization - Parameters:
- map- the map to wrap
 
- 
sizeReturns the number of elements in this multiset.- Specified by:
- sizein interface- Collection<E>
- Specified by:
- sizein interface- MultiSet<E>
- Overrides:
- sizein class- AbstractMultiSet<E>
- Returns:
- current size of the multiset
 
- 
toArrayReturns an array of all of this multiset's elements.- Specified by:
- toArrayin interface- Collection<E>
- Overrides:
- toArrayin class- AbstractCollection<E>
- Returns:
- an array of all of this multiset's elements
 
- 
toArrayReturns an array of all of this multiset's elements. If the input array has more elements than are in the multiset, trailing elements will be set to null.- Specified by:
- toArrayin interface- Collection<E>
- Overrides:
- toArrayin class- AbstractCollection<E>
- Type Parameters:
- T- the type of the array elements
- Parameters:
- array- the array to populate
- Returns:
- an array of all of this multiset's elements
- Throws:
- ArrayStoreException- if the runtime type of the specified array is not a supertype of the runtime type of the elements in this list
- NullPointerException- if the specified array is null
 
- 
uniqueElementsDescription copied from class:AbstractMultiSetReturns the number of unique elements in this multiset.- Specified by:
- uniqueElementsin class- AbstractMultiSet<E>
- Returns:
- the number of unique elements
 
 
-