Package com.myscript.iink
Class MathExternalExpression
java.lang.Object
com.myscript.iink.MathExternalExpression
- All Implemented Interfaces:
AutoCloseable
The MathExternalExpression allows to manage an external math expression.
- Since:
- 4.2
-
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull MathVariableDefinitionChecks if expression represents a variable definition and returns the associated information.final voidclose()final @org.jetbrains.annotations.NotNull double[][]evaluate(@NotNull MathEvaluationVariables variables, double from, double to, int pointCount) Returns the list of points resulting from evaluating the given variables.final @org.jetbrains.annotations.NotNull double[][]evaluate(@NotNull MathEvaluationVariables variables, double from, double to, int pointCount, @Nullable ParameterSet overrideConfiguration) Returns the list of points resulting from evaluating the given variables.protected voidfinalize()final @NotNull MathDiagnosticgetDiagnostic(@NotNull String task) Returns the diagnostic info for the given task.final @NotNull MathDiagnosticgetDiagnostic(@NotNull String task, @Nullable ParameterSet overrideConfiguration) Returns the diagnostic info for the given task.final @NotNull MathEvaluationVariables[]Returns the list of variable names that can be evaluated.final @NotNull StringReturns the expression original string.final @NotNull MathVariableInfo[]Retrieves information about all variables associated with the expression.final doublegetVariableValue(@NotNull String name) Returns the value associated with the given variable name.final booleanisClosed()Tells whether theclose()method has been called.final booleanremoveVariableValue(@NotNull String name) Removes the definition of the given variable name.final voidsetVariableValue(@NotNull String name, double value) Sets the value associated with the given variable name.
-
Method Details
-
finalize
-
close
public final void close()- Specified by:
closein interfaceAutoCloseable
-
isClosed
public final boolean isClosed()Tells whether theclose()method has been called. Once an object is closed any method will throwIllegalStateException.- Returns:
trueif this object is closed.
-
getString
Returns the expression original string.- Returns:
- the original string.
- Throws:
IllegalStateException
-
getDiagnostic
@NotNull public final @NotNull MathDiagnostic getDiagnostic(@NotNull @NotNull String task, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the diagnostic info for the given task.- Parameters:
task- the task to diagnose. Only"evaluation"is currently supported.overrideConfiguration- the extra configuration used.- Returns:
- a diagnostic error code.
- Throws:
NullPointerException- iftaskis null.IllegalArgumentException- whentaskis invalid.IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException
-
getDiagnostic
@NotNull public final @NotNull MathDiagnostic getDiagnostic(@NotNull @NotNull String task) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the diagnostic info for the given task.- Parameters:
task- the task to diagnose: either"numerical-computation"or"evaluation".- Returns:
- a diagnostic error code.
- Throws:
NullPointerException- iftaskis null.IllegalArgumentException- whentaskis invalid.IllegalStateException
-
getEvaluables
@NotNull public final @NotNull MathEvaluationVariables[] getEvaluables() throws IllegalStateExceptionReturns the list of variable names that can be evaluated. An expression with no syntax error can be evaluated when it contains: - a variable definition - a single (multi-occurrence) undefined variable and no equal sign - an equal sign and two undefined variables, with at least one being a single-occurrence Returns an empty list if expression cannot be evaluated. Example: seeMathSolverController::getEvaluables.Note: in case both variables can be evaluated interchangeably, the first returned
MathEvaluationVariableswill use the (leftmost) isolated variable as output if any. Example:"y = cos(x) + 1"will always return:{{ in:"x", out:"y" }, { in:"y", out:"x" }}in that order.- Returns:
- a list of MathEvaluationVariables that can be evaluated.
- Throws:
IllegalStateException
-
evaluate
@NotNull public final @org.jetbrains.annotations.NotNull double[][] evaluate(@NotNull @NotNull MathEvaluationVariables variables, double from, double to, int pointCount, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the list of points resulting from evaluating the given variables. Example: for"y = 2x",evaluate({ in:"x", out:"y" }, -1, 1, 3)returns{ {-1, -2, 0, 0, 1, 2} }, meaning{ {x0, y0, x1, y1, x2, y2} }.- Parameters:
variables- the variables to evaluate.from- the start of the range to evaluate.to- the end of the range to evaluate.pointCount- the number of values to evaluate between [from, to].overrideConfiguration- the extra configuration used.- Returns:
- a list of evaluated points, representing continuous parts of a curve.
With
points[2N]being the input value andpoints[2N+1]the evaluated variable output. - Throws:
NullPointerException- whenvariablesis null.IllegalArgumentException- whenvariablesare not evaluable.IllegalArgumentException- whenfromortois not a number.IllegalArgumentException- whenfromis greater thanto.IllegalArgumentException- whenpointCountis not in[1, 10000].IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException
-
evaluate
@NotNull public final @org.jetbrains.annotations.NotNull double[][] evaluate(@NotNull @NotNull MathEvaluationVariables variables, double from, double to, int pointCount) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the list of points resulting from evaluating the given variables. Example: for"y = 2x",evaluate({ in:"x", out:"y" }, -1, 1, 3)returns{ {-1, -2, 0, 0, 1, 2} }, meaning{ {x0, y0, x1, y1, x2, y2} }.- Parameters:
variables- the variables to evaluate.from- the start of the range to evaluate.to- the end of the range to evaluate.pointCount- the number of values to evaluate between [from, to].- Returns:
- a list of evaluated points, representing continuous parts of a curve.
With
points[2N]being the input value andpoints[2N+1]the evaluated variable output. - Throws:
NullPointerException- whenvariablesis null.IllegalArgumentException- whenvariablesare not evaluable.IllegalArgumentException- whenfromortois not a number.IllegalArgumentException- whenfromis greater thanto.IllegalArgumentException- whenpointCountis not in[1, 10000].IllegalStateException
-
asVariableDefinition
@NotNull public final @NotNull MathVariableDefinition asVariableDefinition() throws IllegalStateExceptionChecks if expression represents a variable definition and returns the associated information. An expression represents a variable definition if it is an equation with a single variable on the left of the equal sign and at least one constant expression on the right (first value is used). Example:"a = 1/2"or"b = 1/3 = 0.33"- Returns:
- the name and value of the defined variable if any, otherwise an invalid definition.
- Throws:
IllegalStateException
-
getVariables
Retrieves information about all variables associated with the expression.- Returns:
- a vector containing the information of all variables.
- Throws:
IllegalStateException
-
getVariableValue
public final double getVariableValue(@NotNull @NotNull String name) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the value associated with the given variable name.- Parameters:
name- the variable name.- Returns:
- a variable value.
- Throws:
IllegalArgumentException- ifnameis not an existing variable name.NullPointerExceptionIllegalStateException
-
setVariableValue
public final void setVariableValue(@NotNull @NotNull String name, double value) throws NullPointerException, IllegalArgumentException, IllegalStateException Sets the value associated with the given variable name.- Parameters:
name- the variable name.value- the variable value.- Throws:
IllegalArgumentException- whennameis an invalid variable name.IllegalArgumentException- whenvalueis an invalid variable value.NullPointerExceptionIllegalStateException
-
removeVariableValue
public final boolean removeVariableValue(@NotNull @NotNull String name) throws NullPointerException, IllegalStateException Removes the definition of the given variable name.- Parameters:
name- the variable name.- Returns:
trueif the variable existed, otherwisefalse.- Throws:
NullPointerExceptionIllegalStateException
-