Class CloneListIterator<E>
- Type Parameters:
E
- the type of elements returned by the iterator
- All Implemented Interfaces:
Iterator<E>
,ListIterator<E>
- Direct Known Subclasses:
SnapshotCloneListIterable.LocalCloneListIterator
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 (e.g. Vector
.
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 CloneListIterator.Mutator
it will delegate the
modification operations to the CloneListIterator.Mutator
.
Alternatively, a subclass can override the modification methods.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Used byCloneListIterator
to remove elements from the original list; since the list iterator does not have direct access to the original list. -
Constructor Summary
ModifierConstructorDescriptionCloneListIterator
(E[] array) Construct a list iterator on a copy of the specified array.CloneListIterator
(E[] array, CloneListIterator.Mutator<E> mutator) Construct a list iterator on a copy of the specified array.CloneListIterator
(List<? extends E> list) Construct a list iterator on a copy of the specified list.CloneListIterator
(List<? extends E> list, CloneListIterator.Mutator<E> mutator) Construct a list iterator on a copy of the specified list.protected
CloneListIterator
(CloneListIterator.Mutator<E> mutator, Object... array) Internal constructor used by subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Add the specified element to the original list.void
boolean
hasNext()
boolean
protected E
The list passed in during construction held elements of typeE
, so this cast is not a problem.protected E
The list passed in during construction held elements of typeE
, so this cast is not a problem.next()
int
previous()
int
void
remove()
protected void
remove
(int index) Remove the specified element from the original list.protected void
Set the specified element in the original list.void
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
CloneListIterator
Construct a list iterator on a copy of the specified array. The modification methods will not be supported, unless a subclass overrides them. -
CloneListIterator
Construct a list iterator on a copy of the specified array. Use the specified list mutator to modify the original list. -
CloneListIterator
Construct a list iterator on a copy of the specified list. The modification methods will not be supported, unless a subclass overrides them. -
CloneListIterator
Construct a list iterator on a copy of the specified list. Use the specified list mutator to modify the original list. -
CloneListIterator
Internal constructor used by subclasses. Swap order of arguments to prevent collision with other constructor. The passed in array will *not* be cloned.
-
-
Method Details
-
add
- Specified by:
add
in interfaceListIterator<E>
-
add
Add the specified element to the original list.This method can be overridden by a subclass as an alternative to building a
CloneListIterator.Mutator
. -
hasNext
public boolean hasNext() -
hasPrevious
public boolean hasPrevious()- Specified by:
hasPrevious
in interfaceListIterator<E>
-
nestedNext
The list passed in during construction held elements of typeE
, so this cast is not a problem. We need this cast because all the elements of the original collection were copied into an object array (Object[]
). -
nestedPrevious
The list passed in during construction held elements of typeE
, so this cast is not a problem. We need this cast because all the elements of the original collection were copied into an object array (Object[]
). -
next
-
nextIndex
public int nextIndex()- Specified by:
nextIndex
in interfaceListIterator<E>
-
previous
- Specified by:
previous
in interfaceListIterator<E>
-
previousIndex
public int previousIndex()- Specified by:
previousIndex
in interfaceListIterator<E>
-
remove
public void remove() -
remove
protected void remove(int index) Remove the specified element from the original list.This method can be overridden by a subclass as an alternative to building a
CloneListIterator.Mutator
. -
set
- Specified by:
set
in interfaceListIterator<E>
-
set
Set the specified element in the original list.This method can be overridden by a subclass as an alternative to building a
CloneListIterator.Mutator
.
-