Class CmsNullIgnoringConcurrentMap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.util.Map<K,​V>

    public class CmsNullIgnoringConcurrentMap<K,​V>
    extends java.lang.Object
    implements java.util.Map<K,​V>
    Wrapper around ConcurrentHashMap which allows null values.

    The point of this is the following: Often, HashMaps in older code are accessed concurrently by multiple threads. When these threads modify the map concurrently, an infinite loop may occur due to the standard HashMap implementation. But sometimes we can't just replace the HashMap with a ConcurrentHashMap because that class doesn't allow null values and we don't always know for certain whether null values are used or not. But if we don't care about the distinction about null values and entries not being present, we can use this map class which will just log an error and remove the entry when trying to set a null value. NOTE: Currently this wrapper does *not* check value modifications made to entries returned by entrySet!

    • 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>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      boolean containsKey​(java.lang.Object key)  
      boolean containsValue​(java.lang.Object value)  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      boolean equals​(java.lang.Object o)  
      V get​(java.lang.Object key)  
      int hashCode()  
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      V put​(K key, V value)
      Sets the given map value for the given key, unless either of them is null.
      void putAll​(java.util.Map<? extends K,​? extends V> m)  
      V remove​(java.lang.Object key)  
      int size()  
      java.lang.String toString()  
      java.util.Collection<V> values()  
      • 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
    • Method Detail

      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<K,​V>
        See Also:
        Map.clear()
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        See Also:
        Map.containsKey(java.lang.Object)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        See Also:
        Map.containsValue(java.lang.Object)
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        See Also:
        Map.entrySet()
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<K,​V>
        Overrides:
        equals in class java.lang.Object
        See Also:
        Map.equals(java.lang.Object)
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        See Also:
        Map.get(java.lang.Object)
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<K,​V>
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Map.hashCode()
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
        See Also:
        Map.isEmpty()
      • keySet

        public java.util.Set<KkeySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
        See Also:
        Map.keySet()
      • put

        public V put​(K key,
                     V value)
        Sets the given map value for the given key, unless either of them is null.

        If the value is null,

        Specified by:
        put in interface java.util.Map<K,​V>
        Parameters:
        key - the key
        value - the value
        Returns:
        the old value
        See Also:
        Map.put(java.lang.Object, java.lang.Object)
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> m)
        Specified by:
        putAll in interface java.util.Map<K,​V>
        See Also:
        Map.putAll(java.util.Map)
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
        See Also:
        Map.remove(java.lang.Object)
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
        See Also:
        Map.size()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()
      • values

        public java.util.Collection<Vvalues()
        Specified by:
        values in interface java.util.Map<K,​V>
        See Also:
        Map.values()