Package randoop.util

Class MultiMap<K,V>

java.lang.Object
randoop.util.MultiMap<K,V>
All Implemented Interfaces:
IMultiMap<K,V>
Direct Known Subclasses:
MultiMap.EmptyMultiMap

public class MultiMap<K,V> extends Object implements IMultiMap<K,V>
Implements an IMultiMap with a java.util.LinkedHashMap.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    An immutable, empty multimap.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<K,Set<V>>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    MultiMap(int initialCapacity)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(K key, V value)
    Precondition: the mapping key→value is not already in the map.
    void
    addAll(Map<? extends K,? extends V> m)
     
    void
    addAll(K key, Collection<? extends V> values)
     
    void
    addAll(MultiMap<K,V> mmap)
     
    void
     
    boolean
    contains(K obj)
     
    static <K, V> MultiMap<K,V>
    Returns an immutable, empty multimap.
    getValues(K key)
    Returns the values that the given key maps to.
    boolean
     
    Returns the set of keys in this map (the domain).
    void
    put(K key, Collection<? extends V> values)
    Adds a key-values mapping to this multimap
    boolean
    remove(K key)
     
    boolean
    remove(K key, V value)
    Precondition: the mapping key→value is in the map.
    int
    Returns the size of this map: the number of mappings.
    Returns a String representation of this map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • MultiMap

      public MultiMap()
    • MultiMap

      public MultiMap(int initialCapacity)
  • Method Details

    • empty

      public static <K, V> MultiMap<K,V> empty()
      Returns an immutable, empty multimap.
      Returns:
      an immutable, empty multimap
    • put

      public void put(K key, Collection<? extends V> values)
      Adds a key-values mapping to this multimap
      Parameters:
      key - the key
      values - the values
    • addAll

      public void addAll(Map<? extends K,? extends V> m)
    • addAll

      public void addAll(K key, Collection<? extends V> values)
    • addAll

      public void addAll(MultiMap<K,V> mmap)
    • add

      public boolean add(K key, V value)
      Description copied from interface: IMultiMap
      Precondition: the mapping key→value is not already in the map.
      Specified by:
      add in interface IMultiMap<K,V>
      Parameters:
      key - cannot be null
      value - cannot be null
      Returns:
      true if the call modifies this object
    • remove

      public boolean remove(K key, V value)
      Description copied from interface: IMultiMap
      Precondition: the mapping key→value is in the map.
      Specified by:
      remove in interface IMultiMap<K,V>
      Parameters:
      key - cannot be null
      value - cannot be null
      Returns:
      true if the call modifies this object
    • remove

      public boolean remove(K key)
    • getValues

      public Set<V> getValues(K key)
      Description copied from interface: IMultiMap
      Returns the values that the given key maps to.
      Specified by:
      getValues in interface IMultiMap<K,V>
      Parameters:
      key - cannot be null
      Returns:
      the set of values for the given key
    • keySet

      public Set<K> keySet()
      Description copied from interface: IMultiMap
      Returns the set of keys in this map (the domain).
      Specified by:
      keySet in interface IMultiMap<K,V>
      Returns:
      the set of keys in this map
    • contains

      public boolean contains(K obj)
    • clear

      public void clear()
    • size

      public int size()
      Description copied from interface: IMultiMap
      Returns the size of this map: the number of mappings.
      Specified by:
      size in interface IMultiMap<K,V>
      Returns:
      the number of entries in this map
    • isEmpty

      public boolean isEmpty()
    • toString

      public String toString()
      Description copied from interface: IMultiMap
      Returns a String representation of this map.
      Specified by:
      toString in interface IMultiMap<K,V>
      Overrides:
      toString in class Object
      Returns:
      a String representation of this map