hussam.math.operations
Class Variable
java.lang.Object
hussam.math.operations.Variable
- All Implemented Interfaces:
- Operation, java.io.Serializable, java.lang.Cloneable
- Direct Known Subclasses:
- Constant
public class Variable
- extends java.lang.Object
- implements Operation
A Variable is an operation indicating a variable amount. A Variable has a name indicating a key mapping for the operation it stores.
- Since:
- 2.0
- Author:
- Hussam Almulhim حسام الملحم
- See Also:
Operation
, ConstantNumber
, Constant
, Function
, Serialized Form
Constructor Summary |
---|
Variable(java.lang.String name) Construcs a New Variable given the name. |
Method Summary |
---|
Variable | clone(OperatorSourceImpl s) Clones this Variable only if it is not contained in the operatorSource given. |
java.lang.String | getName() Returns the name of the variable. |
Operation | optimize() Optimizes the hidden operation. |
double | result() returns the result of the operation. |
void | setOperation(Operation o) Sets the operation from which the result of this variable will be calculated. |
java.lang.String | toString() Returns the name of the variable. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Variable
public Variable(java.lang.String name)
- Construcs a New Variable given the name.
- Parameters:
name
- The name of the variable.
getName
public java.lang.String getName()
- Returns the name of the variable.
- Returns:
- name of the Variable.
setOperation
public void setOperation(Operation o)
- Sets the operation from which the result of this variable will be calculated. For example, you can set this variable to a ConstantNumber using:
variable.setOperation(new ConstantNumber(50));
System.out.println(variable.result());
Output:
50.0
- Parameters:
o
- The operation from which the result will be calculated.
result
public double result()
throws MathException
- Description copied from interface:
Operation
returns the result of the operation.
- Specified by:
result
in interface Operation
- Returns:
- The result value.
- Throws:
MathException
- if there is a Math Exception!!
toString
public java.lang.String toString()
- Returns the name of the variable.
- Overrides:
toString
in class java.lang.Object
- Returns:
- the name of the variable.
clone
public Variable clone(OperatorSourceImpl s)
throws java.lang.CloneNotSupportedException
- Clones this Variable only if it is not contained in the operatorSource given. Otherwise, it returns this Variable.
- Specified by:
clone
in interface Operation
- Parameters:
s
- The OperatorSourceImpl. - Returns:
- Returns the cloned operation.
- Throws:
java.lang.CloneNotSupportedException
- If the operation is not clonable.- See Also:
ConstantNumber.clone(hussam.math.operations.dataBase.OperatorSourceImpl)
, clone(hussam.math.operations.dataBase.OperatorSourceImpl)
optimize
public Operation optimize()
- Optimizes the hidden operation.
- Specified by:
optimize
in interface Operation
- Returns:
- This Variable.