Eclipse Platform
Release 3.7

org.eclipse.osgi.framework.eventmgr
Class CopyOnWriteIdentityMap<K,V>

java.lang.Object
  extended by 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
CopyOnWriteIdentityMap()
          Creates an empty map.
CopyOnWriteIdentityMap(CopyOnWriteIdentityMap<? extends K,? extends V> source)
          Copy constructor.
 
Method Summary
 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.
<L extends K>
void
putAll(L[] keys)
          Add all the keys from the specified array to this map with the value null.
 void putAll(Map<? extends K,? extends V> source)
          Add all the entries from the specified map to this map.
 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
equals, hashCode
 

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 interface Map<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:
IllegalArgumentException - 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.

Specified by:
putAll in interface Map<K,V>
Parameters:
source - The map whose entries are to be added 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 value null.

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 interface Map<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:
IllegalArgumentException - If key is null.

clear

public void clear()
Remove all entries from the map.

Specified by:
clear in interface Map<K,V>

isEmpty

public boolean isEmpty()
Is the map empty?

Specified by:
isEmpty in interface Map<K,V>
Returns:
true if the list is empty.

size

public int size()
Return the number of entries in the map.

Specified by:
size in interface Map<K,V>
Returns:
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 interface Map<K,V>
Parameters:
key - The key object.
Returns:
The value object for the specified key.
Throws:
IllegalArgumentException - 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 interface Map<K,V>
Parameters:
key - The key object.
Returns:
true if the specified key is in the map.
Throws:
IllegalArgumentException - 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 interface Map<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.

Specified by:
entrySet in interface Map<K,V>
Returns:
A Set of Map.Entry for each entry in this map. The entries returned by the set cannot be modified.

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.

Specified by:
keySet in interface Map<K,V>
Returns:
A Set of the key objects in this map

values

public Collection<V> values()
Returns a snapshot of the values in this map. Changes to the returned set or this map will not affect each other.

Specified by:
values in interface Map<K,V>
Returns:
A Collection of the value objects in this map.

Eclipse Platform
Release 3.7

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2011. All rights reserved.