org.xshare.base.iterator
Class FilterIterator

java.lang.Object
  |
  +--org.xshare.base.iterator.FilterIterator
All Implemented Interfaces:
java.util.Iterator

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

Filters the elements of another iteration based on a UnaryPredicate wrapping an given iterator and applying a UnaryPredicate for each element. Only elements, there the predicate is true are returned by this iterator.

Notes On The Implemenation

Version:
$Revision: 1.3 $
Author:
Oliver Fischer
See Also:
RangeIterator

Constructor Summary
FilterIterator(UnaryPredicate pFilterPredicate, java.util.Iterator pSourceIterator)
          Creates a new instance of this iterator for a given predicate and iterator.
 
Method Summary
 boolean hasNext()
          Checks if there are some elements left, for which the condition given to the constructor is true.
 java.lang.Object next()
          Returns the next element which fits in the condition set with the constructor of this instance.
 void remove()
          This method is not supported since this class is only an adapter for another iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilterIterator

public FilterIterator(UnaryPredicate pFilterPredicate,
                      java.util.Iterator pSourceIterator)
Creates a new instance of this iterator for a given predicate and iterator.

Parameters:
pFilterPredicate - an UnaryPredicate which is evaluated for every element of the underlying iterator.
pSourceIterator - an arbitrary iterator which should be filtered according to the criterias expressed in the given predicate.
Method Detail

remove

public void remove()
This method is not supported since this class is only an adapter for another iterator.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - if this method is called.

next

public java.lang.Object next()
Returns the next element which fits in the condition set with the constructor of this instance.

Specified by:
next in interface java.util.Iterator
Throws:
java.util.NoSuchElementException - if hasNext() denies the that there are objects left.
See Also:
hasNext()

hasNext

public boolean hasNext()
Checks if there are some elements left, for which the condition given to the constructor is true.

Specified by:
hasNext in interface java.util.Iterator
Returns:
a boolean value, which is true if there are some elements left to return via next(). Otherwise false is returned.
See Also:
next()


jKiska Base 0.10 [http://jkiska.sourceforge.net]