hussam.math.operations.extra
Class CustomFunctionFactory

java.lang.Object
extended by hussam.math.operations.factory.OperatorFactoryImpl<Function>
extended by hussam.math.operations.extra.CustomFunctionFactory
All Implemented Interfaces:
OperatorFactory<Function>, java.io.Serializable, java.lang.Comparable<Operator>
Direct Known Subclasses:
DynamicFunctionFactory

public class CustomFunctionFactory
extends OperatorFactoryImpl<Function>

This is custom function factory. This can be used to create custom function. when you create a custom factory it is automatically added to a dataSource. OperatorFactoryDB

Author:
Hussam AlMulhim حسام الملحم
See Also:
OperatorFactoryDB, Serialized Form

Nested Class Summary
protected  classCustomFunctionFactory.CustomFunction
          This class acts as a Function which is backed up by an expression held by the mother class.
 
Constructor Summary
CustomFunctionFactory(OperatorSourceImpl source, java.lang.String name, java.lang.String description, java.lang.String expression)
          Creates a new Factory given the expression.
CustomFunctionFactory(java.lang.String name, java.lang.String description, java.lang.String expression)
          Creates a new Factory given the expression.
 
Method Summary
protected  OperationReadercreateReader()
          Prepares the reader.
 OperationgetBasicModel()
          Returns the Operation Model for this factory.
 intgetDefaultArgumentCount()
          Returns the default number of arguments for this operator.
 java.lang.StringgetExpression()
          Returns the expression.
 FunctiongetNewOperator()
          Returns a new Operator.
 OperatorSourcegetOperatorSource()
          Returns the operator source used by this factory.
 java.lang.StringgetVariable(int i)
          Returns the name of the variable at the specified index.
protected  voidprepareModel()
          Prepares the operation model from which thie constructor builds new Functions from the expression used.
protected  voidsetExpression(java.lang.String exp)
          changes the expression.
 java.lang.StringtoString()
          Returns a description of this factory.
 
Methods inherited from class hussam.math.operations.factory.OperatorFactoryImpl
compareTo, getDescription, getName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CustomFunctionFactory

public CustomFunctionFactory(OperatorSourceImpl source,
                             java.lang.String name,
                             java.lang.String description,
                             java.lang.String expression)
Creates a new Factory given the expression.
CustomFunctionFactory fac=new CustomFunctionFactory(OperatorFactoryDB.getInstance(), "Add", adds two arguments", "x+y");
 Function f=fac.getNewOperator();
 f.setOperation(0, 10);
 f.setOperation(1,30);
 System.out.println(f.result()); // output: 40
 
Notice that the factory is added into this source.

Parameters:
source - The dataSource from which the expression will be evaluted.
name - The name of the function.
description - The description of the function.
expression - The expression.

CustomFunctionFactory

public CustomFunctionFactory(java.lang.String name,
                             java.lang.String description,
                             java.lang.String expression)
Creates a new Factory given the expression. The default OperatorFactoryDB will be used as a source.

Parameters:
name - The name of the function.
description - The description of the function.
expression - The expression.
Method Detail

createReader

protected OperationReader createReader()
Prepares the reader. This is called after the constructor is called.

Returns:
an expression reader.

prepareModel

protected void prepareModel()
Prepares the operation model from which thie constructor builds new Functions from the expression used.


getDefaultArgumentCount

public int getDefaultArgumentCount()
Description copied from interface: OperatorFactory
Returns the default number of arguments for this operator.

Specified by:
getDefaultArgumentCount in interface OperatorFactory<Function>
Overrides:
getDefaultArgumentCount in class OperatorFactoryImpl<Function>
Returns:
the default argument count for this operator.

getBasicModel

public Operation getBasicModel()
Returns the Operation Model for this factory. The CustomFunctionFactory uses this model to generate new Functions. It clones the operation and returns it as a new Function. This method was added to have speed in creating and useing functions unlike Version2 implemetation.

Returns:
The Model used to generate Functions.

getVariable

public java.lang.String getVariable(int i)
Returns the name of the variable at the specified index. Important note: The variables are sorted in alphbatical order.

Parameters:
i - index number.
Returns:
the name of the variable.

getNewOperator

public Function getNewOperator()
Description copied from interface: OperatorFactory
Returns a new Operator.

Returns:
The new Operator.

getExpression

public java.lang.String getExpression()
Returns the expression.

Returns:
The expression.

setExpression

protected void setExpression(java.lang.String exp)
changes the expression.

Parameters:
exp - The new expression for this factory.

getOperatorSource

public OperatorSource getOperatorSource()
Returns the operator source used by this factory.

Returns:
the operatorsource.

toString

public java.lang.String toString()
Description copied from class: OperatorFactoryImpl
Returns a description of this factory.

Overrides:
toString in class OperatorFactoryImpl<Function>
Returns:
a description.