net.sourceforge.nite.util
Class IteratorFilter

java.lang.Object
  extended by net.sourceforge.nite.util.IteratorFilter
All Implemented Interfaces:
java.util.Iterator

public class IteratorFilter
extends java.lang.Object
implements java.util.Iterator

An IteratorFilter is used to filter Objects in an Iterator and present them as a new Iterator.
The filter is initialised with a Predicate; only Objects for which the predicate p.valid(Object o) returns true will be passed on, other object will be left out. This implementation is lazy, meaning that the next object from the original iterator will not be accessed before it is needed due to a call to the next() method of this IteratorFilter. The original Iterator will therefore be traversed only once and the elements will not be stored in an intermediate array or something like that.
By default, the IteratorFilter does not allow removal of objects.
Example:
.. Iterator it = someSetOfStrings.iterator(); Predicate p = new Predicate() { public boolean valid(Object o) { return ((String)o).startsWith("a"); } }; Iterator filteredIt = new IteratorFilter(it, p); ..
You can also implement special subclasses of Predicate to achieve more complex boolean tests.

Examples of the use of the different Iterator modifyers (IteratorFilter, IteratorTransform, IteratorChain) can be found in the class RTSI.

Author:
Dennis Reidsma, UTwente
Adapted from the parlevink package (HMI group, University of Twente)

Constructor Summary
IteratorFilter(java.util.Iterator it, Predicate pred)
           
 
Method Summary
 boolean hasNext()
           
 java.lang.Object next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IteratorFilter

public IteratorFilter(java.util.Iterator it,
                      Predicate pred)
Parameters:
it - The Iterator to filter
pred - The Predicate
Method Detail

remove

public void remove()
Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator