Class Operator

java.lang.Object
com.fathzer.soft.javaluator.Operator

public class Operator extends Object
  • Constructor Details

    • Operator

      public Operator(String symbol, int operandCount, Operator.Associativity associativity, int precedence)
      Constructor.
      Parameters:
      symbol - The operator name (Currently, the name's length must be one character).
      operandCount - The number of operands of the operator (must be 1 or 2).
      associativity - The associativity of the operator.
      precedence - The precedence of the operator.
      The precedence is the priority of the operator. An operator with an higher precedence will be executed before an operator with a lower precedence. Example : In "1+3*4" * has a higher precedence than +, so the expression is interpreted as 1+(3*4).
      Throws:
      IllegalArgumentException - if operandCount if not 1 or 2, or if associativity is Operator.Associativity.NONE or null, or if symbol is null, empty or starts/ends with a space character.
  • Method Details

    • getSymbol

      public String getSymbol()
      Gets the operator's symbol.
      Returns:
      a String
    • getOperandCount

      public int getOperandCount()
      Gets the operator's operand count.
      Returns:
      an integer
    • getAssociativity

      public Operator.Associativity getAssociativity()
      Gets this operator's associativity.
      Returns:
      true if the operator is left associative.
      See Also:
    • getPrecedence

      public int getPrecedence()
      Gets the operator's precedence.
      Returns:
      an integer
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object