public class Symbol extends Expression
Symbol
is an Expression
which can be a number
(Constant
) or an identifier (Variable
). The state must be set by
any constructor and can't be changed.Symbol
represents an identifier
it must not be a Variable
in any case. It can be also a
certain static final Constant
, e.g.: Constant.PI
and Constant.E
.Constructor and Description |
---|
Symbol(double d)
Creates a new
Symbol , which represents a constant number
with the value d . |
Symbol(String s)
|
Modifier and Type | Method and Description |
---|---|
Expression |
differentiate(Symbol s)
Returns a Symbol with constant value 1 if this Symbol equals
s.
|
Expression |
dissolveFunctionCalls()
Returns this.
|
boolean |
equals(Object o)
Returns
true if the specified Object is a
Symbol representing the same constant number respectively
the same variable name, false otherwise. |
double |
getConstantValue()
Returns the constant double value this
Symbol is representing
if this Symbol is constant. |
void |
getEssentialVariables(Collection c)
|
Evaluator |
getEvaluator(Type defaultType,
Context context)
Returns the
Evaluator for this Symbol . |
protected int |
getPriority()
Returns a constant value, because a
Symbol must not have a
priority. |
int |
hashCode()
Returns a hash code for this
Symbol . |
boolean |
isComplete()
Returns
true whenever this method is called. |
boolean |
isConstant()
|
Expression |
replaceSymbol(Symbol s,
Expression expr)
Returns the specified expression, if this Symbol equals s.
|
Expression |
simplify()
Returns this Symbol because a Symbol itself can't be simplified.
|
String |
toString()
Returns the constant number respectively the variable name represented by
this
Symbol . |
differentiate, getEssentialVariables
public Symbol(double d)
Symbol
, which represents a constant number
with the value d
.d
- the constant double value this Symbol
will be
representing.getConstantValue()
public Symbol(String s)
s
- the name of the Variable
this Symbol
will be representing.public Expression differentiate(Symbol s)
differentiate
in class Expression
public Expression dissolveFunctionCalls()
dissolveFunctionCalls
in class Expression
Function.insertArguments(Expression)
public boolean equals(Object o)
true
if the specified Object
is a
Symbol
representing the same constant number respectively
the same variable name, false
otherwise.public double getConstantValue()
Symbol
is representing
if this Symbol
is constant. If this Symbol
represents a Variable
, this method throws an
IllegalStateException
.Symbol
is representing
if this Symbol
is constant.IllegalStateException
- if this Symbol
represents a
Variable
.isConstant()
public void getEssentialVariables(Collection c)
getEssentialVariables
in class Expression
c
- the Collection
the Variable
name
will be added to.public Evaluator getEvaluator(Type defaultType, Context context)
Evaluator
for this Symbol
.
Type defaultType
specifies, how to deal with this
Symbols
(evaluate it as a Complex
or a
Real
or whatever?).getEvaluator
in class Expression
defaultType
- the Type
any Symbol
will be
evaluated to.context
- the Context
, the Evaluator for
this Symbol
is getting from (in cases of representing a variable
and not a constant).
Evaluator
for this Symbol
.Evaluator.getReturnType()
,
Context.getEvaluator(Symbol)
protected int getPriority()
Symbol
must not have a
priority. A Symbol
can only be operand of operations which
have priorities.getPriority
in class Expression
-1
.Parser.parse()
,
Expression.getEvaluator(Type,Context)
public int hashCode()
Symbol
. It's the hash code from
the String
representing the constant number respectively
the variable name.hashCode
in class Object
Symbol
.String.hashCode()
public boolean isComplete()
true
whenever this method is called. As soon as a
Symbol
was instantiated (as a number or an identifier), it is
ready to get evaluated. It doesn't matter if the appropriate Variable
is defined or not. Thant is the task for the
Evaluator
.isComplete
in class Expression
true
.Context.getEvaluator(Symbol)
,
UnknownDefinitionException
public boolean isConstant()
true
if this Symbol
represents a constant
double value, false
if this Symbol
represents an
identifier of a Variable
or of a static final Constant
.isConstant
in class Expression
true
if this Symbol
represents a constant
double value, false
if this Symbol
represents an
identifier of a Variable
or of a static final Constant
.getConstantValue()
public Expression replaceSymbol(Symbol s, Expression expr)
replaceSymbol
in class Expression
s
- the Symbol to be replace.expr
- the Expression for replacement.equals(Object)
public Expression simplify()
simplify
in class Expression