|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.util
Class Collections.SynchronizedMap

java.lang.Objectjava.util.Collections.SynchronizedMap
- All Implemented Interfaces:
- Map, java.io.Serializable
- Direct Known Subclasses:
- Collections.SynchronizedSortedMap
- Enclosing class:
- Collections
- private static class Collections.SynchronizedMap
- extends java.lang.Object
- implements Map, java.io.Serializable
- extends java.lang.Object
The implementation of Collections.synchronizedMap(Map) 55 . This
class name is required for compatibility with Sun's JDK serializability.
| Nested Class Summary |
| Nested classes inherited from class java.util.Map |
Map.Entry |
| Field Summary | |
private Set |
entries
Cache the entry set. |
private Set |
keys
Cache the key set. |
private Map |
m
The wrapped map. |
(package private) java.lang.Object |
mutex
The object to synchronize on. |
private static long |
serialVersionUID
Compatible with JDK 1.4. |
private Collection |
values
Cache the value collection. |
| Constructor Summary | |
(package private) |
Collections.SynchronizedMap(Map m)
Wrap a given map. |
(package private) |
Collections.SynchronizedMap(java.lang.Object sync,
Map m)
Called only by trusted code to specify the mutex as well as the map. |
| Method Summary | |
void |
clear()
Clears all the entries from the underlying map. |
boolean |
containsKey(java.lang.Object key)
Returns true if the underlying map contains a entry for the given key. |
boolean |
containsValue(java.lang.Object value)
Returns true if the underlying map contains at least one entry with the
given value. |
Set |
entrySet()
Returns a set view of the mappings in this Map. |
boolean |
equals(java.lang.Object o)
Returns true if the object, o, is also an instance
of Map and contains an equivalent
entry set to that of the underlying map. |
java.lang.Object |
get(java.lang.Object key)
Returns the value associated with the given key, or null if no such mapping exists. |
int |
hashCode()
Calculates the hash code of the underlying map as the sum of the hash codes of all entries. |
boolean |
isEmpty()
Returns true if the underlying map contains no entries. |
Set |
keySet()
Returns a thread-safe set view of the keys in the underlying map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Associates the given key to the given value (optional operation). |
void |
putAll(Map map)
Copies all entries of the given map to the underlying one (optional operation). |
java.lang.Object |
remove(java.lang.Object o)
Removes the mapping for the key, o, if present (optional operation). |
int |
size()
Retrieves the size of the underlying map. |
java.lang.String |
toString()
Returns a textual representation of the underlying map. |
Collection |
values()
Returns a synchronized collection view of the values in the underlying map. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
serialVersionUID
private static final long serialVersionUID
- Compatible with JDK 1.4.
- See Also:
- Constant Field Values
m
private final Map m
- The wrapped map.
mutex
final java.lang.Object mutex
- The object to synchronize on. When an instance is created via public
methods, it will be this; but other uses like
SynchronizedSortedMap.subMap() must specify another mutex. Package
visible for use by subclass.
entries
private transient Set entries
- Cache the entry set.
keys
private transient Set keys
- Cache the key set.
values
private transient Collection values
- Cache the value collection.
| Constructor Detail |
Collections.SynchronizedMap
Collections.SynchronizedMap(Map m)
- Wrap a given map.
Collections.SynchronizedMap
Collections.SynchronizedMap(java.lang.Object sync, Map m)
- Called only by trusted code to specify the mutex as well as the map.
| Method Detail |
clear
public void clear()
- Clears all the entries from the underlying map. A lock is obtained
on the mutex before the map is cleared.
containsKey
public boolean containsKey(java.lang.Object key)
- Returns
trueif the underlying map contains a entry for the given key. A lock is obtained on the mutex before the map is queried.- Specified by:
containsKeyin interfaceMap
containsValue
public boolean containsValue(java.lang.Object value)
- Returns
trueif the underlying map contains at least one entry with the given value. In other words, returnstrueif a value v exists where(value == null ? v == null : value.equals(v)). This usually requires linear time. A lock is obtained on the mutex before the map is queried.- Specified by:
containsValuein interfaceMap
entrySet
public Set entrySet()
- Description copied from interface:
Map - Returns a set view of the mappings in this Map. Each element in the
set is a Map.Entry. The set is backed by the map, so that changes in
one show up in the other. Modifications made while an iterator is
in progress cause undefined behavior. If the set supports removal,
these methods remove the underlying mapping from the map:
Iterator.remove,Set.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this set.
equals
public boolean equals(java.lang.Object o)
- Returns
trueif the object, o, is also an instance ofMapand contains an equivalent entry set to that of the underlying map. A lock is obtained on the mutex before the objects are compared.
get
public java.lang.Object get(java.lang.Object key)
- Returns the value associated with the given key, or null
if no such mapping exists. An ambiguity exists with maps
that accept null values as a return value of null could
be due to a non-existent mapping or simply a null value
for that key. To resolve this,
containsKeyshould be used. A lock is obtained on the mutex before the value is retrieved from the underlying map.
hashCode
public int hashCode()
- Calculates the hash code of the underlying map as the
sum of the hash codes of all entries. A lock is obtained
on the mutex before the hash code is computed.
isEmpty
public boolean isEmpty()
- Returns
trueif the underlying map contains no entries. A lock is obtained on the mutex before the map is examined.
keySet
public Set keySet()
- Returns a thread-safe set view of the keys in the underlying map. The
set is backed by the map, so that changes in one show up in the other.
Modifications made while an iterator is in progress cause undefined
behavior. If the set supports removal, these methods remove the
underlying mapping from the map:
Iterator.remove,Set.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this set. A lock is obtained on the mutex before the set is created.
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
- Associates the given key to the given value (optional operation). If the
underlying map already contains the key, its value is replaced. Be aware
that in a map that permits
nullvalues, a null return does not always imply that the mapping was created. A lock is obtained on the mutex before the modification is made.
putAll
public void putAll(Map map)
- Copies all entries of the given map to the underlying one (optional
operation). If the map already contains a key, its value is replaced.
A lock is obtained on the mutex before the operation proceeds.
remove
public java.lang.Object remove(java.lang.Object o)
- Removes the mapping for the key, o, if present (optional operation). If
the key is not present, this returns null. Note that maps which permit
null values may also return null if the key was removed. A prior
containsKey()check is required to avoid this ambiguity. Before the mapping is removed, a lock is obtained on the mutex.
size
public int size()
- Retrieves the size of the underlying map. A lock
is obtained on the mutex before access takes place.
Maps with a size greater than
Integer.MAX_VALUEreturnInteger.MAX_VALUEinstead.
toString
public java.lang.String toString()
- Returns a textual representation of the underlying
map. A lock is obtained on the mutex before the map
is accessed.
values
public Collection values()
- Returns a synchronized collection view of the values in the underlying
map. The collection is backed by the map, so that changes in one show up in
the other. Modifications made while an iterator is in progress cause
undefined behavior. If the collection supports removal, these methods
remove the underlying mapping from the map:
Iterator.remove,Collection.remove,removeAll,retainAll, andclear. Element addition, viaaddoraddAll, is not supported via this collection. A lock is obtained on the mutex before the collection is created.
|
|||||||||
| Home >> All >> java >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.util.Collections.SynchronizedMap