net.sf.saffron.util
Class Walker

java.lang.Object
  |
  +--net.sf.saffron.util.Walker
All Implemented Interfaces:
Enumeration

public class Walker
extends Object
implements Enumeration

Walks over a tree, returning nodes in prefix order. Objects which are an instance of Walkable supply their children using getChildren(); other objects are assumed to have no children. Do not modify the tree during the enumeration. Example use:Tree t; Walker w = new Walker(t); while (w.hasMoreElements()) { Tree node = (Tree) w.nextNode(); System.out.println(node.toString()); }


Nested Class Summary
(package private)  class Walker.Frame
           
private static class Walker.Region
           
 
Field Summary
(package private)  Walker.Frame currentFrame
           
(package private)  Object nextNode
           
(package private)  Stack stack
           
 
Constructor Summary
Walker(Walkable root)
           
 
Method Summary
private static int arrayFind(Object[] array, Object o)
           
 Object currentElement()
          returns the current object.
 Object getAncestor(int iDepth)
           
private  Walker.Frame getAncestorFrame(int iDepth)
          returns the iDepthth ancestor of the current element
 int getAncestorOrdinal(int iDepth)
          get the ordinal within its parent node of the iDepthth ancestor.
 Object[] getChildren(Object node)
          Override this function to prune the tree, or to allow objects which are not Walkable to have children.
 int getOrdinal()
          get the ordinal within its parent node of the current node.
 Object getParent()
           
 boolean hasMoreElements()
           
 int level()
          returns level in the tree of the current element (that is, last element returned from nextElement()).
static void main(String[] args)
           
private  void moveToNext()
           
 Object nextElement()
           
 void prune()
          Tell walker that we don't want to visit any (more) children of this node.
 void pruneSiblings()
           
private  void visit(Walker.Frame parent, Object node)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentFrame

Walker.Frame currentFrame

nextNode

Object nextNode

stack

Stack stack
Constructor Detail

Walker

public Walker(Walkable root)
Method Detail

getAncestor

public final Object getAncestor(int iDepth)

getParent

public final Object getParent()

getAncestorOrdinal

public int getAncestorOrdinal(int iDepth)
get the ordinal within its parent node of the iDepthth ancestor.


getChildren

public Object[] getChildren(Object node)
Override this function to prune the tree, or to allow objects which are not Walkable to have children.


getOrdinal

public int getOrdinal()
get the ordinal within its parent node of the current node. Returns 0 for the root element. Equivalent to getAncestorOrdinal(0).


currentElement

public Object currentElement()
returns the current object. Not valid until nextElement() has been called.


hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface Enumeration

level

public int level()
returns level in the tree of the current element (that is, last element returned from nextElement()). The level of the root element is 0.


main

public static void main(String[] args)

nextElement

public Object nextElement()
Specified by:
nextElement in interface Enumeration

prune

public void prune()
Tell walker that we don't want to visit any (more) children of this node. The next node visited will be (a return visit to) the node's parent. Not valid until nextElement() has been called.


pruneSiblings

public void pruneSiblings()

getAncestorFrame

private Walker.Frame getAncestorFrame(int iDepth)
returns the iDepthth ancestor of the current element


arrayFind

private static int arrayFind(Object[] array,
                             Object o)

moveToNext

private void moveToNext()

visit

private void visit(Walker.Frame parent,
                   Object node)

SourceForge.net_Logo