public class Variable extends Object implements Evaluator
Variable
object represents a mathematical variable with a
name, value and a certain Type
. The Type
determines
what kind of Object
is used for the variable's value. It's
also necessary for evaluating this Variable
in relation to
other Evaluators
with different evaluation
Types
.
Expression
, all Symbols
, in
the expression-tree-hirarchy, which represent no constant numbers
respectively Constants
like "pi" or "e", must be defined
as a Variable
object with the same name the appropriate
Symbol
has.Modifier and Type | Field and Description |
---|---|
protected String |
name
The name of this
Variable . |
protected Type |
type
The
Type of this Variable . |
protected Object |
value
The value of this
Variable . |
Constructor and Description |
---|
Variable(String name,
Object value,
Type type)
Creates a new
Variable with the name name
the value value and the Type type . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Object |
evaluate()
Evaluates this
Variable by returning its value. |
String |
getName()
Returns the name of this
Variable . |
Type |
getReturnType()
Returns the
Type of this Variable's value. |
Object |
getValue()
Returns the value of this
Variable as an Object . |
void |
setValue(Object newVal)
Sets the value of this
Variable to the specified
Object . |
void |
setValue(Object newVal,
Type newType)
Sets the value of this
Variable to the specified
Object . |
String |
toString()
Returns a
String showing name and value of this
Variable in the following syntax: name=value . |
protected String name
Variable
.protected Type type
Type
of this Variable
.protected Object value
Variable
.public Object evaluate()
Variable
by returning its value.evaluate
in interface Evaluator
Variable
as an Object
.AbstractRealEvaluator.getRealValue(Real)
,
AbstractComplexEvaluator.getComplexValue(Complex)
,
AbstractRealVectorEvaluator.getRealVectorValue(RealVector)
,
AbstractComplexVectorEvaluator.getComplexVectorValue(ComplexVector)
public String getName()
Variable
. The name of a any
Variable
has to be defined by the constructor. A
Variable
can't be renamed.Variable
.public Type getReturnType()
Type
of this Variable's
value.getReturnType
in interface Evaluator
Type
of this Variable's
value.public Object getValue()
Variable
as an Object
.
The Type
of that Object
is returned by the
method getReturnType()
.Variable
.public void setValue(Object newVal)
Variable
to the specified
Object
. Use this method only if you are sure,
that the Type
of the new value is equal to the old
value Type
.newVal
- the new value for this Variable
.setValue(Object,Type)
public void setValue(Object newVal, Type newType)
Variable
to the specified
Object
. The specified Type
is the
Type
of newVal
. Use this method,
if the Type
of the new value differs from the old value
Type
.newVal
- the new value for this Variable
.newType
- the Type
of the new value.setValue(Object)