Class AbstractKeyBasedMap<K,​V>

    • Constructor Detail

      • AbstractKeyBasedMap

        public AbstractKeyBasedMap()
    • Method Detail

      • clear

        public void clear()
        Clear all key/value mappings.
        Specified by:
        clear in interface Map<K,​V>
      • containsKey

        public boolean containsKey​(Object oKey)
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface Map<K,​V>
        Returns:
        true if this map contains a mapping for the specified key, false otherwise.
      • containsValue

        public boolean containsValue​(Object oValue)
        Returns true if this Map maps one or more keys to the specified value.
        Specified by:
        containsValue in interface Map<K,​V>
        Returns:
        true if this Map maps one or more keys to the specified value, false otherwise
      • entrySet

        public Set<Map.Entry<K,​V>> entrySet()
        Returns a set view of the mappings contained in this map. Each element in the returned set is an 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 (except by the iterator's own remove operation, or by the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It is not expected to support the add or addAll operations.
        Specified by:
        entrySet in interface Map<K,​V>
        Returns:
        a set view of the mappings contained in this map
      • get

        public abstract V get​(Object oKey)
        Returns the value to which this map maps the specified key.
        Specified by:
        get in interface Map<K,​V>
        Parameters:
        oKey - the key object
        Returns:
        the value to which this map maps the specified key, or null if the map contains no mapping for this key
      • isEmpty

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

        public Set<K> 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 (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It is not expected to support the add or addAll operations.
        Specified by:
        keySet in interface Map<K,​V>
        Returns:
        a set view of the keys contained in this map
      • put

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

        public void putAll​(Map<? extends K,​? extends V> map)
        Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of calling put(K, V) on this map once for each mapping in the passed map. The behavior of this operation is unspecified if the passed map is modified while the operation is in progress.
        Specified by:
        putAll in interface Map<K,​V>
        Parameters:
        map - the Map containing the key/value pairings to put into this Map
      • remove

        public V remove​(Object oKey)
        Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.
        Specified by:
        remove in interface Map<K,​V>
        Parameters:
        oKey - 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. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
      • size

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

        public Collection<V> 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 (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It is not expected to support the add or addAll operations.
        Specified by:
        values in interface Map<K,​V>
        Returns:
        a Collection view of the values contained in this map
      • getAll

        public Map<K,​V> getAll​(Collection<? extends K> colKeys)
        Get all the specified keys, if they are in the Map. For each key that is in the cache, that key and its corresponding value will be placed in the map that is returned by this method. The absence of a key in the returned map indicates that it was not in the cache, which may imply (for caches that can load behind the scenes) that the requested data could not be loaded.
        Parameters:
        colKeys - a collection of keys that may be in the named cache
        Returns:
        a Map of keys to values for the specified keys passed in colKeys
      • iterateKeys

        protected abstract Iterator<K> iterateKeys()
        Create an iterator over the keys in this Map. The Iterator must support remove() if the Map supports removal.
        Returns:
        a new instance of an Iterator over the keys in this Map
      • removeBlind

        protected boolean removeBlind​(Object oKey)
        Removes the mapping for this key from this map if present. This method exists to allow sub-classes to optimize remove functionality for situations in which the original value is not required.
        Parameters:
        oKey - key whose mapping is to be removed from the map
        Returns:
        true iff the Map changed as the result of this operation
      • equals

        public boolean equals​(Object o)
        Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps t1 and t2 represent the same mappings if t1.keySet().equals(t2.keySet()) and for every key k in t1.keySet(), (t1.get(k)==null ? t2.get(k)==null : t1.get(k).equals(t2.get(k))) . This ensures that the equals method works properly across different implementations of the map interface.
        Specified by:
        equals in interface Map<K,​V>
        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. The hash code of a Map is defined to be the sum of the hash codes of each entry in the Map's entrySet() view. This ensures that t1.equals(t2) implies that t1.hashCode()==t2.hashCode() for any two maps t1 and t2, as required by the general contract of Object.hashCode.
        Specified by:
        hashCode in interface Map<K,​V>
        Overrides:
        hashCode in class Object
        Returns:
        the hash code value for this Map
      • toString

        public String toString()
        Returns a string representation of this Map. The string representation consists of a list of key-value mappings in the order returned by the Map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String.valueOf(Object).
        Overrides:
        toString in class Object
        Returns:
        a String representation of this Map
      • instantiateKeySet

        protected Set<K> instantiateKeySet()
        Factory pattern: Create a Set that represents the keys in the Map
        Returns:
        a new instance of Set that represents the keys in the Map
      • instantiateEntrySet

        protected Set<Map.Entry<K,​V>> instantiateEntrySet()
        Factory pattern: Create a Set that represents the entries in the Map.
        Returns:
        a new instance of Set that represents the entries in the Map
      • instantiateValues

        protected Collection<V> instantiateValues()
        Factory pattern: Instantiate the values Collection.
        Returns:
        a new instance of Collection that represents this Map's values