Class FilterIterator<E>

  • All Implemented Interfaces:
    java.util.Iterator<E>

    public class FilterIterator<E>
    extends java.lang.Object
    implements java.util.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:
    FilterIterator.Filter
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  FilterIterator.Filter<E>
      Used to tests whether or not an element fulfills certain criteria, and hence should be accepted by the FilterIterator instance.
    • Constructor Summary

      Constructors 
      Constructor Description
      FilterIterator​(java.util.Iterator<E> pIterator, FilterIterator.Filter<E> pFilter)
      Creates a FilterIterator that wraps the Iterator.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasNext()
      Returns true if the iteration has more elements.
      E next()
      Returns the next element in the iteration.
      void remove()
      Removes from the underlying collection the last element returned by the iterator (optional operation).
      • 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

      • FilterIterator

        public FilterIterator​(java.util.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:
        FilterIterator.Filter
    • Method Detail

      • 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 java.util.Iterator<E>
        Returns:
        true if the iterator has more elements.
        See Also:
        FilterIterator.Filter.accept(E)
      • next

        public E next()
        Returns the next element in the iteration.
        Specified by:
        next in interface java.util.Iterator<E>
        Returns:
        the next element in the iteration.
        See Also:
        FilterIterator.Filter.accept(E)
      • 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 java.util.Iterator<E>