Class EncapsulatingIterator<E,T>

java.lang.Object
org.bzdev.util.EncapsulatingIterator<E,T>
Type Parameters:
T - the type of the values produced by an existing iterator
E - the type of the values produced by this iterator
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
NamedObjectFactory.ParmNameIterator

public abstract class EncapsulatingIterator<E,T> extends Object implements Iterator<E>
Encapsulating iterator class. An encapsulating iterator uses an iterator passed to its constructor to generate a sequence of objects of type T. Instead of returning an object of type T when next() is called, an object of a different type E is returned. The method next() is responsible for constructing an object of type E from the corresponding object of type T.

One use is in conjunction with a template processor, where objects of type Iterator<TemplateProcessor.KeyMap> can be used for iteration.

  • Constructor Details

    • EncapsulatingIterator

      public EncapsulatingIterator(Iterator<T> it)
      Constructor.
      Parameters:
      it - the iterator to encapsulate
  • Method Details

    • hasNext

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

      protected T encapsulatedNext()
      Get the next element using the iterator passed to the constructor. This method must be called once and only once by next() for each call to next().
      Returns:
      the next element from the encapsulated iterator.
    • next

      public abstract E next()
      Return the next element in the iteration. Typically, this method will create a new element of type E and then configure it based on the value returned by a single call to encapsulatedNext().
      Specified by:
      next in interface Iterator<E>
      Returns:
      the next element in the iteration
    • remove

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