public class CloneListIterator<E> extends java.lang.Object implements IterableListIterator<E>
CloneListIterator iterates over a copy of a list, allowing for concurrent access
to the original list.
The original list passed to the CloneListIterator's constructor should be
synchronized; otherwise you run the risk of a corrupted list.
By default, a CloneListIterator does not support the modification operations; this
is because it does not have access to the original list. But if the CloneListIterator
is supplied with a Mutator it will delegate the modification operations to the Mutator. Alternatively, a subclass can override the modification methods.
| Constructor and Description |
|---|
CloneListIterator(java.util.List<? extends E> list)
Creates a new
CloneListIterator using a copy of the specified list. |
CloneListIterator(java.util.List<? extends E> list,
ListMutator<E> mutator)
Construct a list iterator on a copy of the specified list.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(E item) |
protected void |
add(int index,
E item)
Adds the specified element to the original list.
|
boolean |
hasNext() |
boolean |
hasPrevious() |
java.util.ListIterator<E> |
iterator() |
E |
next() |
int |
nextIndex() |
E |
previous() |
int |
previousIndex() |
void |
remove() |
protected void |
remove(int index)
Removes the specified element from the original list.
|
void |
set(E item) |
protected void |
set(int index,
E item)
Sets the specified element in the original list.
|
java.lang.String |
toString() |
public CloneListIterator(java.util.List<? extends E> list)
CloneListIterator using a copy of the specified list. The
modification methods will not be supported, unless a subclass overrides them.list - The list that is copied in order to iterate over its items without being changed concurrentlypublic CloneListIterator(java.util.List<? extends E> list, ListMutator<E> mutator)
ListMutator
to modify the original list.list - The list that is copied in order to iterate over its items without being changed concurrentlymutator - This ListMutator is used to remove the item from the original listprotected void add(int index,
E item)
This method can be overridden by a subclass as an alternative to building a Mutator.
index - The index of insertionitem - The element to insert into the listpublic boolean hasNext()
public boolean hasPrevious()
hasPrevious in interface java.util.ListIterator<E>public java.util.ListIterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface IterableListIterator<E>public E next()
public int nextIndex()
nextIndex in interface java.util.ListIterator<E>public int previousIndex()
previousIndex in interface java.util.ListIterator<E>public void remove()
protected void remove(int index)
This method can be overridden by a subclass as an alternative to building a ListMutator.
index - The position of the item to remove from the original listprotected void set(int index,
E item)
This method can be overridden by a subclass as an alternative to building a ListMutator.
index - The index of replacementitem - The element to replace the existing onepublic java.lang.String toString()
toString in class java.lang.Object