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

Quick Search    Search Deep

java.util
Class Collections.SynchronizedCollection  view Collections.SynchronizedCollection download Collections.SynchronizedCollection.java

java.lang.Object
  extended byjava.util.Collections.SynchronizedCollection
All Implemented Interfaces:
Collection, java.lang.Iterable, java.io.Serializable
Direct Known Subclasses:
Collections.SynchronizedList, Collections.SynchronizedSet
Enclosing class:
Collections

static class Collections.SynchronizedCollection
extends java.lang.Object
implements Collection, java.io.Serializable

The implementation of Collections.synchronizedCollection(Collection) 55 . This class name is required for compatibility with Sun's JDK serializability. Package visible, so that collections such as the one for Hashtable.values() can specify which object to synchronize on.


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.
 
Constructor Summary
(package private) Collections.SynchronizedCollection(Collection c)
          Wrap a given collection.
(package private) Collections.SynchronizedCollection(java.lang.Object sync, Collection c)
          Called only by trusted code to specify the mutex as well as the collection.
 
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.
 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 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.
 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.
 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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Compatible with JDK 1.4.

See Also:
Constant Field Values

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

Collections.SynchronizedCollection(Collection c)
Wrap a given collection.


Collections.SynchronizedCollection

Collections.SynchronizedCollection(java.lang.Object sync,
                                   Collection c)
Called only by trusted code to specify the mutex as well as the collection.

Method Detail

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.