Class FilterIterator<E>

java.lang.Object
com.twelvemonkeys.util.FilterIterator<E>
All Implemented Interfaces:
Iterator<E>

public class FilterIterator<E> extends Object implements Iterator<E>
Wraps (decorates) an Iterator with extra functionality, to allow element filtering. Each element is filtered against the given Filter, and only elements that are accepted are returned by the next method.

The optional remove operation is implemented, but may throw UnsupportedOperationException if the underlying iterator does not support the remove operation.

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/FilterIterator.java#1 $
Author:
Harald Kuhr, last modified by $Author: haku $
See Also:
  • Field Details

  • Constructor Details

    • FilterIterator

      public FilterIterator(Iterator<E> pIterator, FilterIterator.Filter<E> pFilter)
      Creates a FilterIterator that wraps the Iterator. Each element is filtered against the given Filter, and only elements that are accepted are returned by the next method.
      Parameters:
      pIterator - the iterator to filter
      pFilter - the filter
      See Also:
  • Method Details

    • hasNext

      public boolean hasNext()
      Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
      Specified by:
      hasNext in interface Iterator<E>
      Returns:
      true if the iterator has more elements.
      See Also:
    • next

      public E next()
      Returns the next element in the iteration.
      Specified by:
      next in interface Iterator<E>
      Returns:
      the next element in the iteration.
      See Also:
    • remove

      public void remove()
      Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.
      Specified by:
      remove in interface Iterator<E>