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 TreeWalker

java.lang.Object
  extended byjavafe.filespace.LookAheadEnum
      extended byjavafe.filespace.TreeWalker
All Implemented Interfaces:
java.util.Enumeration

public final class TreeWalker
extends LookAheadEnum

This class provides a way to enumerate all the nodes of a given Tree in depth-first pre-order using lexical ordering on siblings. I.e., X preceeds X.A, which in turn preceeds X.B. The first node in the list will be the root note of the Tree. It also allows enumerating a Tree's direct children in sorted order (based on their labels).

Guarantee: Returned elements are always non-null Trees.


Field Summary
protected  java.util.Enumeration remainingChildren
          The remaining children we have yet to start processing:
protected  java.util.Enumeration remainingNodes
          The remaining nodes from the child we are currently processing:
 
Constructor Summary
TreeWalker(Tree T)
          From a Tree create an enumeration that enumerates all of the Tree's nodes (including the root node first).
 
Method Summary
protected  java.lang.Object calcNextElement()
          * Calculating the next element: * *
private static Tree[] getSortedChildren(Tree T)
          Return a sorted list of a Tree's direct children:
 boolean hasMoreElements()
           
static void main(java.lang.String[] args)
          A simple test driver.
 java.lang.Object nextElement()
           
private static void sort(Tree[] a)
           
static java.util.Enumeration sortedChildren(Tree T)
          Enumerate a Tree's direct children in sorted order (of labels).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

remainingChildren

protected java.util.Enumeration remainingChildren
The remaining children we have yet to start processing:


remainingNodes

protected java.util.Enumeration remainingNodes
The remaining nodes from the child we are currently processing:

Constructor Detail

TreeWalker

public TreeWalker(Tree T)
From a Tree create an enumeration that enumerates all of the Tree's nodes (including the root node first). The nodes are produced in depth-first lexical pre-order.

Method Detail

calcNextElement

protected java.lang.Object calcNextElement()
* Calculating the next element: * *

Specified by:
calcNextElement in class LookAheadEnum

sortedChildren

public static java.util.Enumeration sortedChildren(Tree T)
Enumerate a Tree's direct children in sorted order (of labels).

Guarantee: The resulting enumeration never yields null as an element.


getSortedChildren

private static Tree[] getSortedChildren(Tree T)
Return a sorted list of a Tree's direct children:


sort

private static void sort(Tree[] a)

main

public static void main(java.lang.String[] args)
A simple test driver.


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

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