Algorithm
Development Kit 1.0

algs.model.kdtree
Class TwoDTraversal

java.lang.Object
  extended by algs.model.kdtree.TwoDTraversal
All Implemented Interfaces:
IVisitTwoDNode

public abstract class TwoDTraversal
extends java.lang.Object
implements IVisitTwoDNode

Defines a standard inorder traversal of the TwoDTree and enables subclasses to provide specialized method to take action at each node of the tree.

By referencing the tree, the traversal can be reused even when the tree is altered. Note, however, that altering the tree structure *during* a traversal will lead to non-determined behavior.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
protected TwoDTraversal()
          Default constructor to properly enable subclasses to work.
  TwoDTraversal(TwoDTree tree)
          Start traversal at the root.
 
Method Summary
 void drain(TwoDNode node)
          This drain is never invoked during the node-by-node traversal and it is implemented here to avoid subclasses from mistakenly thinking that they need to implement it.
 void traverse()
          Control the traversal of the entire Tree.
protected  void traverse(TwoDNode node)
          Traverse starting at this given node.
abstract  void visit(TwoDNode node)
          Specialized behavior will be placed here (when visiting node).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwoDTraversal

protected TwoDTraversal()
Default constructor to properly enable subclasses to work.


TwoDTraversal

public TwoDTraversal(TwoDTree tree)
Start traversal at the root.

Parameters:
tree - Need to know the tree to process the traversal.
Method Detail

traverse

protected void traverse(TwoDNode node)
Traverse starting at this given node.

node will never be null.

Parameters:
node -

visit

public abstract void visit(TwoDNode node)
Specialized behavior will be placed here (when visiting node).

Specified by:
visit in interface IVisitTwoDNode
Parameters:
node -

drain

public final void drain(TwoDNode node)
This drain is never invoked during the node-by-node traversal and it is implemented here to avoid subclasses from mistakenly thinking that they need to implement it. We mark this method as final to prevent such attempts.

Specified by:
drain in interface IVisitTwoDNode
Parameters:
node - Node to be drained, though this is never invoked during the traversal.

traverse

public void traverse()
Control the traversal of the entire Tree. Will visit each node in the tree


Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.