|
|||||||||
| 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.SynchronizedSortedMap

java.lang.Objectjava.util.Collections.SynchronizedMap
java.util.Collections.SynchronizedSortedMap
- All Implemented Interfaces:
- Map, java.io.Serializable, SortedMap
- Enclosing class:
- Collections
- private static final class Collections.SynchronizedSortedMap
- extends Collections.SynchronizedMap
- implements SortedMap
- extends Collections.SynchronizedMap
The implementation of Collections.synchronizedSortedMap(SortedMap) 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 | |
(package private) java.lang.Object |
mutex
The object to synchronize on. |
private static long |
serialVersionUID
Compatible with JDK 1.4. |
private SortedMap |
sm
The wrapped map; stored both here and in the superclass to avoid excessive casting. |
| Constructor Summary | |
(package private) |
Collections.SynchronizedSortedMap(java.lang.Object sync,
SortedMap sm)
Called only by trusted code to specify the mutex as well as the map. |
(package private) |
Collections.SynchronizedSortedMap(SortedMap sm)
Wrap a given map. |
| Method Summary | |
void |
clear()
Clears all the entries from the underlying map. |
Comparator |
comparator()
Returns the comparator used in sorting the underlying map, or null if it is the keys' natural ordering. |
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 |
firstKey()
Returns the first, lowest sorted, key from 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. |
SortedMap |
headMap(java.lang.Object toKey)
Returns a submap containing the keys from the first key (as returned by firstKey()) to
the key before that specified. |
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 |
lastKey()
Returns the last, highest sorted, key from 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. |
SortedMap |
subMap(java.lang.Object fromKey,
java.lang.Object toKey)
Returns a submap containing the keys from fromKey to the key before toKey. |
SortedMap |
tailMap(java.lang.Object fromKey)
Returns a submap containing all the keys from fromKey onwards. |
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 |
| Methods inherited from interface java.util.Map |
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Field Detail |
serialVersionUID
private static final long serialVersionUID
- Compatible with JDK 1.4.
- See Also:
- Constant Field Values
sm
private final SortedMap sm
- The wrapped map; stored both here and in the superclass to avoid
excessive casting.
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.
| Constructor Detail |
Collections.SynchronizedSortedMap
Collections.SynchronizedSortedMap(SortedMap sm)
- Wrap a given map.
Collections.SynchronizedSortedMap
Collections.SynchronizedSortedMap(java.lang.Object sync, SortedMap sm)
- Called only by trusted code to specify the mutex as well as the map.
| Method Detail |
comparator
public Comparator comparator()
- Returns the comparator used in sorting the underlying map, or null if
it is the keys' natural ordering. A lock is obtained on the mutex
before the comparator is retrieved.
- Specified by:
comparatorin interfaceSortedMap
firstKey
public java.lang.Object firstKey()
- Returns the first, lowest sorted, key from the underlying map.
A lock is obtained on the mutex before the map is accessed.
headMap
public SortedMap headMap(java.lang.Object toKey)
- Returns a submap containing the keys from the first
key (as returned by
firstKey()) to the key before that specified. The submap supports all operations supported by the underlying map and all actions taking place on the submap are also reflected in the underlying map. A lock is obtained on the mutex prior to submap creation. This operation is equivalent tosubMap(firstKey(), toKey). The submap retains the thread-safe status of this map.
lastKey
public java.lang.Object lastKey()
- Returns the last, highest sorted, key from the underlying map.
A lock is obtained on the mutex before the map is accessed.
subMap
public SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)
- Returns a submap containing the keys from fromKey to
the key before toKey. The submap supports all
operations supported by the underlying map and all actions
taking place on the submap are also reflected in the underlying
map. A lock is obtained on the mutex prior to submap creation.
The submap retains the thread-safe status of this map.
tailMap
public SortedMap tailMap(java.lang.Object fromKey)
- Returns a submap containing all the keys from fromKey onwards.
The submap supports all operations supported by the underlying
map and all actions taking place on the submap are also reflected
in the underlying map. A lock is obtained on the mutex prior to
submap creation. The submap retains the thread-safe status of
this map.
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