Class FilterIterator<E>
java.lang.Object
org.apache.commons.collections4.iterators.FilterIterator<E>
- Type Parameters:
- E- the type of elements returned by this iterator.
- All Implemented Interfaces:
- Iterator<E>,- IteratorOperations<E>
- Direct Known Subclasses:
- UniqueFilterIterator
Decorates an 
Iterator using an optional predicate to filter elements.
 
 This iterator decorates the underlying iterator, only allowing through
 those elements that match the specified Predicate.
 
- Since:
- 1.0
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a newFilterIteratorthat will not function untilsetIteratoris invoked.FilterIterator(Iterator<? extends E> iterator) Constructs a newFilterIteratorthat will not function untilsetPredicateis invoked.FilterIterator(Iterator<? extends E> iterator, Predicate<? super E> predicate) Constructs a newFilterIteratorthat will use the given iterator and predicate.
- 
Method SummaryModifier and TypeMethodDescriptionGets the iterator this iterator is using.Gets the predicate this iterator is using.booleanhasNext()Returns true if the underlying iterator contains an object that matches the predicate.next()Returns the next object that matches the predicate.voidremove()Removes from the underlying collection of the base iterator the last element returned by this iterator.voidsetIterator(Iterator<? extends E> iterator) Sets the iterator for this iterator to use.voidsetPredicate(Predicate<? super E> predicate) Sets the predicate this the iterator to use where null accepts all values.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.IteratorforEachRemainingMethods inherited from interface org.apache.commons.collections4.iterators.IteratorOperationsaddTo, removeNext, toCollection, toList, toSet
- 
Constructor Details- 
FilterIteratorpublic FilterIterator()Constructs a newFilterIteratorthat will not function untilsetIteratoris invoked.
- 
FilterIteratorConstructs a newFilterIteratorthat will not function untilsetPredicateis invoked.- Parameters:
- iterator- the iterator to use
 
- 
FilterIteratorConstructs a newFilterIteratorthat will use the given iterator and predicate.- Parameters:
- iterator- the iterator to use
- predicate- the predicate to use, null accepts all values.
 
 
- 
- 
Method Details- 
getIteratorGets the iterator this iterator is using.- Returns:
- the underlying iterator.
 
- 
getPredicateGets the predicate this iterator is using.- Returns:
- the filtering predicate.
 
- 
hasNextReturns true if the underlying iterator contains an object that matches the predicate.- Specified by:
- hasNextin interface- Iterator<E>
- Returns:
- true if there is another object that matches the predicate
- Throws:
- NullPointerException- if either the iterator or predicate are null
 
- 
nextReturns the next object that matches the predicate.- Specified by:
- nextin interface- Iterator<E>
- Returns:
- the next object which matches the given predicate
- Throws:
- NullPointerException- if either the iterator or predicate are null
- NoSuchElementException- if there are no more elements that match the predicate
 
- 
removeRemoves from the underlying collection of the base iterator the last element returned by this iterator. This method can only be called ifnext()was called, but not afterhasNext(), because thehasNext()call changes the base iterator.- Specified by:
- removein interface- Iterator<E>
- Throws:
- IllegalStateException- if- hasNext()has already been called.
 
- 
setIteratorSets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.- Parameters:
- iterator- the iterator to use
 
- 
setPredicateSets the predicate this the iterator to use where null accepts all values.- Parameters:
- predicate- the predicate to use, null accepts all values.
 
 
-