com.aliasi.util
Class Iterators.Filter<E>

java.lang.Object
  extended by com.aliasi.util.Iterators.Filter<E>
Type Parameters:
E - the type of objects returned by the iterator
All Implemented Interfaces:
Iterator<E>
Enclosing class:
Iterators

public abstract static class Iterators.Filter<E>
extends Object
implements Iterator<E>

An Iterators.Filter filters the stream of objects returned by another iterator by subjecting them to an acceptance test. Instances are constructed with a specified iterator to be filtered; this filter is saved in this class and should not be accessed by other methods. Concrete subclasses must implement accept(Object), which determines which of the elements produced by the containediterator are returned.

Since:
LingPipe1.0
Version:
3.0
Author:
Bob Carpenter

Constructor Summary
Iterators.Filter(Iterator<? extends E> iterator)
          Construct a filtered iterator from the specified iterator.
 
Method Summary
abstract  boolean accept(E x)
          Returns true for objects returned by the contained iterator that should be returned by this iterator.
 boolean hasNext()
          Returns true if calls to next() will return a value.
 E next()
          Returns the next value from the contained iterator that is accepted.
 void remove()
          This operation is not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Iterators.Filter

public Iterators.Filter(Iterator<? extends E> iterator)
Construct a filtered iterator from the specified iterator.

Parameters:
iterator - Contained iterator to be filtered.
Method Detail

accept

public abstract boolean accept(E x)
Returns true for objects returned by the contained iterator that should be returned by this iterator.

Parameters:
x - Object to test.
Returns:
true if this object should be returned by this iterator.

hasNext

public boolean hasNext()
Returns true if calls to next() will return a value.

Implementation note: This iterator stores the next element in a local variable after calls to this method. Calls to next() remove this reference.

Specified by:
hasNext in interface Iterator<E>
Returns:
true if calls to next() will return a value.

next

public E next()
Returns the next value from the contained iterator that is accepted. Acceptance is determined by the method accept(Object).

Specified by:
next in interface Iterator<E>
Returns:
Next object from the underlying iterator that passes the acceptance test.
Throws:
NoSuchElementException - If there are no more elements in the underlying iterator that pass the acceptance test.

remove

public void remove()
This operation is not supported.

Implementation Note: Because calls to hasNext() must iterate over the contained iterator to find the next acceptable object to return, it is not guaranteed that the last element returned by this iterator is the same as the last element returned by the underlying iterator. Thus the underlying iterator can't be used to do the removal without tripping the fail-fast behavior of Iterator.

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - Always.