SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

serp.util
Class LookaheadIterator

java.lang.Object
  |
  +--serp.util.LookaheadIterator
All Implemented Interfaces:
Iterator

public abstract class LookaheadIterator
extends Object
implements Iterator

Iterator type used that looks ahead one element to allow dynamic removal of invalid elements from iteration. The use of this class is perhaps best illustrated by an example from within this package. The ReferenceCollection type uses this iterator type to ensure that references that have expired are not returned to the user.

The Jakarta project's Commons Collections module contains a FilterIterator that is similar to this iterator type, but does not support the Iterator.remove() method.

Note that the remove() method takes linear time, as a new iterator must be fetched and iterated to 1 behind the present position before the change is applied.


Inner Class Summary
static class LookaheadIterator.ItrValue
          This struct holds information about an item to return from the iterator.
 
Constructor Summary
LookaheadIterator()
           
 
Method Summary
 Iterator getIterator()
          Return the internal iterator.
 boolean hasNext()
           
protected abstract  Iterator newIterator()
          Implement this method to return an iterator over the actual elements of the collection.
 Object next()
           
protected abstract  void processValue(LookaheadIterator.ItrValue val)
          Implement this method to properly setup the given LookaheadIterator.ItrValue instance.
 void remove()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookaheadIterator

public LookaheadIterator()
Method Detail

getIterator

public Iterator getIterator()
Return the internal iterator. Note that this iterator changes after calls to remove().

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator

next

public Object next()
Specified by:
next in interface Iterator

remove

public void remove()
Specified by:
remove in interface Iterator

newIterator

protected abstract Iterator newIterator()
Implement this method to return an iterator over the actual elements of the collection. If the remove() method is not overridden, this method may be called multiple times and should return a new iterator placed at the beginning of the collection each time.

processValue

protected abstract void processValue(LookaheadIterator.ItrValue val)
Implement this method to properly setup the given LookaheadIterator.ItrValue instance. The LookaheadIterator.ItrValue.value field will be set with the last value returned by the internal iterator given by newIterator(). This value can be replaced if desired to return some other value on iteration. Or, set the LookaheadIterator.ItrValue.valid field to false to skip this value in the iteration.

SolarMetric Kodo JDO 2.5.8 generated on January 11 2004

Copyright 2001,2002,2003 SolarMetric, Inc. All Rights Reserved.