Class AbstractFilteredIterator<E>

java.lang.Object
com.globalmentor.collections.iterators.AbstractPrimedIterator<E>
com.globalmentor.collections.iterators.AbstractFilteredIterator<E>
Type Parameters:
E - The type of element returned by the iterator.
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
FilteredIterator

public abstract class AbstractFilteredIterator<E> extends AbstractPrimedIterator<E>
Abstract implementation of an iterator that filters an existing iterator.

This version does not support AbstractPrimedIterator.remove().

This version releases the decorated iterator when iteration is finished.

This class is not thread safe.

Author:
Garret Wilson
  • Constructor Details

    • AbstractFilteredIterator

      public AbstractFilteredIterator(Iterator<E> iterator)
      Decorated iterator constructor.
      Parameters:
      iterator - The decorated iterator to be filtered.
      Throws:
      NullPointerException - if the given iterator is null.
  • Method Details

    • primeNext

      protected final E primeNext()
      Returns the next available element for the iterator. The value returned by this method will be returned by the next call to AbstractPrimedIterator.next. The implementation guarantees that this method will not be called again after null is returned.
      Specified by:
      primeNext in class AbstractPrimedIterator<E>
      Returns:
      The next primed value for the iterator, or null if there are no further values.
      See Also:
    • isPass

      protected abstract boolean isPass(E element)
      Indicates whether the given element is included when filtering.
      Parameters:
      element - The element in the filtered iterator.
      Returns:
      true if the element should be included, or null if it should be filtered out.