Class CloneIterator<E>

  • Type Parameters:
    E - the type of elements returned by the iterator
    All Implemented Interfaces:
    Iterator<E>

    public class CloneIterator<E>
    extends Object
    implements Iterator<E>
    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. 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 CloneIterator.Remover it will delegate the remove() operation to the CloneIterator.Remover. Alternatively, a subclass can override the remove(Object) method.

    See Also:
    LiveCloneIterable, SnapshotCloneIterable
    • Constructor Detail

      • CloneIterator

        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).
      • CloneIterator

        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).
      • CloneIterator

        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.
      • CloneIterator

        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.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface Iterator<E>
      • next

        public E next()
        Specified by:
        next in interface Iterator<E>
      • remove

        public void remove()
        Specified by:
        remove in interface Iterator<E>