Class UnaryFunction

java.lang.Object
calculator.functions.UnaryFunction
All Implemented Interfaces:
Expression
Direct Known Subclasses:
Arccosinus, Arcsinus, Arctangente, Cosh, Cosinus, Ln, Sinh, Sinus, Sqrt, Tangente, Tanh

public abstract class UnaryFunction extends Object implements Expression
UnaryFunction is an abstract class that represents unary arithmetic operations, which are a special kind of Expressions, just like binary operations are.
  • Field Details

    • arg

      public Expression arg
      The expression passed as an argument to the arithmetic operation
    • symbol

      protected String symbol
      The character/string used to represent the arithmetic operation (e.g. "cos")
  • Constructor Details

    • UnaryFunction

      protected UnaryFunction(Expression arg) throws IllegalConstruction
      To construct a unary operation with an expression as argument
      Parameters:
      arg - The expression passed as argument to the arithmetic operation
      Throws:
      IllegalConstruction - Exception thrown if a null argument is passed
  • Method Details

    • getArg

      public Expression getArg()
      getter method to return the argument of an arithmetic operation.
      Returns:
      The argument of the arithmetic operation.
    • getSymbol

      public String getSymbol()
      getter method to return the symbol of the arithmetic operation.
      Returns:
      The symbol of the arithmetic operation.
    • op

      public abstract Real op(Real r)
    • op

      public abstract Complex op(Complex c)
    • op

      public abstract IntegerAtom op(IntegerAtom i)
    • op

      public abstract Rationnal op(Rationnal q)
    • accept

      public void accept(Visitor v)
      Accept method to implement the visitor design pattern to traverse arithmetic expressions.
      Specified by:
      accept in interface Expression
      Parameters:
      v - The visitor object
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toString

      public final String toString(Notation n)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object