Package ptolemy.util

Class MultiHashMap<K,​V>

  • Type Parameters:
    K - The type of the keys of the multimap.
    V - The type of the values of the multimap.

    public class MultiHashMap<K,​V>
    extends java.lang.Object
    MultiHashMap is an implementation of the MultiMap interface. It associates a collection of objects to each key. Putting a new object under a key adds to the associated collection. Likewise, removing a object removes from the collection. It is possible that the given object to remove is not contained by the collection. In which case, no changes is made and null is returned. The items in each collection are ordered by insertion, and duplicates are stored in the collections. For example, given a key K and object O1, and O2: MultiHashMap map = new MultiHashMap(); map.put(K, O1); map.put(K, O1); map.put(K, O2); then, map.size(K) would return 3. Iterating through the map returns O1, O1, and O2 in order.
    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Man-Kit Leung, Ben Lickly
    Pt.AcceptedRating:
    Red (mankit)
    Pt.ProposedRating:
    Red (mankit)
    • Constructor Summary

      Constructors 
      Constructor Description
      MultiHashMap()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Collection<V> get​(K key)
      Get the collection of values mapped to by a given key.
      boolean isEmpty()
      Return whether or not this multimap is empty.
      java.util.Set<K> keySet()
      Return a set of all key values represented by this multimap.
      void put​(K key, V value)
      Add the value to the collection associated with the specified key.
      boolean remove​(K key, V value)
      Remove a specified value from the map.
      int size​(java.lang.Object key)
      Return the size of the collection mapped to the specified key.
      java.util.Collection<V> values()
      Return a view of the collection containing all values in the map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MultiHashMap

        public MultiHashMap()
    • Method Detail

      • get

        public java.util.Collection<V> get​(K key)
        Get the collection of values mapped to by a given key.
        Parameters:
        key - The index into the multimap.
        Returns:
        The collection of values at that index.
      • keySet

        public java.util.Set<K> keySet()
        Return a set of all key values represented by this multimap.
        Returns:
        A set of values that are keys of this multimap.
      • isEmpty

        public boolean isEmpty()
        Return whether or not this multimap is empty.
        Returns:
        True, if the map is empty. False, otherwise.
      • put

        public void put​(K key,
                        V value)
        Add the value to the collection associated with the specified key.
        Parameters:
        key - The specified key.
        value - The specified value to add to the collection.
      • remove

        public boolean remove​(K key,
                              V value)
        Remove a specified value from the map. The value is removed from the collection mapped to the specified key. If this is the last value removed from the given key, the specified key is also removed from the map. Subsequent call to get(key) will return false.
        Parameters:
        key - The specified key to remove the value from.
        value - The specified value to remove.
        Returns:
        True, if the value was removed. False, otherwise.
      • size

        public int size​(java.lang.Object key)
        Return the size of the collection mapped to the specified key.
        Parameters:
        key - The specified key.
        Returns:
        The size of the collection, or zero if key is not in the map.
      • values

        public java.util.Collection<V> values()
        Return a view of the collection containing all values in the map. This is a collection containing the union of each collection mapped to the keys.
        Returns:
        A view of all values contained in this map.