com.sri.oaa2.icl
Class IclTermTraverser

java.lang.Object
  |
  +--com.sri.oaa2.icl.IclTermTraverser

public abstract class IclTermTraverser
extends java.lang.Object

An abstract class for doing depth first traversal of an IclTerm. This is an alternative to the Visitor pattern that exists in the IclTerm class. To use it, just create a subclass and provide the discover(IclTerm) and finish(IclTerm) methods. The discover method is called when an IclTerm is first encountered, and the finish method is called when all the children of an IclTerm have been finished. Given an IclTerm t, if t.isAtomic() is true, then finish() will be called immediately after discover() has been called.

Implementation wise, this is faster than a standard recursive traversal, since existing implementations of Java don't handle recursion well.

For an example of using this class, look at the source for GenerateManualConstruction. ToString does something similar, but much more specialized.


Constructor Summary
IclTermTraverser()
           
 
Method Summary
abstract  boolean discover(IclTerm t)
          Called when an IclTerm is first visited.
abstract  boolean finish(IclTerm t)
          Called when an IclTerm's children have all been visited.
 void traverse(IclTerm t)
          Perform a traversal on the given IclTerm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IclTermTraverser

public IclTermTraverser()
Method Detail

discover

public abstract boolean discover(IclTerm t)
Called when an IclTerm is first visited.

Parameters:
t - The IclTerm that was discovered.
Returns:
boolean false to stop the traversal and true otherwise

finish

public abstract boolean finish(IclTerm t)
Called when an IclTerm's children have all been visited.

Parameters:
t - The IclTerm that was finished.
Returns:
boolean false to stop the traversal and true otherwise

traverse

public final void traverse(IclTerm t)
Perform a traversal on the given IclTerm.

Parameters:
t - The IclTerm to traverse.