|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMaths.MathsParse
public class MathsParse
Class used to parse an equation represented by a string and return the result. Variables are represented by a letter followed by any number of alphanumeric characters. Multiply (represented by "*" should be stated explicitly, e.g. a * b NOT a b or ab (the later of which would be parsed as a single variable). Functions should be represented by "f[a,b,...]" where f is the function name and a,b etc. are inputs. Inputs cannot contain other functions but can otherwise contain an expression. The following functions are defined by default:
FunctionParser
to the constructor.
Constructor Summary | |
---|---|
MathsParse(FunctionParser... fps)
Default constructor. |
Method Summary | |
---|---|
CompiledFunction |
compileFunction(java.lang.String equation)
Parses an equation and returns a compiled function that can then be used to compute the value fo an equation. |
double |
parseEquation(java.lang.String equation,
java.util.Map<java.lang.String,java.lang.Double> values)
Parses an equation and returns the result |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MathsParse(FunctionParser... fps)
fps
- A variable number of parsers that define additional functions.
If none is passed then only the default functions are avaliable.Method Detail |
---|
public double parseEquation(java.lang.String equation, java.util.Map<java.lang.String,java.lang.Double> values) throws NoSuchFunction, WrongNumberOfVariables, NoSuchVariable
equation
- The equation to parsevalues
- Map from a string to a double that represents the value of
any variables in the equation
NoSuchFunction
- If the equation uses an undefined function
WrongNumberOfVariables
- If the equation uses a function and passes
it the wrong number of variables
NoSuchVariable
- Thrown if values does not contain a needed variablepublic CompiledFunction compileFunction(java.lang.String equation) throws NoSuchFunction, WrongNumberOfVariables
equation
- The equation to parse
NoSuchFunction
- If the equation uses an undefined function
WrongNumberOfVariables
- If the equation uses a function and passes
it the wrong number of variables
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |