public final class BinaryOperation extends AbstractExpression
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.
|
| Constructor and Description |
|---|
BinaryOperation(MathContext mathContext,
BinaryOperation.Op op,
Expression left,
Expression right)
Creates a new binary operator for the given operator and operands.
|
| Modifier and Type | Method and Description |
|---|---|
BigDecimal |
evaluate(MathContext mathContext)
Evaluates the expression to a BigDecimal 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.
|
static BigDecimal |
pow(BigDecimal x,
BigDecimal y,
MathContext mathContext)
power function which uses the JRE's
BigDecimal.pow(int, MathContext) when y is an integer
within range. |
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(MathContext mathContext)
Returns a simplified version of this expression.
|
String |
toString() |
getMathContextclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitevaluate, isConstantpublic BinaryOperation(MathContext mathContext, BinaryOperation.Op op, Expression left, Expression right)
mathContext - the math contextop - the operator of the operationleft - the left operandright - the right operandpublic static BigDecimal pow(BigDecimal x, BigDecimal y, MathContext mathContext)
BigDecimal.pow(int, MathContext) when y is an integer
within range. Otherwise use BigDecimalMath.pow(BigDecimal, BigDecimal, MathContext).x - the BigDecimal value to take to the powery - the BigDecimal value to serve as exponentmathContext - the MathContext used for the resultmathContextpublic 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 BigDecimal evaluate(MathContext mathContext)
ExpressionmathContext - Use this math context during calculation instead of the one provided during parsing. Does not
affect already simplified subexpressions.public Expression simplify(MathContext mathContext)
ExpressionmathContext - Match context used during simplification.Copyright © 2019. All rights reserved.