Class RestrictedCollections.RestrictedMap

    • Field Detail

      • m_map

        protected Map m_map
        The underlying Map.
      • m_clzKey

        protected Class m_clzKey
        The class of key stored in the Map.
      • m_clzVal

        protected Class m_clzVal
        The class of value stored in the Map.
      • m_set

        protected Set m_set
        The Entry Set.
    • Constructor Detail

      • RestrictedMap

        public RestrictedMap​(Map map,
                             Class clzKey,
                             Class clzVal)
        Constructor.
        Parameters:
        map - the underlying Map
        clzKey - the class of keys that may be stored in the Map
        clzVal - the class of values that may be stored in the Map
    • Method Detail

      • size

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

        public boolean isEmpty()
        Returns true if this map contains no key-value mappings.
        Specified by:
        isEmpty in interface Map
        Returns:
        true if this map contains no key-value mappings
      • containsKey

        public boolean containsKey​(Object key)
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface Map
        Parameters:
        key - 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 this map maps one or more keys to the specified value.
        Specified by:
        containsValue in interface Map
        Parameters:
        value - value whose presence in this map is to be tested
        Returns:
        true if this map maps one or more keys to the specified value.
      • get

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

        public Object put​(Object key,
                          Object value)
        Associates the specified value with the specified key in this map.
        Specified by:
        put in interface 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 null if there was no mapping for key
        Throws:
        ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
      • remove

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

        public void putAll​(Map map)
        Copies all of the mappings from the specified map to this map.
        Specified by:
        putAll in interface Map
        Parameters:
        map - Mappings to be stored in this map
        Throws:
        ClassCastException - if the class of a key or value in the specified map prevents it from being stored in this map
      • clear

        public void clear()
        Removes all mappings from this map.
        Specified by:
        clear in interface Map
      • keySet

        public 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.
        Specified by:
        keySet in interface Map
        Returns:
        a set view of the keys contained in this map
      • values

        public 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.
        Specified by:
        values in interface Map
        Returns:
        a collection view of the values contained in this map
      • entrySet

        public 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.
        Specified by:
        entrySet in interface Map
        Returns:
        a set view of the mappings contained in this map
      • equals

        public boolean equals​(Object o)
        Compares the specified object with this map for equality. Obeys the general contract of Map.equals.
        Specified by:
        equals in interface Map
        Overrides:
        equals in class Object
        Parameters:
        o - object to be compared for equality with this map
        Returns:
        true if the specified object is equal to this map
      • hashCode

        public int hashCode()
        Returns the hash code value for this map. Obeys the general contract of Map.hashCode.
        Specified by:
        hashCode in interface Map
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this map
      • toString

        public String toString()
        Return a String description for this Map.
        Overrides:
        toString in class Object
        Returns:
        a String description of the Map
      • checkKey

        protected void checkKey​(Object o)
        Check the passed object to verify that it passes the "key" restriction of this Map.
        Parameters:
        o - the Object to check
        Throws:
        ClassCastException - if the class of the passed Object prevents it from being used as a key in this Map
      • checkValue

        protected void checkValue​(Object o)
        Check the passed object to verify that it passes the "value" restriction of this Map.
        Parameters:
        o - the Object to check
        Throws:
        ClassCastException - if the class of the passed Object prevents it from being used as a value in this Map