Class CmsNullIgnoringConcurrentMap<K,V>
- java.lang.Object
-
- org.opencms.util.CmsNullIgnoringConcurrentMap<K,V>
-
- Type Parameters:
K
- the key typeV
- 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!
-
-
Constructor Summary
Constructors Constructor Description CmsNullIgnoringConcurrentMap()
Creates a new instance.CmsNullIgnoringConcurrentMap(java.util.Map<K,V> otherMap)
Creates a new instance from another map.
-
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()
-
-
-
Constructor Detail
-
CmsNullIgnoringConcurrentMap
public CmsNullIgnoringConcurrentMap()
Creates a new instance.
-
CmsNullIgnoringConcurrentMap
public CmsNullIgnoringConcurrentMap(java.util.Map<K,V> otherMap)
Creates a new instance from another map.- Parameters:
otherMap
- the other map
-
-
Method Detail
-
clear
public void clear()
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
isEmpty
public boolean isEmpty()
-
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,
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
-