Class Iterators.FilterIterator<A>

java.lang.Object
eu.bandm.tools.util.java.Iterators.FilterIterator<A>
Type Parameters:
A - the element type
All Implemented Interfaces:
Iterator<A>
Enclosing class:
Iterators

public abstract static class Iterators.FilterIterator<A> extends Object implements Iterator<A>
An iterator that passes on only selected elements.

Which elements are passed on from the underlying iterator and which are suppressed may depend on the elements themselves, as well as on the state of the filter.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    FilterIterator(Iterator<? extends A> i)
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract boolean
    accepts(A candidate)
    Checks whether an element should be passed on or suppressed.
    boolean
    Checks whether there is a next element.
    Returns the next element and advances the iterator.
    void
    Removes the previously returned element.

    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 Details

    • FilterIterator

      protected FilterIterator(Iterator<? extends A> i)
      Creates a new instance.
      Parameters:
      i - the underlying iterator
  • Method Details

    • accepts

      protected abstract boolean accepts(A candidate)
      Checks whether an element should be passed on or suppressed.

      This method is called exactly once for each element. It may both use and modify internal state.

      Parameters:
      candidate - the candidate element
      Returns:
      true if the element is to be passed on; false if it is to be suppressed
    • hasNext

      public boolean hasNext()
      Checks whether there is a next element.
      Specified by:
      hasNext in interface Iterator<A>
      Returns:
      true if next may be called
    • next

      public A next()
      Returns the next element and advances the iterator.
      Specified by:
      next in interface Iterator<A>
      Returns:
      the next element
      Throws:
      NoSuchElementException - if there are no more elements
    • remove

      public void remove()
      Removes the previously returned element.
      Specified by:
      remove in interface Iterator<A>