Class CopyOnWriteIdentityMap<K,V>
java.lang.Object
org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap<K,V>
- All Implemented Interfaces:
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
ConstructorDescriptionCreates an empty map.CopyOnWriteIdentityMap
(CopyOnWriteIdentityMap<? extends K, ? extends V> source) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.entrySet()
Returns a snapshot of the entries in this map.Return the value object for the specified key.boolean
isEmpty()
Is the map empty?keySet()
Returns a snapshot of the keys in this map.Add a key, value pair to the map.void
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
.Remove a key from the map and returns the value associated with the key.int
size()
Return the number of entries in the map.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 Details
-
CopyOnWriteIdentityMap
public CopyOnWriteIdentityMap()Creates an empty map. -
CopyOnWriteIdentityMap
Copy constructor.- Parameters:
source
- The CopyOnWriteMap to copy.
-
-
Method Details
-
put
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
Add all the entries from the specified map to this map. -
putAll
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
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
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
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
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
Returns a snapshot of the entries in this map. Changes to the returned set or this map will not affect each other. -
keySet
Returns a snapshot of the keys in this map. Changes to the returned set or this map will not affect each other. -
values
Returns a snapshot of the values in this map. Changes to the returned set or this map will not affect each other.
-