public class FilterIterator<E> extends Object implements 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 Iterator<E> |
iterator |
| Constructor and Description |
|---|
FilterIterator(Iterator<E> pIterator,
FilterIterator.Filter<E> pFilter)
Creates a
FilterIterator that wraps the Iterator. |
protected final FilterIterator.Filter<E> filter
public FilterIterator(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 Iterator<E>true if the iterator has more elements.FilterIterator.Filter.accept(E)public E next()
next in interface 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.Copyright © 2014. All Rights Reserved.