|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgenopt.algorithm.util.math.FunctionEvaluator
public class FunctionEvaluator
Function parser.
This class parses a given String argument and computes the function value as
specified by the String.
To invoke the function, the class genopt.algorithm.util.math.Fun is parsed. If
the function cannot be found in this class, then the class java.lang.StrictMath
is parsed.
A typical argment has the form add(2, subtract(sin(3), 1)).
This project was carried out at:
and supported byGenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.
| Nested Class Summary | |
|---|---|
private class |
FunctionEvaluator.Element
Internal class for an element that contains either a String, a double, or
a char value. |
| Field Summary | |
|---|---|
protected java.util.ArrayList<FunctionEvaluator.Element> |
arrLis
List with Elements that resulted from function parsing. |
protected java.lang.String |
Func
Function to be evaluated. |
private static java.lang.String |
LS
Line separator |
protected java.lang.String |
Name
Function name. |
| Constructor Summary | |
|---|---|
FunctionEvaluator(java.lang.String name,
java.lang.String function)
Creates a new FunctionEvaluator instance. |
|
| Method Summary | |
|---|---|
private FunctionEvaluator.Element |
_evaluate(java.lang.String fun,
java.util.Stack<java.lang.Double> sta)
Evaluates the function fun using all elements in sta as the argument. |
private java.lang.String |
_getErrorMessagePrefix()
Gets the prefix for the error message. |
private FunctionEvaluator.Element |
_parse(java.util.ArrayList<FunctionEvaluator.Element> lis,
java.lang.String fun)
Parses the function. |
private void |
_setArrayList()
Sets the array list that will be used to evaluate the function |
double |
evaluate()
Evaluates the function. |
java.lang.String |
getFunction()
|
java.lang.String |
getName()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.String LS
protected java.lang.String Name
protected java.lang.String Func
protected java.util.ArrayList<FunctionEvaluator.Element> arrLis
| Constructor Detail |
|---|
public FunctionEvaluator(java.lang.String name,
java.lang.String function)
FunctionEvaluator instance.
name - name of the functionfunction - function to be evaluated| Method Detail |
|---|
public double evaluate()
throws java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException - if the method could not be found
java.lang.IllegalAccessException - if an error occurs
java.lang.reflect.InvocationTargetException - if an error occurs
java.lang.IndexOutOfBoundsException - if an error occursprivate void _setArrayList()
private java.lang.String _getErrorMessagePrefix()
private FunctionEvaluator.Element _parse(java.util.ArrayList<FunctionEvaluator.Element> lis,
java.lang.String fun)
throws java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
lis - the ArrayList with the function being evaluated.
The function name must be passed in the fun argument.fun - name of the function that has to be invoked
Element containing the function value
java.lang.NoSuchMethodException - if an error occurs
java.lang.IllegalAccessException - if an error occurs
java.lang.reflect.InvocationTargetException - if an error occurs
private FunctionEvaluator.Element _evaluate(java.lang.String fun,
java.util.Stack<java.lang.Double> sta)
throws java.lang.NoSuchMethodException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
fun using all elements in sta as the argument.
fun - the name of the function that will be invokedsta - a stack of Doubles that are the arguments of
fun
Element that contains the function value
java.lang.NoSuchMethodException - if an error occurs
java.lang.IllegalAccessException - if an error occurs
java.lang.reflect.InvocationTargetException - if an error occurspublic java.lang.String getName()
public java.lang.String getFunction()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||