hussam.math.operations
Class Constant

java.lang.Object
extended by hussam.math.operations.Variable
extended by hussam.math.operations.Constant
All Implemented Interfaces:
Operation, java.io.Serializable, java.lang.Cloneable

public final class Constant
extends Variable

This is an Operation that simulates a constant number.

A Constant Functions as a variable, however, you cannot change
 the value once it is set!
 If you try to change the value, a Runtime Exception will be thrown.

 To make sure that the class functions correctly, it is declared final.

Author:
Hussam Almulhim حسام الملحم
See Also:
Serialized Form

Constructor Summary
Constant(java.lang.String name, Operation o)
          Constructs a new Constant with a name and an Operation.
 
Method Summary
 Constantclone()
          This method returns this Object!
 Constantoptimize()
          This method redircts the call to the hidden Operation inside this Constant.
 voidsetOperation(Operation o)
          This will throw a Runtime Exception.
 
Methods inherited from class hussam.math.operations.Variable
clone, getName, result, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constant

public Constant(java.lang.String name,
Operation o)
Constructs a new Constant with a name and an Operation.

Parameters:
name - The name of the Variable.
o -
The operation used to get the value for that Constant.
Method Detail

setOperation

public void setOperation(Operation o)
This will throw a Runtime Exception.

Overrides:
setOperation in class Variable
Parameters:
o -
The Operation to be set. This method is used to override the method in Variable, so that it would throw a Runtime Exception.

clone

public Constant clone()
This method returns this Object! This method does not clone! Since constants are Immutable objects, it is not seen as a good practice to clone constants!

Overrides:
clone in class java.lang.Object
Returns:
This Constant

optimize

public Constant optimize()
This method redircts the call to the hidden Operation inside this Constant.

Specified by:
optimize in interface Operation
Overrides:
optimize in class Variable
Returns:
This Variable.