org.apache.pivot.collections.concurrent
Class SynchronizedMap<K,V>

java.lang.Object
  extended by org.apache.pivot.collections.concurrent.SynchronizedCollection<K>
      extended by org.apache.pivot.collections.concurrent.SynchronizedMap<K,V>
All Implemented Interfaces:
Iterable<K>, Collection<K>, Dictionary<K,V>, Map<K,V>

public class SynchronizedMap<K,V>
extends SynchronizedCollection<K>
implements Map<K,V>

Synchronized implementation of the Map interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Map
Map.MapListenerList<K,V>
 
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
 
Field Summary
 
Fields inherited from class org.apache.pivot.collections.concurrent.SynchronizedCollection
collection
 
Constructor Summary
SynchronizedMap(Map<K,V> map)
           
 
Method Summary
 boolean containsKey(K key)
          Tests the existence of a key in the dictionary.
 V get(K key)
          Retrieves the value for the given key.
 int getCount()
          Returns the number of entries in the map.
 ListenerList<MapListener<K,V>> getMapListeners()
          Returns the map listener collection.
 boolean isEmpty()
          Tests the emptiness of the dictionary.
 V put(K key, V value)
          Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.
 V remove(K key)
          Removes a key/value pair from the map.
 
Methods inherited from class org.apache.pivot.collections.concurrent.SynchronizedCollection
clear, getComparator, iterator, setComparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.pivot.collections.Map
clear, setComparator
 
Methods inherited from interface org.apache.pivot.collections.Collection
getComparator
 
Methods inherited from interface java.lang.Iterable
iterator
 

Constructor Detail

SynchronizedMap

public SynchronizedMap(Map<K,V> map)
Method Detail

get

public V get(K key)
Description copied from interface: Dictionary
Retrieves the value for the given key.

Specified by:
get in interface Dictionary<K,V>
Parameters:
key - The key whose value is to be returned.
Returns:
The value corresponding to key, or null if the key does not exist. Will also return null if the key refers to a null value. Use containsKey() to distinguish between these two cases.

put

public V put(K key,
             V value)
Description copied from interface: Map
Sets the value of the given key, creating a new entry or replacing the existing value, and firing a corresponding event.

Specified by:
put in interface Dictionary<K,V>
Specified by:
put in interface Map<K,V>
Parameters:
key - The key whose value is to be set.
value - The value to be associated with the given key.
Returns:
The value previously associated with the key.
See Also:
MapListener.valueAdded(Map, Object), MapListener.valueUpdated(Map, Object, Object)

remove

public V remove(K key)
Description copied from interface: Dictionary
Removes a key/value pair from the map.

Specified by:
remove in interface Dictionary<K,V>
Specified by:
remove in interface Map<K,V>
Parameters:
key - The key whose mapping is to be removed.
Returns:
The value that was removed.
See Also:
MapListener.valueRemoved(Map, Object, Object)

isEmpty

public boolean isEmpty()
Description copied from interface: Dictionary
Tests the emptiness of the dictionary.

Specified by:
isEmpty in interface Dictionary<K,V>
Returns:
true if the dictionary contains no keys; false, otherwise.

containsKey

public boolean containsKey(K key)
Description copied from interface: Dictionary
Tests the existence of a key in the dictionary.

Specified by:
containsKey in interface Dictionary<K,V>
Parameters:
key - The key whose presence in the dictionary is to be tested.
Returns:
true if the key exists in the dictionary; false, otherwise.

getCount

public int getCount()
Description copied from interface: Map
Returns the number of entries in the map.

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

getMapListeners

public ListenerList<MapListener<K,V>> getMapListeners()
Description copied from interface: Map
Returns the map listener collection.

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