Class HashMultiSet<T>

  • Type Parameters:
    T - the type of elements
    All Implemented Interfaces:
    MultiSet<T>, Iterable<T>


    public class HashMultiSet<T>
    extends Object
    implements MultiSet<T>
    A straightforward implementation of MultiSet using a HashMap.
    • Constructor Detail

      • HashMultiSet

        public HashMultiSet()
      • HashMultiSet

        public HashMultiSet(MultiSet<T> prototype)
    • Method Detail

      • contains

        public boolean contains(T key)
        Description copied from interface: MultiSet
        Test whether key is present in this MultiSet.
        Specified by:
        contains in interface  MultiSet<T>
        Parameters:
        key - the element queried.
        Returns:
        whether key is contained in this MultiSet.
      • occurences

        public int occurences(T key)
        Description copied from interface: MultiSet
        Get the number of times the element key is present in this MultiSet.
        Specified by:
        occurences in interface  MultiSet<T>
        Parameters:
        key - the element queried.
        Returns:
        the number of occurrences of key in this MultiSet.
      • put

        public void put(T key)
        Description copied from interface: MultiSet
        Put key to the MultiSet once.
        Specified by:
        put in interface  MultiSet<T>
        Parameters:
        key - the element to add.
      • put

        public void put(T key,
                        int howOften)
      • putAll

        public void putAll(Collection<T> keys)
        Description copied from interface: MultiSet
        Put all keys contained in key into the MultiSet once.
        Specified by:
        putAll in interface  MultiSet<T>
        Parameters:
        keys - a collection of keys.
      • remove

        public void remove(T key)
        Description copied from interface: MultiSet
        Remove key from the MultiSet once.
        Specified by:
        remove in interface  MultiSet<T>
        Parameters:
        key - the element to remove.
      • removeAll

        public void removeAll(T key)
        Description copied from interface: MultiSet
        Remove all occurrences of key.
        Specified by:
        removeAll in interface  MultiSet<T>
        Parameters:
        key - the element to remove.
      • removeN

        public void removeN(T key,
                            int n)
        Description copied from interface: MultiSet
        Remove key from the MultiSet once.
        Specified by:
        removeN in interface  MultiSet<T>
        Parameters:
        key - the element to remove.
        n - the number of times to remove the specified element.
      • keySet

        public Set<T> keySet()
        Description copied from interface: MultiSet
        Get the set of keys in this MultiSet.
        Specified by:
        keySet in interface  MultiSet<T>
        Returns:
        the set of keys.