Class CopyOnWriteIdentityMap<K,V>
- java.lang.Object
-
- org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public class CopyOnWriteIdentityMap<K,V> extends Object implements Map<K,V>
A copy-on-write identity map. Write operations result in copying the underlying data so that simultaneous read operations are not affected. This allows for safe, unsynchronized traversal.Note: This class uses identity for key and value comparison, not equals.
- Since:
- 3.5
-
-
Constructor Summary
Constructors Constructor Description CopyOnWriteIdentityMap()
Creates an empty map.CopyOnWriteIdentityMap(CopyOnWriteIdentityMap<? extends K,? extends V> source)
Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Remove all entries from the map.boolean
containsKey(Object key)
Check if the map contains the specified key.boolean
containsValue(Object value)
Check if the map contains the specified value.Set<Map.Entry<K,V>>
entrySet()
Returns a snapshot of the entries in this map.V
get(Object key)
Return the value object for the specified key.boolean
isEmpty()
Is the map empty?Set<K>
keySet()
Returns a snapshot of the keys in this map.V
put(K key, V value)
Add a key, value pair to the map.void
putAll(Map<? extends K,? extends V> source)
Add all the entries from the specified map to this map.<L extends K>
voidputAll(L[] keys)
Add all the keys from the specified array to this map with the valuenull
.V
remove(Object key)
Remove a key from the map and returns the value associated with the key.int
size()
Return the number of entries in the map.Collection<V>
values()
Returns a snapshot of the values in this map.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
CopyOnWriteIdentityMap
public CopyOnWriteIdentityMap()
Creates an empty map.
-
CopyOnWriteIdentityMap
public CopyOnWriteIdentityMap(CopyOnWriteIdentityMap<? extends K,? extends V> source)
Copy constructor.- Parameters:
source
- The CopyOnWriteMap to copy.
-
-
Method Detail
-
put
public V put(K key, V value)
Add a key, value pair to the map. If the key object is already in the map, then its value is replaced with the new value. Keys are compared using identity.- Specified by:
put
in interfaceMap<K,V>
- Parameters:
key
- The key object to be added to the list.value
- The value object to be associated with the key. This may be null.- Returns:
null
if the specified key was newly added to the map. Otherwise the previous value of the key.- Throws:
NullPointerException
- If key is null.
-
putAll
public void putAll(Map<? extends K,? extends V> source)
Add all the entries from the specified map to this map.
-
putAll
public <L extends K> void putAll(L[] keys)
Add all the keys from the specified array to this map with the valuenull
.- Parameters:
keys
- The array of keys to be added to this map.
-
remove
public V remove(Object key)
Remove a key from the map and returns the value associated with the key. Key objects are compared using identity.- Specified by:
remove
in interfaceMap<K,V>
- Parameters:
key
- The key object to be removed from the map.- Returns:
null
if the key was not in the list. Otherwise, the value associated with the key.- Throws:
NullPointerException
- If key is null.
-
clear
public void clear()
Remove all entries from the map.
-
isEmpty
public boolean isEmpty()
Is the map empty?
-
size
public int size()
Return the number of entries in the map.
-
get
public V get(Object key)
Return the value object for the specified key. Keys are compared using identity.- Specified by:
get
in interfaceMap<K,V>
- Parameters:
key
- The key object.- Returns:
- The value object for the specified key.
- Throws:
NullPointerException
- If key is null.
-
containsKey
public boolean containsKey(Object key)
Check if the map contains the specified key. Keys are compared using identity.- Specified by:
containsKey
in interfaceMap<K,V>
- Parameters:
key
- The key object.- Returns:
true
if the specified key is in the map.- Throws:
NullPointerException
- If key is null.
-
containsValue
public boolean containsValue(Object value)
Check if the map contains the specified value. Values are compared using identity.- Specified by:
containsValue
in interfaceMap<K,V>
- Parameters:
value
- The value object.- Returns:
true
if the specified value is in the map.
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
Returns a snapshot of the entries in this map. Changes to the returned set or this map will not affect each other.
-
keySet
public Set<K> keySet()
Returns a snapshot of the keys in this map. Changes to the returned set or this map will not affect each other.
-
-