Class FilteredIterator<T>
java.lang.Object
org.apache.commons.functor.core.collection.FilteredIterator<T>
- Type Parameters:
T- theIteratorgeneric type
- All Implemented Interfaces:
Iterator<T>
Iterator that filters another Iterator by only passing through those elements
that are matched by a specified UnaryPredicate.
- Version:
- $Revision$ $Date$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFlag to mark current iterator element can be removed.The wrapped iterator.private TReference to next element has to be returned by this iterator.private booleanFlag to mark this iterator has more elements or not.private final UnaryPredicate<? super T> The predicate used to test this Iterator elements. -
Constructor Summary
ConstructorsConstructorDescriptionFilteredIterator(Iterator<? extends T> iterator, UnaryPredicate<? super T> predicate) Create a new FilteredIterator. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic <T> Iterator<T> filter(Iterator<? extends T> iter, UnaryPredicate<? super T> pred) Get a filtered Iterator instance applyingpredtoiter.inthashCode()booleanhasNext()next()voidremove()private TGet the next element.private booleansetNext()Set next element.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
predicate
The predicate used to test this Iterator elements. -
iterator
The wrapped iterator. -
next
Reference to next element has to be returned by this iterator. -
nextSet
private boolean nextSetFlag to mark this iterator has more elements or not. -
canRemove
private boolean canRemoveFlag to mark current iterator element can be removed.
-
-
Constructor Details
-
FilteredIterator
Create a new FilteredIterator.- Parameters:
iterator- to filterpredicate- to apply
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
equals
-
hashCode
public int hashCode() -
toString
-
filter
Get a filtered Iterator instance applyingpredtoiter.- Type Parameters:
T- the input iterator generic type- Parameters:
iter- to filterpred- to apply- Returns:
- Iterator
-
setNext
private boolean setNext()Set next element.- Returns:
- whether the current iterator position is valid
-
returnNext
Get the next element.- Returns:
- next element.
-