Package com.twelvemonkeys.util
Class FilterIterator<E>
- java.lang.Object
-
- com.twelvemonkeys.util.FilterIterator<E>
-
- All Implemented Interfaces:
java.util.Iterator<E>
public class FilterIterator<E> extends java.lang.Object implements java.util.Iterator<E>Wraps (decorates) anIteratorwith extra functionality, to allow element filtering. Each element is filtered against the givenFilter, and only elements that areaccepted are returned by thenextmethod.The optional
removeoperation is implemented, but may throwUnsupportedOperationExceptionif 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:
FilterIterator.Filter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFilterIterator.Filter<E>Used to tests whether or not an element fulfills certain criteria, and hence should be accepted by the FilterIterator instance.
-
Constructor Summary
Constructors Constructor Description FilterIterator(java.util.Iterator<E> pIterator, FilterIterator.Filter<E> pFilter)Creates aFilterIteratorthat wraps theIterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()Returnstrueif the iteration has more elements.Enext()Returns the next element in the iteration.voidremove()Removes from the underlying collection the last element returned by the iterator (optional operation).
-
-
-
Field Detail
-
filter
protected final FilterIterator.Filter<E> filter
-
iterator
protected final java.util.Iterator<E> iterator
-
next
private E next
-
current
private E current
-
-
Constructor Detail
-
FilterIterator
public FilterIterator(java.util.Iterator<E> pIterator, FilterIterator.Filter<E> pFilter)
Creates aFilterIteratorthat wraps theIterator. Each element is filtered against the givenFilter, and only elements that areaccepted are returned by thenextmethod.- Parameters:
pIterator- the iterator to filterpFilter- the filter- See Also:
FilterIterator.Filter
-
-
Method Detail
-
hasNext
public boolean hasNext()
Returnstrueif the iteration has more elements. (In other words, returnstrueifnextwould return an element rather than throwing an exception.)- Specified by:
hasNextin interfacejava.util.Iterator<E>- Returns:
trueif the iterator has more elements.- See Also:
FilterIterator.Filter.accept(E)
-
next
public E next()
Returns the next element in the iteration.- Specified by:
nextin interfacejava.util.Iterator<E>- Returns:
- the next element in the iteration.
- See Also:
FilterIterator.Filter.accept(E)
-
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.- Specified by:
removein interfacejava.util.Iterator<E>
-
-