hussam.math.operations
Class Function

java.lang.Object
extended by hussam.math.operations.Function
All Implemented Interfaces:
Operation, Operator, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Operator>
Direct Known Subclasses:
CustomFunctionFactory.CustomFunction

public abstract class Function
extends java.lang.Object
implements Operator

This class is an abstract Operator. You should extend this class to have a special reault method. The result method should use the class's functionality.

A Function uses a list of arguments packaged in an
OperationGroup
The Result method should read the arguments stored in the
getOperationGroup()method.
For Example: You can extend this to have a (factorial) implementation.
 The result implementation reads the first argument, from the Function#getOperationGroup() method.
 Then do the job to return the factorial result!

Version:
2.0
Author:
Hussam Almulhim حسام الملحم
See Also:
OperatorFactoryDB, DynamicFunctionFactory, OperatorFactory, Serialized Form

Field Summary
 
Fields inherited from interface hussam.math.operations.Operator
COMMA, FUNCTION, INDEFINITE, LOGICAL, MULTIPLY, NOTHING, PLUS, POWER
 
Constructor Summary
Function(java.lang.String name)
          Simple constructor.
Function(java.lang.String name, OperationGroup g)
          Simpler constructor.
Function(java.lang.String name, OperationGroup g, java.lang.String discription)
          Construcs a new Function given a name, and an Optional OperationGroup, and a discription
 
Method Summary
protected  voidcheckReady(int argumentCount)
          This can be used as a check for arguments.
 Functionclone(OperatorSourceImpl s)
          This method clones the operation.
 intcompareTo(Operator p)
          Compares the Function with another operator.
 intgetCurrentArgumentCount()
          Returns the current number of arguments inside this Function.
 java.lang.StringgetDiscription()
          The Function Description.
 java.lang.StringgetName()
          Returns the name of this Operator.
 OperationgetOperation(int i)
          Returns the Operation at the specified index.
 OperationGroupgetOperationGroup()
          Returns the OperationGroup
 intgetType()
          Returns Operator.FUNCTION
 Operationoptimize()
          Returns an optimized view of this Function.
 voidsetOperationGroup(OperationGroup group)
          Sets the Operations Group.
 java.lang.StringtoString()
          Returns a String describing the name of the function and the list of arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface hussam.math.operations.Operation
result
 

Constructor Detail

Function

public Function(java.lang.String name,
OperationGroup g,
                java.lang.String discription)
Construcs a new Function given a name, and an Optional OperationGroup, and a discription

Parameters:
name - Name of the Funciton
g - Optional OperationGroup, can be null;
discription - The function description.

Function

public Function(java.lang.String name,
OperationGroup g)
Simpler constructor.

Parameters:
name - function name.
g - Optional OperationGroup.
See Also:
Function(String, OperationGroup, String)

Function

public Function(java.lang.String name)
Simple constructor.

Parameters:
name - Function name.
Method Detail

getDiscription

public java.lang.String getDiscription()
The Function Description.

Returns:
The function description.

getType

public int getType()
Returns Operator.FUNCTION

Specified by:
getType in interface Operator
Returns:
Returns the FUNCTION type. Operator.FUNCTION

setOperationGroup

public void setOperationGroup(OperationGroup group)
Sets the Operations Group.

Parameters:
group - The OperationGroup to be inserted into this Function. From which the result method will calculate the result, based on the argument list inside the OperationGroup.

getOperationGroup

public OperationGroup getOperationGroup()
Returns the OperationGroup

Returns:
the OperationGroup

getOperation

public Operation getOperation(int i)
Returns the Operation at the specified index.

Parameters:
i - the Index of this operation.
Returns:
The operation at that index.

getCurrentArgumentCount

public int getCurrentArgumentCount()
Returns the current number of arguments inside this Function. It gets this number from the operationGroup inserted into this Function.

Returns:
the Current Argument Count

getName

public java.lang.String getName()
Description copied from interface: Operator
Returns the name of this Operator.

Specified by:
getName in interface Operator
Returns:
the name of this operator.

toString

public java.lang.String toString()
Returns a String describing the name of the function and the list of arguments.

Overrides:
toString in class java.lang.Object
Returns:
a describtion of the Function.

compareTo

public int compareTo(Operator p)
Compares the Function with another operator.

Specified by:
compareTo in interface java.lang.Comparable<Operator>
Parameters:
p - The other operator which the method will compare with.
Returns:
1, -1, or 0. indicating larger, smaller, or equal.

checkReady

protected void checkReady(int argumentCount)
                   throws OperatorArgumentMissingException
This can be used as a check for arguments. For example, assume you created a Function that takes 3 arguments, you can call this method checkReady(3) to test if you have already 3 arguments to process, otherwise throws a OperatorArgumentMissingException

Parameters:
argumentCount - The number of arguments to test.
Throws:
OperatorArgumentMissingException - Thrown if the number of arguments contained in this Function is lower than argumentCount.
See Also:
Operand.checkReady()

clone

public Function clone(OperatorSourceImpl s)
               throws java.lang.CloneNotSupportedException
Description copied from interface: Operation
This method clones the operation. Cloning can be achieved by useing the default clone method since Operations are Clonable since Version 3! However, cloning sometimes needs more than what the clone method offers! Notice that this clone method takes an OperatorSource as a parameter, this method should update this source with any arguments needed such as Variables! It can be seen as an implemetation of the Visitor approach. It is also worth to note that this method's implemetation is optional. You can egnore the implemetation of this method and just return
this
.

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), Variable.clone(hussam.math.operations.dataBase.OperatorSourceImpl)

optimize

public Operation optimize()
Returns an optimized view of this Function. First it optimizes all arguments. If all optimized arguments are ConstantNumbers Then this method will return a New ConstantNumber reflecting the same result().
For example, 
 Function : Max(Abs(-20), 23) 
 will be optimized to be a new ConstantNumber(23).
This works for the assumtion that if the argument list has only ConstantNumbers then result of the Function is always constant! Special care should be taken if a Function does not comply to this assumption. That is, override this implemetation when neccesary!

Specified by:
optimize in interface Operation
Returns:
an optimized Operation of this operation.