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

Quick Search    Search Deep

java.util
Class Collections.SynchronizedSortedSet  view Collections.SynchronizedSortedSet download Collections.SynchronizedSortedSet.java

java.lang.Object
  extended byjava.util.Collections.SynchronizedCollection
      extended byjava.util.Collections.SynchronizedSet
          extended byjava.util.Collections.SynchronizedSortedSet
All Implemented Interfaces:
Collection, java.lang.Iterable, java.io.Serializable, Set, SortedSet
Enclosing class:
Collections

private static final class Collections.SynchronizedSortedSet
extends Collections.SynchronizedSet
implements SortedSet

The implementation of Collections.synchronizedSortedSet(SortedSet) 55 . This class name is required for compatibility with Sun's JDK serializability.


Field Summary
(package private)  Collection c
          The wrapped collection.
(package private)  java.lang.Object mutex
          The object to synchronize on.
private static long serialVersionUID
          Compatible with JDK 1.4.
private  SortedSet ss
          The wrapped set; stored both here and in the superclass to avoid excessive casting.
 
Constructor Summary
(package private) Collections.SynchronizedSortedSet(java.lang.Object sync, SortedSet ss)
          Called only by trusted code to specify the mutex as well as the set.
(package private) Collections.SynchronizedSortedSet(SortedSet ss)
          Wrap a given set.
 
Method Summary
 boolean add(java.lang.Object o)
          Adds the object to the underlying collection, first obtaining a lock on the mutex.
 boolean addAll(Collection col)
          Adds the objects in col to the underlying collection, first obtaining a lock on the mutex.
 void clear()
          Removes all objects from the underlying collection, first obtaining a lock on the mutex.
 Comparator comparator()
          Returns the comparator used in sorting the underlying set, or null if it is the elements' natural ordering.
 boolean contains(java.lang.Object o)
          Checks for the existence of o within the underlying collection, first obtaining a lock on the mutex.
 boolean containsAll(Collection c1)
          Checks for the existence of each object in cl within the underlying collection, first obtaining a lock on the mutex.
 boolean equals(java.lang.Object o)
          Returns true if the object, o, is a Set of the same size as the underlying set, and contains each element, e, which occurs in the underlying set.
 java.lang.Object first()
          Returns the first, lowest sorted, element from the underlying set.
 int hashCode()
          Computes the hash code for the underlying set as the sum of the hash code of all elements within the set.
 SortedSet headSet(java.lang.Object toElement)
          Returns a subset containing the element from the first element (as returned by first()) to the element before that specified.
 boolean isEmpty()
          Returns true if there are no objects in the underlying collection.
 Iterator iterator()
          Returns a synchronized iterator wrapper around the underlying collection's iterator.
 java.lang.Object last()
          Returns the last, highest sorted, element from the underlying set.
 boolean remove(java.lang.Object o)
          Removes the specified object from the underlying collection, first obtaining a lock on the mutex.
 boolean removeAll(Collection col)
          Removes all elements, e, of the underlying collection for which col.contains(e) returns true.
 boolean retainAll(Collection col)
          Retains all elements, e, of the underlying collection for which col.contains(e) returns true.
 int size()
          Retrieves the size of the underlying collection.
 SortedSet subSet(java.lang.Object fromElement, java.lang.Object toElement)
          Returns a subset containing the elements from fromElement to the element before toElement.
 SortedSet tailSet(java.lang.Object fromElement)
          Returns a subset containing all the elements from fromElement onwards.
 java.lang.Object[] toArray()
          Returns an array containing each object within the underlying collection.
 java.lang.Object[] toArray(java.lang.Object[] a)
          Copies the elements in the underlying collection to the supplied array.
 java.lang.String toString()
          Returns a string representation of the underlying collection.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Compatible with JDK 1.4.

See Also:
Constant Field Values

ss

private final SortedSet ss
The wrapped set; stored both here and in the superclass to avoid excessive casting.


c

final Collection c
The wrapped collection. Package visible for use by subclasses.


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 SynchronizedMap.values() must specify another mutex. Package visible for use by subclasses.

Constructor Detail

Collections.SynchronizedSortedSet

Collections.SynchronizedSortedSet(SortedSet ss)
Wrap a given set.


Collections.SynchronizedSortedSet

Collections.SynchronizedSortedSet(java.lang.Object sync,
                                  SortedSet ss)
Called only by trusted code to specify the mutex as well as the set.

Method Detail

comparator

public Comparator comparator()
Returns the comparator used in sorting the underlying set, or null if it is the elements' natural ordering. A lock is obtained on the mutex before the comparator is retrieved.

Specified by:
comparator in interface SortedSet

first

public java.lang.Object first()
Returns the first, lowest sorted, element from the underlying set. A lock is obtained on the mutex before the set is accessed.

Specified by:
first in interface SortedSet

headSet

public SortedSet headSet(java.lang.Object toElement)
Returns a subset containing the element from the first element (as returned by first()) to the element before that specified. The subset supports all operations supported by the underlying set and all actions taking place on the subset are also reflected in the underlying set. A lock is obtained on the mutex prior to subset creation. This operation is equivalent to subSet(first(), toElement). The subset retains the thread-safe status of this set.

Specified by:
headSet in interface SortedSet

last

public java.lang.Object last()
Returns the last, highest sorted, element from the underlying set. A lock is obtained on the mutex before the set is accessed.

Specified by:
last in interface SortedSet

subSet

public SortedSet subSet(java.lang.Object fromElement,
                        java.lang.Object toElement)
Returns a subset containing the elements from fromElement to the element before toElement. The subset supports all operations supported by the underlying set and all actions taking place on the subset are also reflected in the underlying set. A lock is obtained on the mutex prior to subset creation. The subset retains the thread-safe status of this set.

Specified by:
subSet in interface SortedSet

tailSet

public SortedSet tailSet(java.lang.Object fromElement)
Returns a subset containing all the elements from fromElement onwards. The subset supports all operations supported by the underlying set and all actions taking place on the subset are also reflected in the underlying set. A lock is obtained on the mutex prior to subset creation. The subset retains the thread-safe status of this set.

Specified by:
tailSet in interface SortedSet

equals

public boolean equals(java.lang.Object o)
Returns true if the object, o, is a Set of the same size as the underlying set, and contains each element, e, which occurs in the underlying set. A lock is obtained on the mutex before the comparison takes place.

Specified by:
equals in interface Set

hashCode

public int hashCode()
Computes the hash code for the underlying set as the sum of the hash code of all elements within the set. A lock is obtained on the mutex before the computation occurs.

Specified by:
hashCode in interface Set

add

public boolean add(java.lang.Object o)
Adds the object to the underlying collection, first obtaining a lock on the mutex.

Specified by:
add in interface Collection

addAll

public boolean addAll(Collection col)
Adds the objects in col to the underlying collection, first obtaining a lock on the mutex.

Specified by:
addAll in interface Collection

clear

public void clear()
Removes all objects from the underlying collection, first obtaining a lock on the mutex.

Specified by:
clear in interface Collection

contains

public boolean contains(java.lang.Object o)
Checks for the existence of o within the underlying collection, first obtaining a lock on the mutex.

Specified by:
contains in interface Collection

containsAll

public boolean containsAll(Collection c1)
Checks for the existence of each object in cl within the underlying collection, first obtaining a lock on the mutex.

Specified by:
containsAll in interface Collection

isEmpty

public boolean isEmpty()
Returns true if there are no objects in the underlying collection. A lock on the mutex is obtained before the check is performed.

Specified by:
isEmpty in interface Collection

iterator

public Iterator iterator()
Returns a synchronized iterator wrapper around the underlying collection's iterator. A lock on the mutex is obtained before retrieving the collection's iterator.

Specified by:
iterator in interface Collection

remove

public boolean remove(java.lang.Object o)
Removes the specified object from the underlying collection, first obtaining a lock on the mutex.

Specified by:
remove in interface Collection

removeAll

public boolean removeAll(Collection col)
Removes all elements, e, of the underlying collection for which col.contains(e) returns true. A lock on the mutex is obtained before the operation proceeds.

Specified by:
removeAll in interface Collection

retainAll

public boolean retainAll(Collection col)
Retains all elements, e, of the underlying collection for which col.contains(e) returns true. That is, every element that doesn't exist in col is removed. A lock on the mutex is obtained before the operation proceeds.

Specified by:
retainAll in interface Collection

size

public int size()
Retrieves the size of the underlying collection. A lock on the mutex is obtained before the collection is accessed.

Specified by:
size in interface Collection

toArray

public java.lang.Object[] toArray()
Returns an array containing each object within the underlying collection. A lock is obtained on the mutex before the collection is accessed.

Specified by:
toArray in interface Collection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Copies the elements in the underlying collection to the supplied array. If a.length < size(), a new array of the same run-time type is created, with a size equal to that of the collection. If a.length > size(), then the elements from 0 to size() - 1 contain the elements from this collection. The following element is set to null to indicate the end of the collection objects. However, this only makes a difference if null is not a permitted value within the collection. Before the copying takes place, a lock is obtained on the mutex.

Specified by:
toArray in interface Collection

toString

public java.lang.String toString()
Returns a string representation of the underlying collection. A lock is obtained on the mutex before the string is created.