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 Summary
Nested 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.MultiSet
MultiSet.Entry<E> -
Constructor Summary
Constructors -
Method Summary
Modifier 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.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArrayMethods inherited from interface org.apache.commons.collections4.MultiSet
containsAll, retainAll
-
Constructor Details
-
AbstractMultiSet
protected AbstractMultiSet()Constructs a new instance subclasses.
-
-
Method Details
-
add
Description 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 interfaceCollection<E>- Specified by:
addin interfaceMultiSet<E>- Overrides:
addin classAbstractCollection<E>- Parameters:
object- the object to add- Returns:
truealways, as the size of the MultiSet is increased in any case
-
add
Description 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. -
clear
Clears the multiset removing all elements from the entrySet.- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>
-
contains
Determines if the multiset contains the given element.- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
object- the object to search for- Returns:
- true if the multiset contains the given element
-
createEntrySet
Create a new view for the set of entries in this multiset.- Returns:
- a view of the set of entries
-
createEntrySetIterator
Creates an entry set iterator. Subclasses can override this to return iterators with different properties.- Returns:
- the entrySet iterator
-
createUniqueSet
Create a new view for the set of unique elements in this multiset.- Returns:
- a view of the set of unique elements
-
createUniqueSetIterator
Creates a unique set iterator. Subclasses can override this to return iterators with different properties.- Returns:
- the uniqueSet iterator
-
doReadObject
Reads the multiset in using a custom routine.- Parameters:
in- the input stream- Throws:
IOException- any of the usual I/O related exceptionsClassNotFoundException- if the stream contains an object which class cannot be loadedClassCastException- if the stream does not contain the correct objects
-
doWriteObject
Writes the multiset out using a custom routine.- Parameters:
out- the output stream- Throws:
IOException- any of the usual I/O related exceptions
-
entrySet
-
equals
Description 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
-
hashCode
Description 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). -
iterator
Gets an iterator over the multiset elements. Elements present in the MultiSet more than once will be returned repeatedly. -
remove
Description 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 interfaceCollection<E>- Specified by:
removein interfaceMultiSet<E>- Overrides:
removein classAbstractCollection<E>- Parameters:
object- the object to remove- Returns:
trueif this call changed the collection
-
remove
Description 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 interfaceMultiSet<E>- Parameters:
object- the object to removeoccurrences- 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
-
removeAll
Description copied from interface:MultiSetRemove all occurrences of all elements from this MultiSet represented in the given collection.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceMultiSet<E>- Overrides:
removeAllin classAbstractCollection<E>- Parameters:
coll- the collection of elements to remove- Returns:
trueif this call changed the multiset
-
setCount
Description 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(). -
size
Returns the number of elements in this multiset.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceMultiSet<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- current size of the multiset
-
toString
Implement a toString() method suitable for debugging.- Overrides:
toStringin classAbstractCollection<E>- Returns:
- a debugging toString
-
uniqueElements
Returns the number of unique elements in this multiset.- Returns:
- the number of unique elements
-
uniqueSet
-