Package com.fathzer.soft.javaluator
Class Operator
java.lang.Object
com.fathzer.soft.javaluator.Operator
An operator.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionOperator(String symbol, int operandCount, Operator.Associativity associativity, int precedence) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets this operator's associativity.intGets the operator's operand count.intGets the operator's precedence.Gets the operator's symbol.inthashCode()
-
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 isOperator.Associativity.NONEor null, or if symbol is null, empty or starts/ends with a space character.
-
-
Method Details
-
getSymbol
Gets the operator's symbol.- Returns:
- a String
-
getOperandCount
public int getOperandCount()Gets the operator's operand count.- Returns:
- an integer
-
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() -
equals
-