Class TreeMultiSet<E>
- Type Parameters:
E- The type held in the multiset
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,MultiSet<E>,SortedMultiSet<E>
SortedMultiSet, using a TreeMap to provide the
data storage. This is the standard implementation of a sorted multiset.
Order will be maintained among the multiset members and can be viewed through the iterator.
A MultiSet stores each object in the collection together with a
count of occurrences. Extra methods on the interface allow multiple copies
of an object to be added or removed at once.
Note that TreeMultiSet is not synchronized and is not thread-safe.
If you wish to use this multiset from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this multiset using
MultiSetUtils.synchronizedSortedMultiSet(SortedMultiSet).
Unsynchronized concurrent modification can corrupt the structure of the backing
TreeMap, and a malformed tree may cause subsequent operations, including
reads, to enter an infinite loop.
- Since:
- 4.6.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.collections4.multiset.AbstractMapMultiSet
AbstractMapMultiSet.EntrySetIterator<E>, AbstractMapMultiSet.MultiSetEntry<E>, AbstractMapMultiSet.MutableInteger, AbstractMapMultiSet.UniqueSetIterator<E>Nested classes/interfaces inherited from class org.apache.commons.collections4.multiset.AbstractMultiSet
AbstractMultiSet.AbstractEntry<E>, AbstractMultiSet.EntrySet<E>, AbstractMultiSet.UniqueSet<E>Nested classes/interfaces inherited from interface org.apache.commons.collections4.MultiSet
MultiSet.Entry<E> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an emptyTreeMultiSet.TreeMultiSet(Iterable<? extends E> iterable) Constructs a multiset containing all the members of the given Iterable.TreeMultiSet(Collection<? extends E> coll) Constructs aTreeMultiSetcontaining all the members of the specified collection.TreeMultiSet(Comparator<? super E> comparator) Constructs an empty multiset that maintains order on its unique representative members according to the givenComparator. -
Method Summary
Modifier and TypeMethodDescriptionintAlways throwsUnsupportedOperationException.Comparator<? super E> Returns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.first()Returns the first (lowest) member.protected SortedMap<E, AbstractMapMultiSet.MutableInteger> getMap()Gets the map that backs this multiset.last()Returns the last (highest) member.Methods inherited from class org.apache.commons.collections4.multiset.AbstractMapMultiSet
clear, contains, createEntrySetIterator, createUniqueSetIterator, doReadObject, doWriteObject, equals, getCount, hashCode, isEmpty, iterator, remove, setMap, size, toArray, toArray, uniqueElementsMethods inherited from class org.apache.commons.collections4.multiset.AbstractMultiSet
add, createEntrySet, createUniqueSet, entrySet, remove, removeAll, setCount, toString, uniqueSetMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAllMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, clear, contains, isEmpty, parallelStream, removeIf, spliterator, stream, toArray, toArray
-
Constructor Details
-
TreeMultiSet
public TreeMultiSet()Constructs an emptyTreeMultiSet. -
TreeMultiSet
Constructs aTreeMultiSetcontaining all the members of the specified collection.- Parameters:
coll- The collection to copy into the multiset
-
TreeMultiSet
Constructs an empty multiset that maintains order on its unique representative members according to the givenComparator.- Parameters:
comparator- The comparator to use
-
TreeMultiSet
Constructs a multiset containing all the members of the given Iterable.- Parameters:
iterable- An iterable to copy into this multiset.- Since:
- 4.6.0
-
-
Method Details
-
add
Always throwsUnsupportedOperationException.- Specified by:
addin interfaceMultiSet<E>- Overrides:
addin classAbstractMapMultiSet<E>- Parameters:
object- Ignored.occurrences- Ignored.- Returns:
- The number of occurrences of the object in the multiset before this operation; possibly zero.
- Throws:
IllegalArgumentException- if the object to be added does not implementComparableand theTreeMultiSetis using natural orderingNullPointerException- if the specified key is null and this multiset uses natural ordering, or its comparator does not permit null keys
-
comparator
Description copied from interface:SortedMultiSetReturns the comparator associated with this sorted multiset, or null if it uses its elements' natural ordering.- Specified by:
comparatorin interfaceSortedMultiSet<E>- Returns:
- The comparator in use, or null if natural ordering.
-
first
Description copied from interface:SortedMultiSetReturns the first (lowest) member.- Specified by:
firstin interfaceSortedMultiSet<E>- Returns:
- The first element in the sorted multiset.
-
getMap
Description copied from class:AbstractMapMultiSetGets the map that backs this multiset. Not intended for interactive use outside of subclasses.- Overrides:
getMapin classAbstractMapMultiSet<E>- Returns:
- The map being used by the MultiSet.
-
last
Description copied from interface:SortedMultiSetReturns the last (highest) member.- Specified by:
lastin interfaceSortedMultiSet<E>- Returns:
- The last element in the sorted multiset.
-