Class FilteredIterator<X>

java.lang.Object
repast.simphony.util.collections.FilteredIterator<X>
All Implemented Interfaces:
Iterable<X>, Iterator<X>

public class FilteredIterator<X> extends Object implements Iterator<X>, Iterable<X>
An iterator that decorates another iterator with filtering capabilities based on a specified rule. This allows for early stopping of iteration on the first invalid entry or full traversal.

This does not support the remove operation.

Version:
$Revision: 1.1 $ $Date: 2005/12/21 22:25:35 $
Author:
Jerry Vos
  • Constructor Summary

    Constructors
    Constructor
    Description
    FilteredIterator(Iterator<X> innerIterator, org.apache.commons.collections15.Predicate<X> predicate)
    Constructs this iterator working on the specified iterator with the specified predicate, and searching through all the iterator.
    FilteredIterator(Iterator<X> innerIterator, org.apache.commons.collections15.Predicate<X> predicate, boolean scanAll)
    Constructs this iterator working on the specified iterator with the specified predicate.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the iteration has more elements.
    Returns an iterator over a set of elements of type T.
    Returns the next element in the iteration.
    void
    Unsupported, throws an UnsupportedOperationException.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator

    Methods inherited from interface java.util.Iterator

    forEachRemaining
  • Constructor Details

    • FilteredIterator

      public FilteredIterator(Iterator<X> innerIterator, org.apache.commons.collections15.Predicate<X> predicate)
      Constructs this iterator working on the specified iterator with the specified predicate, and searching through all the iterator.
      Parameters:
      innerIterator - the iterator to add the functionality to
      predicate - the predicate that determines the validity of objects (the filtering rule)
    • FilteredIterator

      public FilteredIterator(Iterator<X> innerIterator, org.apache.commons.collections15.Predicate<X> predicate, boolean scanAll)
      Constructs this iterator working on the specified iterator with the specified predicate.
      Parameters:
      innerIterator - the iterator to add the functionality to
      predicate - the predicate that determines the validity of objects (the filtering rule)
  • Method Details

    • next

      public X next()
      Returns the next element in the iteration. Calling this method repeatedly until the hasNext() method returns false will return each element in the underlying collection exactly once.
      Specified by:
      next in interface Iterator<X>
      Returns:
      the next element in the iteration.
      Throws:
      NoSuchElementException - iteration has no more elements.
    • 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<X>
      Returns:
      true if the iterator has more elements.
    • iterator

      public Iterator<X> iterator()
      Returns an iterator over a set of elements of type T.
      Specified by:
      iterator in interface Iterable<X>
      Returns:
      an Iterator.
    • remove

      public void remove()
      Unsupported, throws an UnsupportedOperationException.
      Specified by:
      remove in interface Iterator<X>