Class ConcurrentWeakHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- de.hybris.platform.util.collections.ConcurrentWeakHashMap<K,V>
-
- All Implemented Interfaces:
java.util.concurrent.ConcurrentMap<K,V>,java.util.Map<K,V>
public class ConcurrentWeakHashMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.concurrent.ConcurrentMap<K,V>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceConcurrentWeakHashMap.LazyValueCreator<K,V>
-
Constructor Summary
Constructors Constructor Description ConcurrentWeakHashMap()Constructs a new, empty HashMap with a default capacity and load factor.ConcurrentWeakHashMap(int initialCapacity)Constructs a new, empty HashMap with the specified initial capacity and default load factor.ConcurrentWeakHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)Constructs a new, empty HashMap with the specified initial capacity and the specified load factor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all mappings from all segment, leaving the ConcurrentWeakHashMap empty.booleancontainsKey(java.lang.Object key)java.util.Set<java.util.Map.Entry<K,V>>entrySet()Vget(java.lang.Object key)Returns the value to which this HashMap maps the specified key.VgetOrPut(K key, ConcurrentWeakHashMap.LazyValueCreator<K,V> valueCreator)Checks if a value is already mapped and returns that one.java.util.Set<K>keySet()Vput(K key, V value)VputIfAbsent(K key, V value)Vremove(java.lang.Object key)booleanremove(java.lang.Object key, java.lang.Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)intsize()This function is not accurate under concurrent environment.-
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
ConcurrentWeakHashMap
public ConcurrentWeakHashMap(int initialCapacity, float loadFactor, int concurrencyLevel)Constructs a new, empty HashMap with the specified initial capacity and the specified load factor.- Parameters:
initialCapacity- the initial capacity of the HashMap.loadFactor- a number between 0.0 and 1.0.concurrencyLevel- the estimated number of concurrently updating threads. The implementation performs internal sizing to try to accommodate this many threads.- Throws:
java.lang.IllegalArgumentException- if neither keys nor values use hard references, if the initial capacity is less than or equal to zero, or if the load factor is less than or equal to zero
-
ConcurrentWeakHashMap
public ConcurrentWeakHashMap(int initialCapacity)
Constructs a new, empty HashMap with the specified initial capacity and default load factor.- Parameters:
initialCapacity- the initial capacity of the HashMap.
-
ConcurrentWeakHashMap
public ConcurrentWeakHashMap()
Constructs a new, empty HashMap with a default capacity and load factor.
-
-
Method Detail
-
get
public V get(java.lang.Object key)
Returns the value to which this HashMap maps the specified key. Returns null if the HashMap contains no mapping for this key.
-
remove
public V remove(java.lang.Object key)
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
size
public int size()
This function is not accurate under concurrent environment.
-
containsKey
public boolean containsKey(java.lang.Object key)
-
clear
public void clear()
Clear all mappings from all segment, leaving the ConcurrentWeakHashMap empty.
-
keySet
public java.util.Set<K> keySet()
-
getOrPut
public V getOrPut(K key, ConcurrentWeakHashMap.LazyValueCreator<K,V> valueCreator)
Checks if a value is already mapped and returns that one. If it does not find that key a new value is lazily created and returned as result.Please note that the returned value is always the one which stays inside the map after that call, which is totally different to traditional methods like put or putIfAbsent!
-
-