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

Quick Search    Search Deep

java.util
Class Collections.SynchronizedIterator  view Collections.SynchronizedIterator download Collections.SynchronizedIterator.java

java.lang.Object
  extended byjava.util.Collections.SynchronizedIterator
All Implemented Interfaces:
Iterator
Direct Known Subclasses:
Collections.SynchronizedListIterator
Enclosing class:
Collections

private static class Collections.SynchronizedIterator
extends java.lang.Object
implements Iterator

The implementation of the various iterator methods in the synchronized classes. These iterators must "sync" on the same object as the collection they iterate over.


Field Summary
private  Iterator i
          The wrapped iterator.
(package private)  java.lang.Object mutex
          The object to synchronize on.
 
Constructor Summary
(package private) Collections.SynchronizedIterator(java.lang.Object sync, Iterator i)
          Only trusted code creates a wrapper, with the specified sync.
 
Method Summary
 boolean hasNext()
          Returns true if objects can still be retrieved from the iterator using next().
 java.lang.Object next()
          Retrieves the next object in the underlying collection.
 void remove()
          Removes the object that was last returned by next() from the underlying collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mutex

final java.lang.Object mutex
The object to synchronize on. Package visible for use by subclass.


i

private final Iterator i
The wrapped iterator.

Constructor Detail

Collections.SynchronizedIterator

Collections.SynchronizedIterator(java.lang.Object sync,
                                 Iterator i)
Only trusted code creates a wrapper, with the specified sync.

Method Detail

next

public java.lang.Object next()
Retrieves the next object in the underlying collection. A lock is obtained on the mutex before the collection is accessed.

Specified by:
next in interface Iterator

hasNext

public boolean hasNext()
Returns true if objects can still be retrieved from the iterator using next(). A lock is obtained on the mutex before the collection is accessed.

Specified by:
hasNext in interface Iterator

remove

public void remove()
Removes the object that was last returned by next() from the underlying collection. Only one call to this method is allowed per call to the next() method, and it does not affect the value that will be returned by next(). Thus, if element n was retrieved from the collection by next(), it is this element that gets removed. Regardless of whether this takes place or not, element n+1 is still returned on the subsequent next() call.

Specified by:
remove in interface Iterator