mondrian.olap
Class Walker

java.lang.Object
  extended by mondrian.olap.Walker
All Implemented Interfaces:
java.util.Enumeration

public class Walker
extends java.lang.Object
implements java.util.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.

If the tree is modified during the enumeration, strange things may happen.

Example use:

    Tree t;
    Walker w = new Walker(t);
    while (w.hasMoreElements()) {
      Tree node = (Tree) w.nextNode();
      System.out.println(node.toString());
    }
 


Constructor Summary
Walker(Walkable root)
           
 
Method Summary
 java.lang.Object currentElement()
          returns the current object.
 java.lang.Object getAncestor(int iDepth)
           
 int getAncestorOrdinal(int iDepth)
          get the ordinal within its parent node of the iDepthth ancestor.
 java.lang.Object[] getChildren(java.lang.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.
 java.lang.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(java.lang.String[] args)
           
 java.lang.Object nextElement()
           
 void prune()
          Tell walker that we don't want to visit any (more) children of this node.
 void pruneSiblings()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Walker

public Walker(Walkable root)
Method Detail

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface java.util.Enumeration

nextElement

public java.lang.Object nextElement()
Specified by:
nextElement in interface java.util.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()

currentElement

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


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.


getParent

public final java.lang.Object getParent()

getAncestor

public final java.lang.Object getAncestor(int iDepth)

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).


getAncestorOrdinal

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


getChildren

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


main

public static void main(java.lang.String[] args)

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads