public class BinaryOperation extends Object implements Expression
A binary operation has two sub-expressions. A set of supported operations is also defined. If both arguments are constant, simplifying this expression will again lead to a constant expression.
Modifier and Type | Class and Description |
---|---|
static class |
BinaryOperation.Op
Enumerates the operations supported by this expression.
|
Modifier and Type | Field and Description |
---|---|
static double |
EPSILON
When comparing two double values, those are considered equal, if their difference is lower than the defined
epsilon.
|
Constructor and Description |
---|
BinaryOperation(BinaryOperation.Op op,
Expression left,
Expression right)
Creates a new binary operator for the given operator and operands.
|
Modifier and Type | Method and Description |
---|---|
double |
evaluate()
Evaluates the expression to a double number.
|
Expression |
getLeft()
Returns the left operand
|
BinaryOperation.Op |
getOp()
Returns the operation performed by this binary operation.
|
Expression |
getRight()
Returns the right operand
|
boolean |
isSealed()
Determines if the operation is sealed and operands must not be re-ordered.
|
void |
seal()
Marks an operation as sealed, meaning that re-ordering or operations on the same level must not be re-ordered.
|
void |
setLeft(Expression left)
Replaces the left operand of the operation with the given expression.
|
Expression |
simplify()
Returns a simplified version of this expression.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isConstant
public static final double EPSILON
public BinaryOperation(BinaryOperation.Op op, Expression left, Expression right)
op
- the operator of the operationleft
- the left operandright
- the right operandpublic BinaryOperation.Op getOp()
public Expression getLeft()
public void setLeft(Expression left)
left
- the new expression to be used as left operandpublic Expression getRight()
public void seal()
Binary operations are sealed if they're e.g. surrounded by braces.
public boolean isSealed()
public double evaluate()
Expression
evaluate
in interface Expression
public Expression simplify()
Expression
simplify
in interface Expression
Copyright © 2020. All rights reserved.