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 to each element. Only elements, there the predicate is true are returned by this iterator.

Notes On The Implemenation

Version:
$Revision: 1.6.2.1 $
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()
          Removes the last element returned by next() from the underlaying iteration by forwarding the remove call to it.
 
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.
Throws:
java.lang.NullPointerException - if one of both arguments is null
Method Detail

remove

public void remove()
Removes the last element returned by next() from the underlaying iteration by forwarding the remove call to it.

Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException - if the source iteration doesn't support this method.

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.2.1 Release Esche [http://jkiska.sourceforge.net]