Top Description Inners Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.tools.utility.iterator

public Class CloneIterator<E>

extends Object
implements Iterator<E>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Known Direct Subclasses
org.eclipse.persistence.jpa.jpql.tools.utility.iterable.SnapshotCloneIterable.LocalCloneIterator
Type Parameters
<E>
the type of elements returned by the iterator
Imports
java.io.Serializable, java.util.Collection, .Iterator, org.eclipse.persistence.jpa.jpql.utility.iterator.ArrayIterator

A CloneIterator iterates over a copy of a collection, allowing for concurrent access to the original collection.

The original collection passed to the CloneIterator's constructor should be synchronized (e.g. java.util.Vector); otherwise you run the risk of a corrupted collection.

By default, a CloneIterator does not support the remove() operation; this is because it does not have access to the original collection. But if the CloneIterator is supplied with an Remover it will delegate the remove() operation to the Remover. Alternatively, a subclass can override the remove(Object) method.

See Also
LiveCloneIterable, SnapshotCloneIterable

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CloneIterator.Remover<T>

Used by CloneIterator to remove elements from the original collection; since the iterator does not have direct access to the original collection.

Field Summary

Modifier and TypeField and Description
private E
private final Iterator<Object>
private boolean
private final CloneIterator.Remover<E>

Constructor Summary

AccessConstructor and Description
public
CloneIterator(Collection<? extends E> collection)

Construct an iterator on a copy of the specified collection.

public
CloneIterator(E[] array)

Construct an iterator on a copy of the specified array.

public
CloneIterator(Collection<? extends E> collection, CloneIterator.Remover<E> remover)

Construct an iterator on a copy of the specified collection.

public
CloneIterator(E[] array, CloneIterator.Remover<E> remover)

Construct an iterator on a copy of the specified array.

protected
CloneIterator(CloneIterator.Remover<E> remover, Object... array)

Internal constructor used by subclasses.

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.
protected E
nestedNext()

The collection passed in during construction held elements of type E, so this cast is not a problem.

public E
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.
public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).
protected void
remove(E e)

Remove the specified element from the original collection.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
private E current
iteratorback to summary
private final Iterator<Object> iterator
removeAllowedback to summary
private boolean removeAllowed
removerback to summary
private final CloneIterator.Remover<E> remover

Constructor Detail

CloneIteratorback to summary
public CloneIterator(Collection<? extends E> collection)

Construct an iterator on a copy of the specified collection. The remove() method will not be supported, unless a subclass overrides the remove(Object).

CloneIteratorback to summary
public CloneIterator(E[] array)

Construct an iterator on a copy of the specified array. The remove() method will not be supported, unless a subclass overrides the remove(Object).

CloneIteratorback to summary
public CloneIterator(Collection<? extends E> collection, CloneIterator.Remover<E> remover)

Construct an iterator on a copy of the specified collection. Use the specified remover to remove objects from the original collection.

CloneIteratorback to summary
public CloneIterator(E[] array, CloneIterator.Remover<E> remover)

Construct an iterator on a copy of the specified array. Use the specified remover to remove objects from the original array.

CloneIteratorback to summary
protected CloneIterator(CloneIterator.Remover<E> remover, Object... array)

Internal constructor used by subclasses. Swap order of arguments to prevent collision with other constructor. The passed in array will *not* be cloned.

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nestedNextback to summary
protected E nestedNext()

The collection passed in during construction held elements of type E, 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[]).

Annotations
@SuppressWarnings:unchecked
nextback to summary
public E next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:E

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
removeback to summary
protected void remove(E e)

Remove the specified element from the original collection.

This method can be overridden by a subclass as an alternative to building a Remover.

org.eclipse.persistence.jpa.jpql.tools.utility.iterator back to summary

public Interface CloneIterator.Remover<T>

Known Direct Implementers
org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover.ReadOnly, org.eclipse.persistence.jpa.jpql.tools.utility.iterable.CloneIterable.DefaultRemover

Used by CloneIterator to remove elements from the original collection; since the iterator does not have direct access to the original collection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Method Summary

Modifier and TypeMethod and Description
public void
remove(T element)

Remove the specified object from the original collection.

Method Detail

removeback to summary
public void remove(T element)

Remove the specified object from the original collection.

org.eclipse.persistence.jpa.jpql.tools.utility.iterator back to summary

public final Class CloneIterator.Remover.ReadOnly<S>

extends Object
implements CloneIterator.Remover<S>, Serializable
Class Inheritance
  • java.lang.Object
  • org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover.ReadOnly
All Implemented Interfaces
java.io.Serializable, org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover

Field Summary

Modifier and TypeField and Description
public static final CloneIterator.Remover<T>
private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <R> CloneIterator.Remover<R>
private Object
public void
remove(Object element)

Implements org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover.remove.

Remove the specified object from the original collection.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final CloneIterator.Remover<T> INSTANCE
Annotations
@SuppressWarnings:rawtypes
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

ReadOnlyback to summary
private ReadOnly()

Method Detail

instanceback to summary
public static <R> CloneIterator.Remover<R> instance()
Annotations
@SuppressWarnings:unchecked
readResolveback to summary
private Object readResolve()
removeback to summary
public void remove(Object element)

Implements org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover.remove.

Doc from org.eclipse.persistence.jpa.jpql.tools.utility.iterator.CloneIterator.Remover.remove.

Remove the specified object from the original collection.

Annotations
@Override