Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

java.util
Class Collections.SynchronizedSortedMap  view Collections.SynchronizedSortedMap download Collections.SynchronizedSortedMap.java

java.lang.Object
  extended byjava.util.Collections.SynchronizedMap
      extended byjava.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

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:
comparator in interface SortedMap

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.

Specified by:
firstKey in interface SortedMap

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 to subMap(firstKey(), toKey). The submap retains the thread-safe status of this map.

Specified by:
headMap in interface SortedMap

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.

Specified by:
lastKey in interface SortedMap

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.

Specified by:
subMap in interface SortedMap

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.

Specified by:
tailMap in interface SortedMap

clear

public void clear()
Clears all the entries from the underlying map. A lock is obtained on the mutex before the map is cleared.

Specified by:
clear in interface Map

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if the underlying map contains a entry for the given key. A lock is obtained on the mutex before the map is queried.

Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if the underlying map contains at least one entry with the given value. In other words, returns true if 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:
containsValue in interface Map

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, and clear. Element addition, via add or addAll, is not supported via this set.

Specified by:
entrySet in interface Map

equals

public 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. A lock is obtained on the mutex before the objects are compared.

Specified by:
equals in interface Map

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, containsKey should be used. A lock is obtained on the mutex before the value is retrieved from the underlying map.

Specified by:
get in interface 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.

Specified by:
hashCode in interface Map

isEmpty

public boolean isEmpty()
Returns true if the underlying map contains no entries. A lock is obtained on the mutex before the map is examined.

Specified by:
isEmpty in interface Map

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, and clear. Element addition, via add or addAll, is not supported via this set. A lock is obtained on the mutex before the set is created.

Specified by:
keySet in interface Map

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 null values, a null return does not always imply that the mapping was created. A lock is obtained on the mutex before the modification is made.

Specified by:
put in interface Map

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.

Specified by:
putAll in interface Map

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.

Specified by:
remove in interface Map

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_VALUE return Integer.MAX_VALUE instead.

Specified by:
size in interface Map

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, and clear. Element addition, via add or addAll, is not supported via this collection. A lock is obtained on the mutex before the collection is created.

Specified by:
values in interface Map