gshute.util
Class FilteredIterator

java.lang.Object
  |
  +--gshute.util.FilteredIterator

public class FilteredIterator
extends java.lang.Object
implements java.util.Iterator

A FilteredIterator is an iterator that filters the items in a base iterator. The filtering is performed by an item filter that is specified by a parameter in the constructor. The iteration sequence of a filtered iterator consists of those items in the base iteration sequence that are accepted by the filter, appearing in the same order as in the base iteration sequence.


Constructor Summary
FilteredIterator(java.util.Collection c, Filter fltr)
          new FilteredIterator(c, fltr) returns a new filtered iterator whose base iterator is a default iterator for c and whose filter is fltr.
FilteredIterator(java.util.Iterator baseIt, Filter fltr)
          new FilteredIterator(baseIt, fltr) returns a new filtered iterator whose base iterator is baseIt and whose filter is fltr.
 
Method Summary
protected  void findNextAcceptableItem()
          findNextAcceptableItem() advances the base iterator to the next item that is accepted by the filter, if there is one.
 boolean hasNext()
          iter.hasNext() returns true if there is another object in iter.
 java.lang.Object next()
          iter.next() returns the next object in iter and advances iter.
 void remove()
          iter.remove() removes the last object returned by iter.next() from its underlying collection (not supported).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FilteredIterator

public FilteredIterator(java.util.Collection c,
                        Filter fltr)
new FilteredIterator(c, fltr) returns a new filtered iterator whose base iterator is a default iterator for c and whose filter is fltr.

FilteredIterator

public FilteredIterator(java.util.Iterator baseIt,
                        Filter fltr)
new FilteredIterator(baseIt, fltr) returns a new filtered iterator whose base iterator is baseIt and whose filter is fltr.
Method Detail

hasNext

public boolean hasNext()
iter.hasNext() returns true if there is another object in iter.
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
iter.next() returns the next object in iter and advances iter.
Specified by:
next in interface java.util.Iterator

remove

public void remove()
iter.remove() removes the last object returned by iter.next() from its underlying collection (not supported). This operation is not supported by filtered iterators due to inadequacy of the iterator interface.
Specified by:
remove in interface java.util.Iterator

findNextAcceptableItem

protected void findNextAcceptableItem()
findNextAcceptableItem() advances the base iterator to the next item that is accepted by the filter, if there is one. The item is recorded in nextAcceptableItem and hasAnother is set to true if there is a next acceptable item.