Class AbstractMultiSet<E>
- Type Parameters:
- E- the type held in the multiset
- All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- MultiSet<E>
- Direct Known Subclasses:
- AbstractMapMultiSet
MultiSet interface to simplify the
 creation of subclass implementations.- Since:
- 4.1
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classInner class AbstractEntry.protected static classInner class EntrySet.protected static classInner class UniqueSet.Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSetMultiSet.Entry<E>
- 
Constructor SummaryConstructors
- 
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.voidclear()Clears the multiset removing all elements from the entrySet.booleanDetermines if the multiset contains the given element.protected Set<MultiSet.Entry<E>> Create a new view for the set of entries in this multiset.protected abstract Iterator<MultiSet.Entry<E>> Creates an entry set iterator.Create a new view for the set of unique elements in this multiset.Creates a unique set iterator.protected voidReads the multiset in using a custom routine.protected voidWrites the multiset out using a custom routine.entrySet()Returns an unmodifiable view of the entries of this multiset.booleanCompares this MultiSet to another object.intGets the number of occurrence of the given element in this multiset by iterating over its entrySet.inthashCode()Gets a hash code for the MultiSet compatible with the definition of equals.iterator()Gets an iterator over the multiset elements.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.intSets the number of occurrences of the specified object in the MultiSet to the given count.intsize()Returns the number of elements in this multiset.toString()Implement a toString() method suitable for debugging.protected abstract intReturns the number of unique elements in this multiset.Returns a view of the unique elements of this multiset.Methods inherited from class java.util.AbstractCollectionaddAll, containsAll, isEmpty, retainAll, toArray, toArrayMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionaddAll, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArrayMethods inherited from interface org.apache.commons.collections4.MultiSetcontainsAll, retainAll
- 
Constructor Details- 
AbstractMultiSetprotected AbstractMultiSet()Constructs a new instance subclasses.
 
- 
- 
Method Details- 
addDescription copied from interface:MultiSetAdds one copy 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 as 1.- Specified by:
- addin interface- Collection<E>
- Specified by:
- addin interface- MultiSet<E>
- Overrides:
- addin class- AbstractCollection<E>
- Parameters:
- object- the object to add
- Returns:
- truealways, as the size of the MultiSet is increased in any case
 
- 
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.
- 
clearClears the multiset removing all elements from the entrySet.- Specified by:
- clearin interface- Collection<E>
- Overrides:
- clearin class- AbstractCollection<E>
 
- 
containsDetermines if the multiset contains the given element.- Specified by:
- containsin interface- Collection<E>
- Overrides:
- containsin class- AbstractCollection<E>
- Parameters:
- object- the object to search for
- Returns:
- true if the multiset contains the given element
 
- 
createEntrySetCreate a new view for the set of entries in this multiset.- Returns:
- a view of the set of entries
 
- 
createEntrySetIteratorCreates an entry set iterator. Subclasses can override this to return iterators with different properties.- Returns:
- the entrySet iterator
 
- 
createUniqueSetCreate a new view for the set of unique elements in this multiset.- Returns:
- a view of the set of unique elements
 
- 
createUniqueSetIteratorCreates a unique set iterator. Subclasses can override this to return iterators with different properties.- Returns:
- the uniqueSet iterator
 
- 
doReadObjectReads the multiset in using a custom routine.- 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.- Parameters:
- out- the output stream
- Throws:
- IOException- any of the usual I/O related exceptions
 
- 
entrySet
- 
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. 
- 
getCount
- 
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).
- 
iteratorGets an iterator over the multiset elements. Elements present in the MultiSet more than once will be returned repeatedly.
- 
removeDescription copied from interface:MultiSetRemoves 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 MultiSet.uniqueSet().- Specified by:
- removein interface- Collection<E>
- Specified by:
- removein interface- MultiSet<E>
- Overrides:
- removein class- AbstractCollection<E>
- Parameters:
- object- the object to remove
- Returns:
- trueif this call changed the collection
 
- 
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>
- 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
 
- 
removeAllDescription copied from interface:MultiSetRemove all occurrences of all elements from this MultiSet represented in the given collection.- Specified by:
- removeAllin interface- Collection<E>
- Specified by:
- removeAllin interface- MultiSet<E>
- Overrides:
- removeAllin class- AbstractCollection<E>
- Parameters:
- coll- the collection of elements to remove
- Returns:
- trueif this call changed the multiset
 
- 
setCountDescription copied from interface:MultiSetSets 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 MultiSet.uniqueSet().
- 
sizeReturns the number of elements in this multiset.- Specified by:
- sizein interface- Collection<E>
- Specified by:
- sizein interface- MultiSet<E>
- Specified by:
- sizein class- AbstractCollection<E>
- Returns:
- current size of the multiset
 
- 
toStringImplement a toString() method suitable for debugging.- Overrides:
- toStringin class- AbstractCollection<E>
- Returns:
- a debugging toString
 
- 
uniqueElementsReturns the number of unique elements in this multiset.- Returns:
- the number of unique elements
 
- 
uniqueSet
 
-