Package com.singularsys.jep.walkers

# Class TreeAnalyzer

java.lang.Object
com.singularsys.jep.walkers.PostfixTreeWalker
com.singularsys.jep.walkers.TreeAnalyzer

public class TreeAnalyzer extends PostfixTreeWalker
Analyze an expression, counting the number of nodes of each type, and recording which variables, functions and operators occurred in the expression.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TreeAnalyzer()`
  Creates an empty tree analyser.
  `TreeAnalyzer(Node node)`
  Create a new instance and Analyze the node.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `analyze(Node node)`
  Analyze a node, results will be added to the current total.
  `Map<Object,Integer>`
  `getConstants()`
  A map with each constant and the number of times it occurs
  `Map<String,Integer>`
  `getFunctions()`
  A map with each function used and the number of times it occurred
  `int`
  `getMaxDepth()`
  The depth of the tree
  `int`
  `getNumConst()`
  `int`
  `getNumFunctions()`
  `int`
  `getNumNodes()`
  `int`
  `getNumOperators()`
  `int`
  `getNumUniqueVariables()`
  `int`
  `getNumVariables()`
  `Map<Operator,Integer>`
  `getOperators()`
  A map with each operator used and the number of times it occurred
  `String[]`
  `getVariableNames()`
  Return the names of the variables, sorted alphabetically.
  `Map<Variable,Integer>`
  `getVariables()`
  A map with each variable used and the number of times it occurred
  `void`
  `merge(TreeAnalyzer ta)`
  Merge the result with the argument, producing total for all trees.
  `String`
  `summary()`
  A short summary string
  `String`
  `toString()`
  Reports statistics about the tree, number of nodes, depth, and the number of variables, functions, operators and constants with the number of times each occurs.
  `protected void`
  `visit(ASTConstant node, int nchildren, int depth)`
  Visit a constant node
  `protected void`
  `visit(ASTFunNode node, int nchildren, int depth)`
  Visit a function node
  `protected void`
  `visit(ASTOpNode node, int nchildren, int depth)`
  Visit an operator node
  `protected void`
  `visit(ASTVarNode node, int nchildren, int depth)`
  Visit a variable node

  ### Methods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker

  `suppressExaminingChildren, walk, walkSubEquations`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### TreeAnalyzer

    public TreeAnalyzer(Node node) throws JepException
    Create a new instance and Analyze the node.
    Parameters:
      `node` - node to analyze
    Throws:
      `JepException`

  - ### TreeAnalyzer

    public TreeAnalyzer()
    Creates an empty tree analyser. Useful for producing combined statistics via the `merge(TreeAnalyzer)` method.

- ## Method Details

  - ### analyze

    public void analyze(Node node) throws JepException
    Analyze a node, results will be added to the current total.
    Parameters:
      `node` -
    Throws:
      `JepException`

  - ### toString

    public String toString()
    Reports statistics about the tree, number of nodes, depth, and the number of variables, functions, operators and constants with the number of times each occurs.
    Overrides:
      `toString` in class `Object`

  - ### summary

    public String summary()
    A short summary string
    Returns:
      a one line summary

  - ### visit

    protected void visit(ASTFunNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a function node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTOpNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit an operator node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTVarNode node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a variable node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### visit

    protected void visit(ASTConstant node, int nchildren, int depth)
    Description copied from class: `PostfixTreeWalker`
    Visit a constant node
    Specified by:
      `visit` in class `PostfixTreeWalker`
    Parameters:
      `node` - the current node being visited
      `nchildren` - number of children of the node
      `depth` - depth of tree, root node is depth 1.

  - ### getMaxDepth

    public int getMaxDepth()
    The depth of the tree
    Returns:
      depth, depth of root node is 1

  - ### getNumConst

    public int getNumConst()

  - ### getNumFunctions

    public int getNumFunctions()

  - ### getNumNodes

    public int getNumNodes()

  - ### getNumOperators

    public int getNumOperators()

  - ### getNumVariables

    public int getNumVariables()

  - ### getNumUniqueVariables

    public int getNumUniqueVariables()

  - ### getOperators

    public Map<Operator,Integer> getOperators()
    A map with each operator used and the number of times it occurred
    Returns:
      a map whose keys are the operators and the values are the number of occurrences

  - ### getVariables

    public Map<Variable,Integer> getVariables()
    A map with each variable used and the number of times it occurred
    Returns:
      a map whose keys are the variables and the values are the number of occurrences

  - ### getVariableNames

    public String[] getVariableNames()
    Return the names of the variables, sorted alphabetically.
    Returns:
      an array of variable names

  - ### getFunctions

    public Map<String,Integer> getFunctions()
    A map with each function used and the number of times it occurred

  - ### getConstants

    public Map<Object,Integer> getConstants()
    A map with each constant and the number of times it occurs

  - ### merge

    public void merge(TreeAnalyzer ta)
    Merge the result with the argument, producing total for all trees.
    Parameters:
      `ta` -