Class ListMap<K,​V>


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

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.util.Map.Entry<K,​java.util.List<V>>> entrySet()
      Returns the entries of this.
      void freeze()
      Irreversibly prevent changes to the content of this.
      java.util.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.
      java.util.List<V> getList​(K key)
      The same as get
      boolean isFrozen()
      Returns whether this allows changes
      java.util.Set<K> keySet()
      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)  
      V 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 size()
      Returns the number of keys in this map
      java.lang.String toString()  
      java.util.Collection<java.util.List<V>> values()
      Returns the list values of this
      • Methods inherited from class java.lang.Object

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

      • 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​(java.lang.Class<? extends java.util.Map> implementation)
    • Method Detail

      • 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:
        java.lang.IndexOutOfBoundsException - if there is no value at the given index for this key
      • get

        public java.util.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 java.util.List<V> getList​(K key)
        The same as get
      • entrySet

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

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

        public java.util.Collection<java.util.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • size

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