ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.filespace
Class LookAheadEnum

java.lang.Object
  extended byjavafe.filespace.LookAheadEnum
All Implemented Interfaces:
java.util.Enumeration
Direct Known Subclasses:
FilterEnum, TreeWalker, TreeWalker_ArrayEnum

abstract class LookAheadEnum
extends java.lang.Object
implements java.util.Enumeration

This layer describes how to implement an Enumeration in terms of a single function that returns the next element in a series, or null if the series is exhausted.

Using one function instead of the two used by Enumeration has the advantage of avoiding possible duplication of code to determine whether or not any elements remain in the series.

Limitation: null cannot belong to the resulting Enumerations.


Field Summary
private  java.lang.Object lookAhead
           
private  boolean lookAheadValid
           
 
Constructor Summary
LookAheadEnum()
          Create an look-ahead enumerator that will return the non-null results of calcNextElement().
LookAheadEnum(java.lang.Object first)
          Create a look-ahead enumerator that will return first followed by the non-null results of calcNextElement().
 
Method Summary
protected abstract  java.lang.Object calcNextElement()
          Compute the next element in the series, or return null if the series is exhausted.
private  void ensureLookedAhead()
          Ensure that lookAheadValid is set, calling calcNextElement if needed.
 boolean hasMoreElements()
           
 java.lang.Object nextElement()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lookAheadValid

private boolean lookAheadValid

lookAhead

private java.lang.Object lookAhead
Constructor Detail

LookAheadEnum

public LookAheadEnum()
Create an look-ahead enumerator that will return the non-null results of calcNextElement().


LookAheadEnum

public LookAheadEnum(java.lang.Object first)
Create a look-ahead enumerator that will return first followed by the non-null results of calcNextElement().

Method Detail

ensureLookedAhead

private void ensureLookedAhead()
Ensure that lookAheadValid is set, calling calcNextElement if needed.


hasMoreElements

public final boolean hasMoreElements()
Specified by:
hasMoreElements in interface java.util.Enumeration
Returns:
true iff any more elements exist in this enumeration.

nextElement

public final java.lang.Object nextElement()
Specified by:
nextElement in interface java.util.Enumeration

calcNextElement

protected abstract java.lang.Object calcNextElement()
Compute the next element in the series, or return null if the series is exhausted. This function will never be called again once it returns null.


ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage