Class Counter


public class Counter extends Visitor
Counter is a visitor that counts the numbers, operations, and depth in an arithmetic expression.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the depth.
    int
    Gets the number of numbers.
    int
    Gets the number of operations.
    void
    The Visitor can traverse a Complex number (a subtype of Expression)
    void
    The Visitor can traverse an Integer (a subtype of Expression)
    void
    The Visitor can traverse a Rationnal number (a subtype of Expression)
    void
    The Visitor can traverse a Real number (a subtype of Expression)
    void
    The Visitor can traverse a binary function (a subtype of Expression)
    void
    The Visitor can traverse an unary function (a subtype of Expression)
    void
    Visit an operation: increments the operation count, then recursively visits all child expressions to accumulate counts.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Counter

      public Counter()
      Default constructor.
  • Method Details

    • visit

      public void visit(Real r)
      Description copied from class: Visitor
      The Visitor can traverse a Real number (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      r - The Real number being visited
    • visit

      public void visit(IntegerAtom i)
      Description copied from class: Visitor
      The Visitor can traverse an Integer (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      i - The operation being visited
    • visit

      public void visit(Complex c)
      Description copied from class: Visitor
      The Visitor can traverse a Complex number (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      c - The Real number being visited
    • visit

      public void visit(Rationnal q)
      Description copied from class: Visitor
      The Visitor can traverse a Rationnal number (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      q - The Real number being visited
    • visit

      public void visit(Operation o)
      Visit an operation: increments the operation count, then recursively visits all child expressions to accumulate counts.
      Specified by:
      visit in class Visitor
      Parameters:
      o - The operation being visited
    • visit

      public void visit(UnaryFunction o)
      Description copied from class: Visitor
      The Visitor can traverse an unary function (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      o - The unary function being visited
    • visit

      public void visit(BinaryFunction f)
      Description copied from class: Visitor
      The Visitor can traverse a binary function (a subtype of Expression)
      Specified by:
      visit in class Visitor
      Parameters:
      f - The binary function being visited
    • getNbOps

      public int getNbOps()
      Gets the number of operations.
      Returns:
      The number of operations in the expression
    • getNbNbs

      public int getNbNbs()
      Gets the number of numbers.
      Returns:
      The number of numbers in the expression
    • getDepth

      public int getDepth()
      Gets the depth.
      Returns:
      The depth (0 for a number, 1 for a simple operation, etc.)