java.util.concurrent
Interface ConcurrentMap<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values
All Superinterfaces:
Map sample code for java.util.Map definition code for java.util.Map <K,V>
All Known Implementing Classes:
ConcurrentHashMap sample code for java.util.concurrent.ConcurrentHashMap definition code for java.util.concurrent.ConcurrentHashMap

public interface ConcurrentMap<K,V>
extends Map sample code for java.util.Map definition code for java.util.Map <K,V>

A Map sample code for java.util.Map definition code for java.util.Map providing additional atomic putIfAbsent, remove, and replace methods.

This interface is a member of the Java Collections Framework.

Since:
1.5

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map sample code for java.util.Map definition code for java.util.Map
Map.Entry sample code for java.util.Map.Entry definition code for java.util.Map.Entry <K,V>
 
Method Summary
 V putIfAbsent sample code for java.util.concurrent.ConcurrentMap.putIfAbsent(K, V) definition code for java.util.concurrent.ConcurrentMap.putIfAbsent(K, V) (K key, V value)
          If the specified key is not already associated with a value, associate it with the given value.
 boolean remove sample code for java.util.concurrent.ConcurrentMap.remove(java.lang.Object, java.lang.Object) definition code for java.util.concurrent.ConcurrentMap.remove(java.lang.Object, java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key, Object sample code for java.lang.Object definition code for java.lang.Object  value)
          Remove entry for key only if currently mapped to given value.
 V replace sample code for java.util.concurrent.ConcurrentMap.replace(K, V) definition code for java.util.concurrent.ConcurrentMap.replace(K, V) (K key, V value)
          Replace entry for key only if currently mapped to some value.
 boolean replace sample code for java.util.concurrent.ConcurrentMap.replace(K, V, V) definition code for java.util.concurrent.ConcurrentMap.replace(K, V, V) (K key, V oldValue, V newValue)
          Replace entry for key only if currently mapped to given value.
 
Methods inherited from interface java.util.Map sample code for java.util.Map definition code for java.util.Map
clear sample code for java.util.Map.clear() definition code for java.util.Map.clear() , containsKey sample code for java.util.Map.containsKey(java.lang.Object) definition code for java.util.Map.containsKey(java.lang.Object) , containsValue sample code for java.util.Map.containsValue(java.lang.Object) definition code for java.util.Map.containsValue(java.lang.Object) , entrySet sample code for java.util.Map.entrySet() definition code for java.util.Map.entrySet() , equals sample code for java.util.Map.equals(java.lang.Object) definition code for java.util.Map.equals(java.lang.Object) , get sample code for java.util.Map.get(java.lang.Object) definition code for java.util.Map.get(java.lang.Object) , hashCode sample code for java.util.Map.hashCode() definition code for java.util.Map.hashCode() , isEmpty sample code for java.util.Map.isEmpty() definition code for java.util.Map.isEmpty() , keySet sample code for java.util.Map.keySet() definition code for java.util.Map.keySet() , put sample code for java.util.Map.put(K, V) definition code for java.util.Map.put(K, V) , putAll sample code for java.util.Map.putAll(java.util.Map) definition code for java.util.Map.putAll(java.util.Map) , remove sample code for java.util.Map.remove(java.lang.Object) definition code for java.util.Map.remove(java.lang.Object) , size sample code for java.util.Map.size() definition code for java.util.Map.size() , values sample code for java.util.Map.values() definition code for java.util.Map.values()
 

Method Detail

putIfAbsent sample code for java.util.concurrent.ConcurrentMap.putIfAbsent(K, V) definition code for java.util.concurrent.ConcurrentMap.putIfAbsent(K, V)

V putIfAbsent(K key,
              V value)
If the specified key is not already associated with a value, associate it with the given value. This is equivalent to
   if (!map.containsKey(key)) 
      return map.put(key, value);
   else
      return map.get(key);
 
Except that the action is performed atomically.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
ClassCastException sample code for java.lang.ClassCastException definition code for java.lang.ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if this map does not permit null keys or values, and the specified key or value is null.

remove sample code for java.util.concurrent.ConcurrentMap.remove(java.lang.Object, java.lang.Object) definition code for java.util.concurrent.ConcurrentMap.remove(java.lang.Object, java.lang.Object)

boolean remove(Object sample code for java.lang.Object definition code for java.lang.Object  key,
               Object sample code for java.lang.Object definition code for java.lang.Object  value)
Remove entry for key only if currently mapped to given value. Acts as
 
  if ((map.containsKey(key) && map.get(key).equals(value)) {
     map.remove(key);
     return true;
 } else return false;
 
except that the action is performed atomically.

Parameters:
key - key with which the specified value is associated.
value - value associated with the specified key.
Returns:
true if the value was removed, false otherwise
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the remove operation is not supported by this map.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if this map does not permit null keys or values, and the specified key or value is null.

replace sample code for java.util.concurrent.ConcurrentMap.replace(K, V, V) definition code for java.util.concurrent.ConcurrentMap.replace(K, V, V)

boolean replace(K key,
                V oldValue,
                V newValue)
Replace entry for key only if currently mapped to given value. Acts as
 
  if ((map.containsKey(key) && map.get(key).equals(oldValue)) {
     map.put(key, newValue);
     return true;
 } else return false;
 
except that the action is performed atomically.

Parameters:
key - key with which the specified value is associated.
oldValue - value expected to be associated with the specified key.
newValue - value to be associated with the specified key.
Returns:
true if the value was replaced
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if this map does not permit null keys or values, and the specified key or value is null.

replace sample code for java.util.concurrent.ConcurrentMap.replace(K, V) definition code for java.util.concurrent.ConcurrentMap.replace(K, V)

V replace(K key,
          V value)
Replace entry for key only if currently mapped to some value. Acts as
 
  if ((map.containsKey(key)) {
     return map.put(key, value);
 } else return null;
 
except that the action is performed atomically.

Parameters:
key - key with which the specified value is associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
UnsupportedOperationException sample code for java.lang.UnsupportedOperationException definition code for java.lang.UnsupportedOperationException - if the put operation is not supported by this map.
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if this map does not permit null keys or values, and the specified key or value is null.