public abstract class BinaryOperation extends Expression
BinaryOperation
is an Expression
which
represents a mathematical binary operation (addition, subtraction,
multiplication, division or power operation) of two other
Expressions
(the operands).Modifier and Type | Field and Description |
---|---|
protected Expression |
operand1
This
BinaryOperation's first operand. |
protected Expression |
operand2
This
BinaryOperation's second operand. |
Constructor and Description |
---|
BinaryOperation(int type,
int pri)
Creates a new
BinaryOperation with the operation type
type and the evaluation priority pri . |
BinaryOperation(int type,
int pri,
Expression op1,
Expression op2)
Creates a new
BinaryOperation with the operation type
type , the evaluation priority pri and both
operands op1 and op2 . |
Modifier and Type | Method and Description |
---|---|
Expression |
dissolveFunctionCalls()
Inserts the arguments of any FunctionCall in the expression-tree-hierarchy
into the appropriate function definitions and replaces the FunctionCalls
by that new Expressions.
|
boolean |
equals(Object o)
Returns
true if the specified Object is a
BinaryOperation of the same operation type and with equal
operands, false otherwise. |
void |
getEssentialVariables(Collection c)
Adds the names of the
Variables which are essential for
evaluation into the specified Collection . |
Evaluator |
getEvaluator(Type defaultType,
Context context)
Returns the
Evaluator for this BinaryOperation . |
Expression |
getOperand1()
Returns the first operand of this
BinaryOperation or
null if there is no operand defined yet. |
Expression |
getOperand2()
Returns the second operand of this
BinaryOperation or
null if there is no operand defined yet. |
int |
getPriority()
Returns the evaluation priority of this
BinaryOperation . |
int |
getType()
Returns the operation type of this
BinaryOperation . |
boolean |
isComplete()
Returns
true if both operands of this
BinaryOperation are not null and also complete,
false otherwise. |
boolean |
isConstant()
Returns
true if both operands of this
BinaryOperation are not null and also constant,
false if not. |
Expression |
replaceSymbol(Symbol s,
Expression expr)
Replaces all Symbols equal to s in this BinaryOperation
with the specified Expression.
|
void |
setOperands(Expression op1,
Expression op2)
Sets the operands of this
BinaryOperation to the specified
Expressions . |
String |
toString()
Returns a
String representing this
BinaryOperation . |
differentiate, differentiate, getEssentialVariables, simplify
protected Expression operand1
BinaryOperation's
first operand.protected Expression operand2
BinaryOperation's
second operand.public BinaryOperation(int type, int pri)
BinaryOperation
with the operation type
type
and the evaluation priority pri
.
The operands of this BinaryOperation
will be
null
until you call the method setOperands(Expression,Expression)
. Use the other constructor, if
the operands are already known.type
- the operation type this BinaryOperation
will
represent.pri
- the evaluation priority this BinaryOperation
will
have.public BinaryOperation(int type, int pri, Expression op1, Expression op2)
BinaryOperation
with the operation type
type
, the evaluation priority pri
and both
operands op1
and op2
. Use the other
constructor if at least one of the operands is not known.type
- the operation type this BinaryOperation
will
represent.pri
- the evaluation priority this BinaryOperation
will
have.op1
- the first operand for this BinaryOperation
.op2
- the second operand for this BinaryOperation
.public Expression dissolveFunctionCalls()
Expression
dissolveFunctionCalls
in class Expression
Function.insertArguments(Expression)
public boolean equals(Object o)
true
if the specified Object
is a
BinaryOperation
of the same operation type and with equal
operands, false
otherwise.public void getEssentialVariables(Collection c)
Variables
which are essential for
evaluation into the specified Collection
. Therefor it gets the
essential Variables
of both operands of this
BinaryOperation
.getEssentialVariables
in class Expression
c
- the Collection
the Variable
names
will be added to.public Evaluator getEvaluator(Type defaultType, Context context)
Evaluator
for this BinaryOperation
.
Type defaultType
specifies, how to deal with
Symbols
in the expression-tree-hirarchy (evaluate any
Symbol
as a Complex
or a Real
or
whatever?). It has nothing to do with getType()
.getEvaluator
in class Expression
defaultType
- the Type
any Symbol
will be
evaluated to.context
- the Context
, the Evaluators for
the Symbols
are getting from.
Evaluator
for this BinaryOperation
.Evaluator.getReturnType()
,
Context.getEvaluator(Symbol)
public Expression getOperand1()
BinaryOperation
or
null
if there is no operand defined yet. Define the
operands with the appropriate constructor or with the method
setOperands(Expression, Expression)
.BinaryOperation
.public Expression getOperand2()
BinaryOperation
or
null
if there is no operand defined yet. Define the
operands with the appropriate constructor or with the method
setOperands(Expression, Expression)
.BinaryOperation
.public int getPriority()
BinaryOperation
.getPriority
in class Expression
BinaryOperation
.Parser.parse()
,
Expression.getEvaluator(Type,Context)
public int getType()
BinaryOperation
.
It's the ASCII-code of the following characters representing the
appropriate operation:BinaryOperation
.public boolean isComplete()
true
if both operands of this
BinaryOperation
are not null and also complete,
false
otherwise.isComplete
in class Expression
true
if both operands of this
BinaryOperation
are not null and also complete,
false
otherwise.public boolean isConstant()
true
if both operands of this
BinaryOperation
are not null and also constant,
false
if not.isConstant
in class Expression
true
if both operands of this
BinaryOperation
are not null and also constant,
false
if not.public Expression replaceSymbol(Symbol s, Expression expr)
replaceSymbol
in class Expression
s
- the Symbol to be replace.expr
- the Expression for replacement.Symbol.replaceSymbol(Symbol,Expression)
public void setOperands(Expression op1, Expression op2)
BinaryOperation
to the specified
Expressions
.op1
- the new first operand for this BinaryOperation
.op2
- the new second operand for this BinaryOperation
.