public class FilterIterator<E>
extends java.lang.Object
implements java.util.Iterator<E>
Iterator with extra functionality, to allow
element filtering. Each
element is filtered against the given Filter, and only elements
that are accepted are returned by the next method.
The optional remove operation is implemented, but may throw
UnsupportedOperationException if the underlying iterator does not
support the remove operation.FilterIterator.Filter| Modifier and Type | Class and Description |
|---|---|
static interface |
FilterIterator.Filter<E>
Used to tests whether or not an element fulfills certain criteria, and
hence should be accepted by the FilterIterator instance.
|
| Modifier and Type | Field and Description |
|---|---|
protected FilterIterator.Filter<E> |
filter |
protected java.util.Iterator<E> |
iterator |
| Constructor and Description |
|---|
FilterIterator(java.util.Iterator<E> pIterator,
FilterIterator.Filter<E> pFilter)
Creates a
FilterIterator that wraps the Iterator. |
protected final FilterIterator.Filter<E> filter
protected final java.util.Iterator<E> iterator
public FilterIterator(java.util.Iterator<E> pIterator, FilterIterator.Filter<E> pFilter)
FilterIterator that wraps the Iterator. Each
element is filtered against the given Filter, and only elements
that are accepted are returned by the next method.pIterator - the iterator to filterpFilter - the filterFilterIterator.Filterpublic boolean hasNext()
true if the iteration has more elements. (In other
words, returns true if next would return an element
rather than throwing an exception.)hasNext in interface java.util.Iterator<E>true if the iterator has more elements.FilterIterator.Filter.accept(E)public E next()
next in interface java.util.Iterator<E>FilterIterator.Filter.accept(E)public void remove()
next. The behavior of an iterator is unspecified if
the underlying collection is modified while the iteration is in
progress in any way other than by calling this method.remove in interface java.util.Iterator<E>Copyright © 2018. All Rights Reserved.