Class HashMultiSet<T>

  • Type Parameters:
    T - the class of the elements of this multi-set.
    All Implemented Interfaces:
    MultiSet<T>, java.lang.Iterable<T>

    public final class HashMultiSet<T>
    extends AbstractMultiSet<java.util.Map<T,​MultiSet.Multiplicity>,​T>
    implements MultiSet<T>
    Represents a set with multiplicities based on a HashMap. Mathematically this is something between a set and a family. Note that this kind of set does support null elements.
    Version:
    1.0
    Author:
    Ernst Reissner
    • Constructor Detail

      • HashMultiSet

        public HashMultiSet()
        Creates a new, empty MultiSet.
      • HashMultiSet

        public HashMultiSet​(MultiSet<? extends T> other)
        Copy constructor.
        Parameters:
        other - another MultiSet instance.
      • HashMultiSet

        public HashMultiSet​(java.util.Set<? extends T> sSet)
        Creates a multi set with the elements of sSet and all elements with multiplicity 1.
        Parameters:
        sSet - some instance of a sorted set.
    • Method Detail

      • getSet

        public java.util.Set<T> getSet()
        Returns a view of the underlying set of this MultiSet. For certain implementations, this set is immutable to prevent implicit modification of this MultiSet.
        Specified by:
        getSet in interface MultiSet<T>
        Returns:
        the Set containing exactly the objects with strictly positive multiplicity in this MultiSet.
      • getMap

        public java.util.Map<T,​MultiSet.Multiplicity> getMap()
        Returns a view of the underlying map of this MultiSet as a map mapping each entry to its multiplicity.
        Specified by:
        getMap in interface MultiSet<T>
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface MultiSet<T>
        Overrides:
        toString in class java.lang.Object