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