Class NestedMap

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Map

    public class NestedMap
    extends java.lang.Object
    implements java.util.Map, java.io.Serializable
    A nested map refers to parent maps for entries not found in this map. Modifications of this map do not affect the parent maps.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map local
      The local map.
      protected java.util.Map[] parents
      The parent maps.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        NestedMap​(java.util.Map parent)
      Create a nested map, referring to the specified parent map.
        NestedMap​(java.util.Map[] parents)
      Create a nested map, referring to the specified parent maps.
      protected NestedMap​(java.util.Map[] parents, java.util.Map local)
      Create a nested map, referring to the specified parent map, using the given map for storing local mappings.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from this map (optional operation).
      boolean containsKey​(java.lang.Object key)
      Returns
      boolean containsValue​(java.lang.Object value)
      Returns
      java.util.Set entrySet()
      Returns a set view of the mappings contained in this map.
      boolean equals​(java.lang.Object o)
      Compares the specified object with this map for equality.
      java.lang.Object get​(java.lang.Object key)
      Returns the value to which this map maps the specified key.
      java.util.Map getLocalMap()
      Get the map containing the local mappings.
      int hashCode()
      Returns the hash code value for this map.
      boolean isEmpty()
      Returns
      java.util.Set keySet()
      Returns a set view of the keys contained in this map.
      java.lang.Object put​(java.lang.Object key, java.lang.Object value)
      Associates the specified value with the specified key in this map (optional operation).
      void putAll​(java.util.Map t)
      Copies all of the mappings from the specified map to this map (optional operation).
      java.lang.Object remove​(java.lang.Object key)
      Removes the mapping for this key from this map if it is present (optional operation).
      int size()
      Returns the number of key-value mappings in this map.
      java.lang.String toString()
      Create a string representation of this map.
      java.util.Collection values()
      Returns a collection view of the values contained in this map.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • local

        protected java.util.Map local
        The local map.
      • parents

        protected java.util.Map[] parents
        The parent maps.
    • Constructor Detail

      • NestedMap

        public NestedMap​(java.util.Map parent)
        Create a nested map, referring to the specified parent map.
        Parameters:
        parent - The parent map.
      • NestedMap

        public NestedMap​(java.util.Map[] parents)
        Create a nested map, referring to the specified parent maps.
        Parameters:
        parents - The parent maps.
      • NestedMap

        protected NestedMap​(java.util.Map[] parents,
                            java.util.Map local)
        Create a nested map, referring to the specified parent map, using the given map for storing local mappings.
        Parameters:
        parents - The parent map.
        local - The map for local mappings.
    • Method Detail

      • getLocalMap

        public java.util.Map getLocalMap()
        Get the map containing the local mappings.
      • size

        public int size()
        Returns the number of key-value mappings in this map. If the map contains more than
        Specified by:
        size in interface java.util.Map
        Returns:
        the number of key-value mappings in this map.
      • isEmpty

        public boolean isEmpty()
        Returns
        Specified by:
        isEmpty in interface java.util.Map
        Returns:
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Returns
        Specified by:
        containsKey in interface java.util.Map
        Parameters:
        key - key whose presence in this map is to be tested.
        Returns:
        Throws:
        java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
        java.lang.NullPointerException - if the key is
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Returns
        Specified by:
        containsValue in interface java.util.Map
        Parameters:
        value - value whose presence in this map is to be tested.
        Returns:
        Throws:
        java.lang.ClassCastException - if the value is of an inappropriate type for this map (optional).
        java.lang.NullPointerException - if the value is
      • get

        public java.lang.Object get​(java.lang.Object key)
        Returns the value to which this map maps the specified key. Returns
        Specified by:
        get in interface java.util.Map
        Parameters:
        key - key whose associated value is to be returned.
        Returns:
        the value to which this map maps the specified key, or
        Throws:
        java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
        java.lang.NullPointerException - key is
        See Also:
        containsKey(Object)
      • put

        public java.lang.Object put​(java.lang.Object key,
                                    java.lang.Object value)
        Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced by the specified value. (A map m.containsKey(k) would return
        Specified by:
        put in interface java.util.Map
        Parameters:
        key - key with which the specified value is to be associated.
        value - value to be associated with the specified key.
        Returns:
        previous value associated with specified key, or
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
        java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
        java.lang.NullPointerException - this map does not permit
      • remove

        public java.lang.Object remove​(java.lang.Object key)
        Removes the mapping for this key from this map if it is present (optional operation). More formally, if this map contains a mapping from key (key==null ? k==null : key.equals(k)), that mapping is removed. (The map can contain at most one such mapping.)
        Specified by:
        remove in interface java.util.Map
        Parameters:
        key - key whose mapping is to be removed from the map.
        Returns:
        previous value associated with specified key, or
        Throws:
        java.lang.ClassCastException - if the key is of an inappropriate type for this map (optional).
        java.lang.NullPointerException - if the key is
        java.lang.UnsupportedOperationException - if the
      • putAll

        public void putAll​(java.util.Map t)
        Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key
        Specified by:
        putAll in interface java.util.Map
        Parameters:
        t - Mappings to be stored in this map.
        Throws:
        java.lang.UnsupportedOperationException - if the
        java.lang.ClassCastException - if the class of a key or value in the specified map prevents it from being stored in this map.
        java.lang.IllegalArgumentException - some aspect of a key or value in the specified map prevents it from being stored in this map.
        java.lang.NullPointerException - the specified map is
      • clear

        public void clear()
        Removes all mappings from this map (optional operation).
        Specified by:
        clear in interface java.util.Map
        Throws:
        java.lang.UnsupportedOperationException - if clear is not supported by this map.
      • keySet

        public java.util.Set keySet()
        Returns a set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the
        Specified by:
        keySet in interface java.util.Map
        Returns:
        a set view of the keys contained in this map.
      • values

        public java.util.Collection values()
        Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the
        Specified by:
        values in interface java.util.Map
        Returns:
        a collection view of the values contained in this map.
      • entrySet

        public java.util.Set entrySet()
        Returns a set view of the mappings contained in this map. Each element in the returned set is a Map.Entry. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the
        Specified by:
        entrySet in interface java.util.Map
        Returns:
        a set view of the mappings contained in this map.
      • equals

        public boolean equals​(java.lang.Object o)
        Compares the specified object with this map for equality. Returns
        Specified by:
        equals in interface java.util.Map
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - object to be compared for equality with this map.
        Returns:
      • hashCode

        public int hashCode()
        Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hashCodes of each entry in the map's entrySet view. This ensures that
        Specified by:
        hashCode in interface java.util.Map
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this map.
        See Also:
        Object.hashCode(), Object.equals(Object), equals(Object)
      • toString

        public java.lang.String toString()
        Create a string representation of this map.
        Overrides:
        toString in class java.lang.Object