hussam.math.operations.extra
Class CustomFunction

java.lang.Object
extended by hussam.math.operations.Function
extended by hussam.math.operations.extra.CustomFunction
All Implemented Interfaces:
Operation, Operator, java.lang.Comparable<Operator>

public class CustomFunction
extends Function

A Custom Function, is a Function that takes an expression to evaluate the arguments.
 This class can be extended to support different custom functions.

Version:
2.0
Author:
Hussam Al-Mulhim حسام الملحم

Field Summary
protected  java.lang.Stringexpression
          a String indicating the expression which will be evaulated.
 
Fields inherited from interface hussam.math.operations.Operator
COMMA, FUNCTION, INDEFINITE, LOGICAL, MULTIPLY, NOTHING, PLUS, POWER
 
Constructor Summary
CustomFunction(OperatorSource s, java.lang.String name, java.lang.String expression)
          Constructing using An operatorSource, the name of the function, the expression used to evalute the arguments.
CustomFunction(java.lang.String name, java.lang.String expression)
          This will use the default OperatorSource.
 
Method Summary
protected  voidexecute()
          Evaluates the argument.
 java.lang.StringgetExpression()
          Returns the Expression used to evaluate the Arguments
 VariablegetVariable(int i)
          Returns the variable contained in the expression.
 doubleresult()
          returns the result of the operation.
 voidsetOperation(int i, Operation op)
           
protected  voidsetReader(OperationReader reader)
          Sets the Reader to use to read the Expression.
 
Methods inherited from class hussam.math.operations.Function
checkReady, compareTo, getCurrentArgumentCount, getDiscription, getName, getOperation, getOperationGroup, getType, setOperationGroup, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

expression

protected java.lang.String expression
a String indicating the expression which will be evaulated.

Constructor Detail

CustomFunction

public CustomFunction(OperatorSource s,
                      java.lang.String name,
                      java.lang.String expression)
Constructing using An operatorSource, the name of the function, the expression used to evalute the arguments.

Parameters:
s - The Datasource, from which the expression can be evaluated.
name -
The name of the function.
expression - The expression used.

CustomFunction

public CustomFunction(java.lang.String name,
                      java.lang.String expression)
               throws MathException
This will use the default OperatorSource.

Throws:
MathException
See Also:
OperatorFactoryDB
Method Detail

execute

protected void execute()
                throws MathException
Evaluates the argument.
 This method is called when the result method is called.

Throws:
MathException - If the expression has a problem.

getExpression

public java.lang.String getExpression()
Returns the Expression used to evaluate the Arguments

Returns:
The expression used.

result

public double result()
              throws MathException
Description copied from interface: Operation
returns the result of the operation.

Returns:
The result value.
Throws:
MathException - Throws MathException if there is a Math Exception!!

getVariable

public Variable getVariable(int i)
Returns the variable contained in the expression.
 You can set the value of the Variable afterwords!

Returns:
The Variable at the spicified position.
 The Variables are sorted in alphabatical order.!
Throws:
java.lang.ArrayIndexOutOfBoundsException - If i is not in the variable array!
See Also:
setOperation(int, Operation)

setOperation

public void setOperation(int i,
Operation op)

setReader

protected void setReader(OperationReader reader)
                  throws MathException
Sets the Reader to use to read the Expression.

Parameters:
reader - The reader to be set.
Throws:
MathException - when an exception occured.