Package repast.simphony.util.collections
Class FilteredIterator<X>
- java.lang.Object
-
- repast.simphony.util.collections.FilteredIterator<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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Returns true if the iteration has more elements.Iterator<X>
iterator()
Returns an iterator over a set of elements of type T.X
next()
Returns the next element in the iteration.void
remove()
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 Detail
-
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 topredicate
- 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 topredicate
- the predicate that determines the validity of objects (the filtering rule)
-
-
Method Detail
-
next
public X next()
Returns the next element in the iteration. Calling this method repeatedly until thehasNext()
method returns false will return each element in the underlying collection exactly once.- Specified by:
next
in interfaceIterator<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.)
-
-