Class AbstractVisitor<T,R>

java.lang.Object
io.openml.gearbox.binarytree.traversal.AbstractVisitor<T,R>
Type Parameters:
T - The type of value stored in the node
R - The type of object to be computed via a visiting the tree, see getTraversalResult()
All Implemented Interfaces:
Function<TreeNode<T>,R>
Direct Known Subclasses:
AbstractInOrderVisitor, AbstractPostOrderVisitor, AbstractPreOrderVisitor

@Deprecated public abstract class AbstractVisitor<T,R> extends Object implements Function<TreeNode<T>,R>
Deprecated.
AbstractInOrderVisitor reflects an obsolete implementation that doesn't strictly bind the principle of Visitor pattern. Please use the enhanced TreeTraverser
AbstractVisitor represents the notion of iteratively reading a binary tree.

It offers 3 common operations that can be shared across implementations

  1. get reading result
  2. perform actions on each visited node
  3. early return
  • Constructor Details

    • AbstractVisitor

      public AbstractVisitor()
      Deprecated.
  • Method Details

    • getTraversalResult

      protected abstract R getTraversalResult()
      Deprecated.
      Returns the final result computed after visiting tree (either all-node visit or partial visit)

      For example, this method can return the max node value of entire tree after iterating through all tree nodes.

      Returns:
      object computed by a complete or partial traversal
    • visitNode

      protected abstract void visitNode(TreeNode<T> node)
      Deprecated.
      Performs actions on each visited node during traversal.
      Parameters:
      node - Node on which the action is performed against
    • canTerminate

      protected abstract boolean canTerminate()
      Deprecated.
      Returns whether or not the traversal should terminate early and call getTraversalResult() right after.

      For example, this could be useful while searching a tree for a target

            1
          /  \
         2   3
        / \   \
       4  5   6
       
      Suppose we are searching for node 2 in the tree above. canTerminate() can be implemented as
       
       if (node.value == 2) {
           return true
       } else {
           return false
       }
       
       
      Returns:
      true if traversal result is already publishable.