Package net.objecthunter.exp4j.operator
Class Operator
java.lang.Object
net.objecthunter.exp4j.operator.Operator
Class representing operators that can be used in an expression
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final char[]The set of allowed operator charsstatic final intThe precedence value for the addition operationstatic final intThe precedence value for the division operationstatic final intThe precedence value for the modulo operationstatic final intThe precedence value for the multiplication operationstatic final intThe precedence value for the power operationstatic final intThe precedence value for the subtraction operationstatic final intThe precedence value for the unary minus operationstatic final intThe precedence value for the unary plus operation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract doubleapply(double... args) Apply the operation on the given operandsintGet the number of operandsintCheck the precedence value for the operatorGet the operator symbolstatic booleanisAllowedOperatorChar(char ch) Check if a character is an allowed operator charbooleanCheck if the operator is left associative
-
Field Details
-
PRECEDENCE_ADDITION
public static final int PRECEDENCE_ADDITIONThe precedence value for the addition operation- See Also:
-
PRECEDENCE_SUBTRACTION
public static final int PRECEDENCE_SUBTRACTIONThe precedence value for the subtraction operation- See Also:
-
PRECEDENCE_MULTIPLICATION
public static final int PRECEDENCE_MULTIPLICATIONThe precedence value for the multiplication operation- See Also:
-
PRECEDENCE_DIVISION
public static final int PRECEDENCE_DIVISIONThe precedence value for the division operation- See Also:
-
PRECEDENCE_MODULO
public static final int PRECEDENCE_MODULOThe precedence value for the modulo operation- See Also:
-
PRECEDENCE_POWER
public static final int PRECEDENCE_POWERThe precedence value for the power operation- See Also:
-
PRECEDENCE_UNARY_MINUS
public static final int PRECEDENCE_UNARY_MINUSThe precedence value for the unary minus operation- See Also:
-
PRECEDENCE_UNARY_PLUS
public static final int PRECEDENCE_UNARY_PLUSThe precedence value for the unary plus operation- See Also:
-
ALLOWED_OPERATOR_CHARS
public static final char[] ALLOWED_OPERATOR_CHARSThe set of allowed operator chars
-
-
Constructor Details
-
Operator
Create a new operator for use in expressions- Parameters:
symbol- the symbol of the operatornumberOfOperands- the number of operands the operator takes (1 or 2)leftAssociative- set to true if the operator is left associative, false if it is right associativeprecedence- the precedence value of the operator
-
-
Method Details
-
isAllowedOperatorChar
public static boolean isAllowedOperatorChar(char ch) Check if a character is an allowed operator char- Parameters:
ch- the char to check- Returns:
- true if the char is allowed an an operator symbol, false otherwise
-
isLeftAssociative
public boolean isLeftAssociative()Check if the operator is left associative- Returns:
- true os the operator is left associative, false otherwise
-
getPrecedence
public int getPrecedence()Check the precedence value for the operator- Returns:
- the precedence value
-
apply
public abstract double apply(double... args) Apply the operation on the given operands- Parameters:
args- the operands for the operation- Returns:
- the calculated result of the operation
-
getSymbol
-
getNumOperands
public int getNumOperands()Get the number of operands- Returns:
- the number of operands
-