Class ListMap<K,V>

java.lang.Object
com.yahoo.collections.ListMap<K,V>

public class ListMap<K,V> extends Object
A map holding multiple items at each key (using ArrayList and HashMap).
Author:
bratseth
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ListMap(ListMap<K,V> original)
    Copy constructor.
    ListMap(Class<? extends Map> implementation)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the entries of this.
    void
    Irreversibly prevent changes to the content of this.
    get(K key)
    Returns the List containing the elements with this key, or an empty list if there are no elements for this key.
    getList(K key)
    The same as get
    boolean
    Returns whether this allows changes
    Returns the keys of this
    void
    put(K key)
    Put a key without adding a new value, such that there is an empty list of values if no values are already added
    void
    put(K key, V value)
    Puts an element into this.
    void
    removeAll(K key)
     
    removeValue(K key, int index)
    Removes the value at the given index.
    boolean
    removeValue(K key, V value)
     
    void
    replace(K key, V value)
    Put this map in the state where it has just the given value of the given key
    int
    Returns the number of keys in this map
     
    Returns the list values of this

    Methods inherited from class java.lang.Object

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

    • ListMap

      public ListMap()
    • ListMap

      public ListMap(ListMap<K,V> original)
      Copy constructor. This will not be frozen even if the argument map is
    • ListMap

      public ListMap(Class<? extends Map> implementation)
  • Method Details

    • put

      public void put(K key, V value)
      Puts an element into this. Multiple elements at the same position are added to the list at this key
    • put

      public void put(K key)
      Put a key without adding a new value, such that there is an empty list of values if no values are already added
    • replace

      public void replace(K key, V value)
      Put this map in the state where it has just the given value of the given key
    • removeAll

      public void removeAll(K key)
    • removeValue

      public boolean removeValue(K key, V value)
    • removeValue

      public V removeValue(K key, int index)
      Removes the value at the given index.
      Returns:
      the removed value
      Throws:
      IndexOutOfBoundsException - if there is no value at the given index for this key
    • get

      public List<V> get(K key)
      Returns the List containing the elements with this key, or an empty list if there are no elements for this key. The returned list can be modified to add and remove values if the value exists.
    • getList

      public List<V> getList(K key)
      The same as get
    • entrySet

      public Set<Map.Entry<K,List<V>>> entrySet()
      Returns the entries of this. Entries will be unmodifiable if this is frozen.
    • keySet

      public Set<K> keySet()
      Returns the keys of this
    • values

      public Collection<List<V>> values()
      Returns the list values of this
    • freeze

      public void freeze()
      Irreversibly prevent changes to the content of this. If this is already frozen, this method does nothing.
    • isFrozen

      public boolean isFrozen()
      Returns whether this allows changes
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • size

      public int size()
      Returns the number of keys in this map