Package com.twelvemonkeys.util
Class FilterIterator<E>
java.lang.Object
com.twelvemonkeys.util.FilterIterator<E>
- All Implemented Interfaces:
Iterator<E>
Wraps (decorates) an
Iterator
with extra functionality, to allow
element filtering. Each
element is filtered against the given Filter
, and only elements
that are accept
ed 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.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/FilterIterator.java#1 $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Used to tests whether or not an element fulfills certain criteria, and hence should be accepted by the FilterIterator instance. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFilterIterator
(Iterator<E> pIterator, FilterIterator.Filter<E> pFilter) Creates aFilterIterator
that wraps theIterator
. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
filter
-
iterator
-
next
-
current
-
-
Constructor Details
-
FilterIterator
Creates aFilterIterator
that wraps theIterator
. Each element is filtered against the givenFilter
, and only elements that areaccept
ed are returned by thenext
method.- Parameters:
pIterator
- the iterator to filterpFilter
- the filter- See Also:
-
-
Method Details
-
hasNext
public boolean hasNext()Returnstrue
if the iteration has more elements. (In other words, returnstrue
ifnext
would return an element rather than throwing an exception.) -
next
Returns the next element in the iteration. -
remove
public void remove()Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call tonext
. 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.
-