|
http://www.eteks.com | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.eteks.parser.CompiledFunction
Compiled functions with a fixed number of parameters and able to compute its value
with an interpreter. Instances of this class are returned by the
compileFunction ()
method of the FunctionParser
class,
and can be computed with the value of its parameters. This method parses the definition
of a function and builds a tree of type ExpressionNode
matching the expression
of the function.
The two computeFunction ()
methods of this class allow to compute
the value of a function according to the value of the parameters passed to the method :
double computeFunction (double [] parametersValue)
is the easiest
and the fastest method to use if your function computes double numbers.Object computeFunction (Interpreter interpreter, Object [] parametersValue)
allows to choose the implementation of the interpreter that computes the
constants, operators and functions of Syntax
with parametersValue
.computeFunction ()
returns the same
result :
The other methods of this class returns the different properties of a function (name, parameters, definition,...).FunctionParser parser = new FunctionParser (); CompiledFunction function = parser.compileFunction ("f(x) = x * ln (x)"); double doubleResult1 = function.computeFunction (new double [] {2}); Interpreter interpreter = new DoubleInterpreter (); Object doubleResult2 = function.computeFunction (interpreter, new Double [] {new Double (2)});
FunctionParser
,
Interpreter
, Serialized FormConstructor Summary | |
CompiledFunction(java.lang.String definition,
java.lang.String name,
java.lang.String[] parameters,
ExpressionNode expressionTree)
Creates a compiled function named name with its parameters
parameters , its definition definition and the
tree expressionTree matching the expression of the function. |
Method Summary | |
double |
computeFunction(double[] parametersValue)
Returns the result of the function computed with the value of its parameters. |
java.lang.Object |
computeFunction(Interpreter interpreter,
java.lang.Object[] parametersValue)
Returns the result of the function computed with the value of its parameters parametersValue .
|
java.lang.String |
getDefinition()
Returns the definition of this function. |
ExpressionNode |
getExpressionTree()
Returns the tree of the expression of this function. |
java.lang.String |
getName()
Returns the name of this function. |
int |
getParameterCount()
Returns the number of parameters this function is requiring at runtime. |
java.lang.String[] |
getParameters()
Returns the array of the name of the parameters this function is requiring at runtime. |
boolean |
isValidParameterCount(int count)
Returns true if count is equal to the required number
of parameters. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public CompiledFunction(java.lang.String definition, java.lang.String name, java.lang.String[] parameters, ExpressionNode expressionTree)
name
with its parameters
parameters
, its definition definition
and the
tree expressionTree
matching the expression of the function.definition
- the definition of this function. This is
the parsed string from which was created this function.name
- the name of this function (extracted from the definition)parameters
- the name of its parameters (extracted from the definition)expressionTree
- the tree built by the parser matching the expression of the function.Method Detail |
public java.lang.String getDefinition()
FunctionParser
that created this function.public java.lang.String getName()
getName
in interface Function
FunctionParser
or
ExpressionParser
.public java.lang.String[] getParameters()
public int getParameterCount()
public boolean isValidParameterCount(int count)
true
if count
is equal to the required number
of parameters.isValidParameterCount
in interface Function
com.eteks.parser.Function
count
- Number of parameters (may be equal to 0).public ExpressionNode getExpressionTree()
f(x) = x * ln (x)
has the following tree :
BinaryOperatorNode
with OPERATOR_MULTIPLY
keyFunctionParameterNode
for parameter at index 0CommonFunctionNode
with FUNCTION_LN
keyFunctionParameterNode
for parameter at index 0public double computeFunction(double[] parametersValue)
computeExpression (parametersValue)
on the root
of its tree.computeFunction (Interpreter, Object [])
method of this class,
but of course it can compute only double numbers.parametersValue
- the value of parameters required to compute this function.ExpressionNode
public java.lang.Object computeFunction(Interpreter interpreter, java.lang.Object[] parametersValue)
parametersValue
.
This method simply calls computeExpression (interpreter, parametersValue)
on the root
of its tree.computeFunction
in interface Function
interpreter
- the runtime interpreter used to compute the operations of Syntax
.parametersValue
- the value of parameters required to compute this function
(already evaluated if they are expressions). parametersValue
may be null
if this function doesn't require parameters.Double
, String
, ...) according to
interpreter
implementation.java.lang.IllegalArgumentException
- if the parametersValue size is different of the required one.ExpressionNode
|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |