Class SnapshotCloneIterable<E>
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.utility.iterable.CloneIterable<E>
-
- org.eclipse.persistence.jpa.jpql.tools.utility.iterable.SnapshotCloneIterable<E>
-
- Type Parameters:
E
- the type of elements returned by the iterable's iterator
- All Implemented Interfaces:
java.lang.Iterable<E>
public class SnapshotCloneIterable<E> extends CloneIterable<E>
ASnapshotCloneIterable
returns an iterator on a "snapshot" of a collection, allowing for concurrent access to the original collection. A copy of the collection is created when the iterable is constructed. As a result, the contents of the collection will be the same with every call toiterator()
.The original collection passed to the
SnapshotCloneIterable
's constructor should be thread-safe (e.g.Vector
); otherwise you run the risk of a corrupted collection.By default, the iterator returned by a
SnapshotCloneIterable
does not support theIterator.remove()
operation; this is because it does not have access to the original collection. But if theSnapshotCloneIterable
is supplied with aCloneIterator.Remover
it will delegate theIterator.remove()
operation to theRemover
. Alternatively, a subclass can override the iterable'sCloneIterable.remove(Object)
method.This iterable is useful for multiple passes over a collection that should not be changed (e.g. by another thread) between passes.
- See Also:
CloneIterator
, LiveCloneIterable,SnapshotCloneListIterable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SnapshotCloneIterable.LocalCloneIterator<E>
provide access to "internal" constructor-
Nested classes/interfaces inherited from class org.eclipse.persistence.jpa.jpql.tools.utility.iterable.CloneIterable
CloneIterable.DefaultRemover
-
-
Constructor Summary
Constructors Constructor Description SnapshotCloneIterable(java.util.Collection<? extends E> collection)
Construct a "snapshot" iterable for the specified collection.SnapshotCloneIterable(java.util.Collection<? extends E> collection, CloneIterator.Remover<E> remover)
Construct a "snapshot" iterable for the specified collection.SnapshotCloneIterable(java.util.Iterator<? extends E> iterator)
Construct a "snapshot" iterable for the specified iterator.SnapshotCloneIterable(java.util.Iterator<? extends E> iterator, CloneIterator.Remover<E> remover)
Construct a "snapshot" iterable for the specified iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<E>
iterator()
java.lang.String
toString()
-
Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.utility.iterable.CloneIterable
buildDefaultRemover, remove
-
-
-
-
Constructor Detail
-
SnapshotCloneIterable
public SnapshotCloneIterable(java.util.Iterator<? extends E> iterator)
Construct a "snapshot" iterable for the specified iterator. TheIterator.remove()
operation will not be supported by the iterator returned byiterator()
unless a subclass overrides the iterable'sCloneIterable.remove(Object)
method.
-
SnapshotCloneIterable
public SnapshotCloneIterable(java.util.Iterator<? extends E> iterator, CloneIterator.Remover<E> remover)
Construct a "snapshot" iterable for the specified iterator. The specified remover will be used by any generated iterators to remove objects from the original collection.
-
SnapshotCloneIterable
public SnapshotCloneIterable(java.util.Collection<? extends E> collection)
Construct a "snapshot" iterable for the specified collection. TheIterator.remove()
operation will not be supported by the iterator returned byiterator()
unless a subclass overrides the iterable'sCloneIterable.remove(Object)
method.
-
SnapshotCloneIterable
public SnapshotCloneIterable(java.util.Collection<? extends E> collection, CloneIterator.Remover<E> remover)
Construct a "snapshot" iterable for the specified collection. The specified remover will be used by any generated iterators to remove objects from the original collection.
-
-
Method Detail
-
iterator
public java.util.Iterator<E> iterator()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-