Class CloneListIterator<E>

java.lang.Object
org.eclipse.persistence.jpa.jpql.utility.iterator.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

public class CloneListIterator<E> extends Object implements ListIterator<E>
A 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:
  • Constructor Details

    • CloneListIterator

      public CloneListIterator(E[] array)
      Construct a list iterator on a copy of the specified array. The modification methods will not be supported, unless a subclass overrides them.
    • CloneListIterator

      public CloneListIterator(E[] array, CloneListIterator.Mutator<E> mutator)
      Construct a list iterator on a copy of the specified array. Use the specified list mutator to modify the original list.
    • CloneListIterator

      public CloneListIterator(List<? extends E> list)
      Construct a list iterator on a copy of the specified list. The modification methods will not be supported, unless a subclass overrides them.
    • CloneListIterator

      public CloneListIterator(List<? extends E> list, CloneListIterator.Mutator<E> mutator)
      Construct a list iterator on a copy of the specified list. Use the specified list mutator to modify the original list.
    • CloneListIterator

      protected CloneListIterator(CloneListIterator.Mutator<E> mutator, 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 Details

    • add

      public void add(E o)
      Specified by:
      add in interface ListIterator<E>
    • add

      protected void add(int index, E o)
      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()
      Specified by:
      hasNext in interface Iterator<E>
      Specified by:
      hasNext in interface ListIterator<E>
    • hasPrevious

      public boolean hasPrevious()
      Specified by:
      hasPrevious in interface ListIterator<E>
    • nestedNext

      protected E nestedNext()
      The list 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[]).
    • nestedPrevious

      protected E nestedPrevious()
      The list 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[]).
    • next

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

      public int nextIndex()
      Specified by:
      nextIndex in interface ListIterator<E>
    • previous

      public E previous()
      Specified by:
      previous in interface ListIterator<E>
    • previousIndex

      public int previousIndex()
      Specified by:
      previousIndex in interface ListIterator<E>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<E>
      Specified by:
      remove in interface ListIterator<E>
    • 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

      public void set(E o)
      Specified by:
      set in interface ListIterator<E>
    • set

      protected void set(int index, E o)
      Set the specified element in the original list.

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