Class LazyMap<K,​V>

  • Type Parameters:
    K - The type of key.
    V - The type of value.
    All Implemented Interfaces:
    Map<K,​V>

    public class LazyMap<K,​V>
    extends Object
    implements Map<K,​V>
    A map with lazy initialization. The factory is called to initialize the map on the first call to one of this object's methods.
    • Field Detail

      • factory

        protected Factory<Map<K,​V>> factory
        Factory to create the instance of the map to expose.
    • Constructor Detail

      • LazyMap

        protected LazyMap()
        Constructs a new lazy map. Allows factory to be set in subclass constructor.
      • LazyMap

        public LazyMap​(Factory<Map<K,​V>> factory)
        Constructs a new lazy map.
        Parameters:
        factory - factory to create the map instance to expose.
    • Method Detail

      • size

        public int size()
        Returns the number of key-value mappings in this map.
        Specified by:
        size in interface Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Returns true if the map contains no key-value mappings.
        Specified by:
        isEmpty in interface Map<K,​V>
      • containsKey

        public boolean containsKey​(Object key)
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface Map<K,​V>
        Parameters:
        key - the key whose presence in this map is to be tested.
        Returns:
        true if this map contains a mapping for the specified key.
      • containsValue

        public boolean containsValue​(Object value)
        Returns true if the map maps one or more keys to the specified value.
        Specified by:
        containsValue in interface Map<K,​V>
        Parameters:
        value - the value whose presence in the map is to be tested.
        Returns:
        true if the map maps one or more keys to the specified value.
      • get

        public V get​(Object key)
        Returns the value to which the specified key is mapped, or null if the map contains no mapping for the key.
        Specified by:
        get in interface Map<K,​V>
        Parameters:
        key - the key whose associated value is to be returned.
        Returns:
        the value to which the specified key is mapped, or null if no mapping.
      • put

        public V put​(K key,
                     V value)
        Associates the specified value with the specified key in the map.
        Specified by:
        put in interface Map<K,​V>
        Parameters:
        key - key with which the specified value is to be associated.
        value - value to be associated with the specified key.
        Returns:
        the previous value associated with key, or null if no mapping.
      • remove

        public V remove​(Object key)
        Removes the mapping for a key from the map if it is present.
        Specified by:
        remove in interface Map<K,​V>
        Parameters:
        key - key whose mapping is to be removed from the map.
        Returns:
        the previous value associated with key, or null if no mapping.
      • putAll

        public void putAll​(Map<? extends K,​? extends V> m)
        Copies all of the mappings from the specified map to the map.
        Specified by:
        putAll in interface Map<K,​V>
        Parameters:
        m - mappings to be stored in the map.
      • clear

        public void clear()
        Removes all of the mappings from the map.
        Specified by:
        clear in interface Map<K,​V>
      • keySet

        public Set<K> keySet()
        Returns a Set view of the keys contained in the map.
        Specified by:
        keySet in interface Map<K,​V>
      • entrySet

        public Set<Map.Entry<K,​V>> entrySet()
        Returns a Set view of the mappings contained in the map.
        Specified by:
        entrySet in interface Map<K,​V>
      • hashCode

        public int hashCode()
        Returns the hash code value for the map.
        Specified by:
        hashCode in interface Map<K,​V>
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object o)
        Compares the specified object with the map for equality.
        Specified by:
        equals in interface Map<K,​V>
        Overrides:
        equals in class Object
        Parameters:
        o - object to be compared for equality with the map.
        Returns:
        true if the specified object is equal to the map.