public abstract class Operator extends Object
| Modifier and Type | Field and Description |
|---|---|
static char[] |
ALLOWED_OPERATOR_CHARS
The set of allowed operator chars
|
static int |
PRECEDENCE_ADDITION
The precedence value for the addition operation
|
static int |
PRECEDENCE_DIVISION
The precedence value for the division operation
|
static int |
PRECEDENCE_MODULO
The precedence value for the modulo operation
|
static int |
PRECEDENCE_MULTIPLICATION
The precedence value for the multiplication operation
|
static int |
PRECEDENCE_POWER
The precedence value for the power operation
|
static int |
PRECEDENCE_SUBTRACTION
The precedence value for the subtraction operation
|
static int |
PRECEDENCE_UNARY_MINUS
The precedence value for the unary minus operation
|
static int |
PRECEDENCE_UNARY_PLUS
The precedence value for the unary plus operation
|
| Constructor and Description |
|---|
Operator(String symbol,
int numberOfOperands,
boolean leftAssociative,
int precedence)
Create a new operator for use in expressions
|
| Modifier and Type | Method and Description |
|---|---|
abstract double |
apply(double... args)
Apply the operation on the given operands
|
int |
getNumOperands()
Get the number of operands
|
int |
getPrecedence()
Check the precedence value for the operator
|
String |
getSymbol()
Get the operator symbol
|
static boolean |
isAllowedOperatorChar(char ch)
Check if a character is an allowed operator char
|
boolean |
isLeftAssociative()
Check if the operator is left associative
|
public static final int PRECEDENCE_ADDITION
public static final int PRECEDENCE_SUBTRACTION
public static final int PRECEDENCE_MULTIPLICATION
public static final int PRECEDENCE_DIVISION
public static final int PRECEDENCE_MODULO
public static final int PRECEDENCE_POWER
public static final int PRECEDENCE_UNARY_MINUS
public static final int PRECEDENCE_UNARY_PLUS
public static final char[] ALLOWED_OPERATOR_CHARS
public Operator(String symbol, int numberOfOperands, boolean leftAssociative, int precedence)
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 operatorpublic static boolean isAllowedOperatorChar(char ch)
ch - the char to checkpublic boolean isLeftAssociative()
public int getPrecedence()
public abstract double apply(double... args)
args - the operands for the operationpublic String getSymbol()
public int getNumOperands()
DMelt 2.0 © DataMelt by jWork.ORG