Class FilterIterator<E>
- java.lang.Object
-
- org.apache.openjpa.lib.util.collections.FilterIterator<E>
-
- All Implemented Interfaces:
java.util.Iterator<E>
public class FilterIterator<E> extends java.lang.Object implements java.util.Iterator<E>Decorates anotherIteratorusing a predicate to filter elements.This iterator decorates the underlying iterator, only allowing through those elements that match the specified
Predicate.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description FilterIterator()Constructs a newFilterIteratorthat will not function untilsetIteratoris invoked.FilterIterator(java.util.Iterator<? extends E> iterator)Constructs a newFilterIteratorthat will not function untilsetPredicateis invoked.FilterIterator(java.util.Iterator<? extends E> iterator, java.util.function.Predicate<? super E> predicate)Constructs a newFilterIteratorthat will use the given iterator and predicate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Iterator<? extends E>getIterator()Gets the iterator this iterator is using.java.util.function.Predicate<? super E>getPredicate()Gets the predicate this iterator is using.booleanhasNext()Returns true if the underlying iterator contains an object that matches the predicate.Enext()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(java.util.Iterator<? extends E> iterator)Sets the iterator for this iterator to use.voidsetPredicate(java.util.function.Predicate<? super E> predicate)Sets the predicate this the iterator to use.
-
-
-
Constructor Detail
-
FilterIterator
public FilterIterator()
Constructs a newFilterIteratorthat will not function untilsetIteratoris invoked.
-
FilterIterator
public FilterIterator(java.util.Iterator<? extends E> iterator)
Constructs a newFilterIteratorthat will not function untilsetPredicateis invoked.- Parameters:
iterator- the iterator to use
-
-
Method Detail
-
hasNext
public boolean hasNext()
Returns true if the underlying iterator contains an object that matches the predicate.- Specified by:
hasNextin interfacejava.util.Iterator<E>- Returns:
- true if there is another object that matches the predicate
- Throws:
java.lang.NullPointerException- if either the iterator or predicate are null
-
next
public E next()
Returns the next object that matches the predicate.- Specified by:
nextin interfacejava.util.Iterator<E>- Returns:
- the next object which matches the given predicate
- Throws:
java.lang.NullPointerException- if either the iterator or predicate are nulljava.util.NoSuchElementException- if there are no more elements that match the predicate
-
remove
public void remove()
Removes 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 interfacejava.util.Iterator<E>- Throws:
java.lang.IllegalStateException- ifhasNext()has already been called.
-
getIterator
public java.util.Iterator<? extends E> getIterator()
Gets the iterator this iterator is using.- Returns:
- the iterator
-
setIterator
public void setIterator(java.util.Iterator<? extends E> iterator)
Sets the iterator for this iterator to use. If iteration has started, this effectively resets the iterator.- Parameters:
iterator- the iterator to use
-
getPredicate
public java.util.function.Predicate<? super E> getPredicate()
Gets the predicate this iterator is using.- Returns:
- the predicate
-
setPredicate
public void setPredicate(java.util.function.Predicate<? super E> predicate)
Sets the predicate this the iterator to use.- Parameters:
predicate- the predicate to use
-
-