blog
Class AbstractObjectIterator

java.lang.Object
  extended by blog.AbstractObjectIterator
All Implemented Interfaces:
ObjectIterator, java.util.Iterator

public abstract class AbstractObjectIterator
extends java.lang.Object
implements ObjectIterator

Abstract implementation of the ObjectIterator interface. Subclasses must implement the findNext method, and may also implement skipAfterNext.


Field Summary
protected  boolean canDetermineNext
          Should be set to false by findNext when the next object cannot be determined.
 
Constructor Summary
AbstractObjectIterator()
           
 
Method Summary
 boolean canDetermineNext()
          Returns true if this ObjectIterator is running on a partial world that is complete enough to determine whether there is a next object, and if so, what that object is.
protected abstract  java.lang.Object findNext()
          Returns the next object to be returned by this iterator, or null if there are no more objects.
 boolean hasNext()
           
 java.lang.Object next()
           
 void remove()
           
protected  int skipAfterNext()
          Behaves like skipIndistinguishable, except it can assume that this call to skipIndistinguishable comes immediately after a successful call to next, with no intervening calls to findNext or any other methods.
 int skipIndistinguishable()
          Skips remaining objects that are indistinguishable from the object returned by the last call to next.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canDetermineNext

protected boolean canDetermineNext
Should be set to false by findNext when the next object cannot be determined.

Constructor Detail

AbstractObjectIterator

public AbstractObjectIterator()
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Specified by:
next in interface java.util.Iterator

remove

public void remove()
Specified by:
remove in interface java.util.Iterator

skipIndistinguishable

public int skipIndistinguishable()
Description copied from interface: ObjectIterator
Skips remaining objects that are indistinguishable from the object returned by the last call to next. Two objects are indistinguishable if the underlying partial world implies that they both satisfy the same POP application, neither one serves as a value or argument for any instantiated basic random variable, and neither one occurs in the set of "externally distinguished" objects passed to the iterator call that produced this iterator. Typically, the externally distinguished objects are the values of logical variables in the current scope.

This method can only be called immediately after a call to next: that is, there can be no intervening calls to any methods on this iterator. Even calling hasNext may cause some implementations to lose internal state that is necessary for skipping indistinguishable objects.

Specified by:
skipIndistinguishable in interface ObjectIterator
Returns:
the number of objects skipped (may be zero). The return value is always zero if canDetermineNext would return false.

canDetermineNext

public boolean canDetermineNext()
Description copied from interface: ObjectIterator
Returns true if this ObjectIterator is running on a partial world that is complete enough to determine whether there is a next object, and if so, what that object is. If hasNext is called when canDetermineNext would return false, then hasNext returns false.

Specified by:
canDetermineNext in interface ObjectIterator

skipAfterNext

protected int skipAfterNext()
Behaves like skipIndistinguishable, except it can assume that this call to skipIndistinguishable comes immediately after a successful call to next, with no intervening calls to findNext or any other methods.

This default implementation just returns zero.


findNext

protected abstract java.lang.Object findNext()
Returns the next object to be returned by this iterator, or null if there are no more objects. If the next object cannot be determined, this method sets the protected field canDetermineNext to false and returns null.

This method will not be called when canDetermineNext is false. However, it may be called again after it has returned null, in which case it should just return null again.