Package net.objecthunter.exp4j.operator
Class Operator
java.lang.Object
net.objecthunter.exp4j.operator.Operator
- All Implemented Interfaces:
Serializable
Class representing operators that can be used in an expression
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
This is the threshold used to considerfalse
values false, it has a default value of 1.0E-12static final int
The precedence value for the addition operation (default: 500)static final int
The precedence value for the boolean and (default: 200)static final int
The precedence value for the division operation (default: 1000)static final int
The precedence value for the modulo operation (default: 1000)static final int
The precedence value for the multiplication operation (default: 1000)static final int
The precedence value for the boolean not (default: 300)static final int
The precedence value for the boolean or (default: 100)static final int
The precedence value for the power operation (default: 10000)static final int
The precedence value for the subtraction operation (default: 500)static final int
The precedence value for the unary minus operation (default: 5000)static final int
The precedence value for the unary plus operation (default: 5000) -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract double
apply
(double... args) Apply the operation on the given operandsint
Get the number of operandsint
Check the precedence value for the operatorGet the operator symbolstatic boolean
isAllowedOperatorChar
(char ch) Check if a character is an allowed operator charboolean
Check if the operator is left associative
-
Field Details
-
PRECEDENCE_ADDITION
public static final int PRECEDENCE_ADDITIONThe precedence value for the addition operation (default: 500)- See Also:
-
PRECEDENCE_SUBTRACTION
public static final int PRECEDENCE_SUBTRACTIONThe precedence value for the subtraction operation (default: 500)- See Also:
-
PRECEDENCE_MULTIPLICATION
public static final int PRECEDENCE_MULTIPLICATIONThe precedence value for the multiplication operation (default: 1000)- See Also:
-
PRECEDENCE_DIVISION
public static final int PRECEDENCE_DIVISIONThe precedence value for the division operation (default: 1000)- See Also:
-
PRECEDENCE_MODULO
public static final int PRECEDENCE_MODULOThe precedence value for the modulo operation (default: 1000)- See Also:
-
PRECEDENCE_POWER
public static final int PRECEDENCE_POWERThe precedence value for the power operation (default: 10000)- See Also:
-
PRECEDENCE_UNARY_MINUS
public static final int PRECEDENCE_UNARY_MINUSThe precedence value for the unary minus operation (default: 5000)- See Also:
-
PRECEDENCE_UNARY_PLUS
public static final int PRECEDENCE_UNARY_PLUSThe precedence value for the unary plus operation (default: 5000)- See Also:
-
PRECEDENCE_NOT
public static final int PRECEDENCE_NOTThe precedence value for the boolean not (default: 300)- See Also:
-
PRECEDENCE_AND
public static final int PRECEDENCE_ANDThe precedence value for the boolean and (default: 200)- See Also:
-
PRECEDENCE_OR
public static final int PRECEDENCE_ORThe precedence value for the boolean or (default: 100)- See Also:
-
BOOLEAN_THRESHOLD
public static final double BOOLEAN_THRESHOLDThis is the threshold used to considerfalse
values false, it has a default value of 1.0E-12- See Also:
-
-
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 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
Get the operator symbol- Returns:
- the symbol
-
getNumOperands
public int getNumOperands()Get the number of operands- Returns:
- the number of operands
-