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

Quick Search    Search Deep

java.util
Class Collections.SynchronizedListIterator  view Collections.SynchronizedListIterator download Collections.SynchronizedListIterator.java

java.lang.Object
  extended byjava.util.Collections.SynchronizedIterator
      extended byjava.util.Collections.SynchronizedListIterator
All Implemented Interfaces:
Iterator, ListIterator
Enclosing class:
Collections

private static final class Collections.SynchronizedListIterator
extends Collections.SynchronizedIterator
implements ListIterator

The implementation of SynchronizedList#listIterator(). This iterator must "sync" on the same object as the list it iterates over.


Field Summary
private  ListIterator li
          The wrapped iterator, stored both here and in the superclass to avoid excessive casting.
(package private)  java.lang.Object mutex
          The object to synchronize on.
 
Constructor Summary
(package private) Collections.SynchronizedListIterator(java.lang.Object sync, ListIterator li)
          Only trusted code creates a wrapper, with the specified sync.
 
Method Summary
 void add(java.lang.Object o)
          Insert an element into the underlying list at the current position of the iterator (optional operation).
 boolean hasNext()
          Returns true if objects can still be retrieved from the iterator using next().
 boolean hasPrevious()
          Tests whether there are elements remaining in the underlying list in the reverse direction.
 java.lang.Object next()
          Retrieves the next object in the underlying collection.
 int nextIndex()
          Find the index of the element that would be returned by a call to next().
 java.lang.Object previous()
          Obtain the previous element from the underlying list.
 int previousIndex()
          Find the index of the element that would be returned by a call to previous.
 void remove()
          Removes the object that was last returned by next() from the underlying collection.
 void set(java.lang.Object o)
          Replace the element last returned by a call to next() or previous() with a given object (optional operation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.ListIterator
hasNext, next, remove
 

Field Detail

li

private final ListIterator li
The wrapped iterator, stored both here and in the superclass to avoid excessive casting.


mutex

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

Constructor Detail

Collections.SynchronizedListIterator

Collections.SynchronizedListIterator(java.lang.Object sync,
                                     ListIterator li)
Only trusted code creates a wrapper, with the specified sync.

Method Detail

add

public void add(java.lang.Object o)
Insert an element into the underlying list at the current position of the iterator (optional operation). The element is inserted in between the element that would be returned by previous() and the element that would be returned by next(). After the insertion, a subsequent call to next is unaffected, but a call to previous returns the item that was added. The values returned by nextIndex() and previousIndex() are incremented. A lock is obtained on the mutex before the addition takes place.

Specified by:
add in interface ListIterator

hasPrevious

public boolean hasPrevious()
Tests whether there are elements remaining in the underlying list in the reverse direction. In other words, previous() will not fail with a NoSuchElementException. A lock is obtained on the mutex before the check takes place.

Specified by:
hasPrevious in interface ListIterator

nextIndex

public int nextIndex()
Find the index of the element that would be returned by a call to next(). If hasNext() returns false, this returns the list size. A lock is obtained on the mutex before the query takes place.

Specified by:
nextIndex in interface ListIterator

previous

public java.lang.Object previous()
Obtain the previous element from the underlying list. Repeated calls to previous may be used to iterate backwards over the entire list, or calls to next and previous may be used together to go forwards and backwards. Alternating calls to next and previous will return the same element. A lock is obtained on the mutex before the object is retrieved.

Specified by:
previous in interface ListIterator

previousIndex

public int previousIndex()
Find the index of the element that would be returned by a call to previous. If hasPrevious() returns false, this returns -1. A lock is obtained on the mutex before the query takes place.

Specified by:
previousIndex in interface ListIterator

set

public void set(java.lang.Object o)
Replace the element last returned by a call to next() or previous() with a given object (optional operation). This method may only be called if neither add() nor remove() have been called since the last call to next() or previous. A lock is obtained on the mutex before the list is modified.

Specified by:
set in interface ListIterator

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