Class TreeMultiSet<E>

Type Parameters:
E - The type held in the multiset
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, MultiSet<E>, SortedMultiSet<E>

public class TreeMultiSet<E> extends AbstractMapMultiSet<E> implements SortedMultiSet<E>, Serializable
Implements 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:
  • Constructor Details

    • TreeMultiSet

      public TreeMultiSet()
      Constructs an empty TreeMultiSet.
    • TreeMultiSet

      public TreeMultiSet(Collection<? extends E> coll)
      Constructs a TreeMultiSet containing all the members of the specified collection.
      Parameters:
      coll - The collection to copy into the multiset
    • TreeMultiSet

      public TreeMultiSet(Comparator<? super E> comparator)
      Constructs an empty multiset that maintains order on its unique representative members according to the given Comparator.
      Parameters:
      comparator - The comparator to use
    • TreeMultiSet

      public TreeMultiSet(Iterable<? extends E> iterable)
      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