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.
      • add

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

        public void add(T key,
                        int howOften)
      • addAll

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

        public void addAll(Collection<T> keys,
                           int howOften)
      • 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(Collection<? extends T> c)
      • removeOccurences

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

        public void removeAllOccurences(Collection<? extends T> c)
      • 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.
      • removeAllN

        public void removeAllN(Collection<? extends T> c,
                               int n)
      • 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.