Class AbstractFilteredIterator<E>

  • Type Parameters:
    E - The type of element returned by the iterator.
    All Implemented Interfaces:
    java.util.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 Summary

      Constructors 
      Constructor Description
      AbstractFilteredIterator​(java.util.Iterator<E> iterator)
      Decorated iterator constructor.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract boolean isPass​(E element)
      Indicates whether the given element is included when filtering.
      protected E primeNext()
      Returns the next available element for the iterator.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Constructor Detail

      • AbstractFilteredIterator

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

      • 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(Object)
      • 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.