JUtil

net.cscott.jutil
Class FilterIterator<A,B>

java.lang.Object
  extended by net.cscott.jutil.UnmodifiableIterator<B>
      extended by net.cscott.jutil.FilterIterator<A,B>
All Implemented Interfaces:
Iterator<B>

public class FilterIterator<A,B>
extends UnmodifiableIterator<B>

A FilterIterator filters and maps a source Iterator to generate a new one. Note that this implementation reads one element ahead, so if the Filter changes for an object 'o' between the time that is read (when next() is called, returning the object preceding 'o', and checking that 'o' satisfies the current Filter) and the time when hasNext() is called, 'o' will still be returned, regardless of what Filter.isElement(o) returns. Thus, it is recommended that only Filters which remain consistent throughout the iteration be used.

Version:
$Id: FilterIterator.java,v 1.2 2006-10-30 19:58:05 cananian Exp $
Author:
C. Scott Ananian

Nested Class Summary
static class FilterIterator.Filter<A,B>
           
 
Constructor Summary
FilterIterator(Iterator<A> i, FilterIterator.Filter<A,B> f)
          Creates a FilterIterator.
 
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 B next()
          Returns the next element in the iteration.
 
Methods inherited from class net.cscott.jutil.UnmodifiableIterator
proxy, remove
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilterIterator

public FilterIterator(Iterator<A> i,
                      FilterIterator.Filter<A,B> f)
Creates a FilterIterator.

Method Detail

next

public B next()
Description copied from class: UnmodifiableIterator
Returns the next element in the iteration.

Specified by:
next in interface Iterator<B>
Specified by:
next in class UnmodifiableIterator<B>

hasNext

public boolean hasNext()
Description copied from class: UnmodifiableIterator
Returns true if the iteration has more elements.

Specified by:
hasNext in interface Iterator<B>
Specified by:
hasNext in class UnmodifiableIterator<B>
Returns:
true if the iterator has more elements.

JUtil

Copyright (c) 2006 C. Scott Ananian