Package com.myscript.iink
Class MathSolverController
java.lang.Object
com.myscript.iink.MathSolverController
- All Implemented Interfaces:
AutoCloseable
A MathSolverController allows to configure and run math operations on an editor.
Note: Following limitation applies: the part managed by the associated editor must be a "Raw Content" and the specified block must be a "Math" block.
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionfinal voidapplyAction(@NotNull String blockId, @NotNull String action) Applies the solved action of the specified block to the rendering.final voidapplyAction(@NotNull String blockId, @NotNull String action, @Nullable ParameterSet overrideConfiguration) Applies the solved action of the specified block to the rendering.final @NotNull MathVariableDefinitionasVariableDefinition(@NotNull String blockId) Checks if the specified block represents a variable definition and returns the associated information.final voidclose()final @org.jetbrains.annotations.NotNull double[][]evaluate(@NotNull String blockId, @NotNull MathEvaluationVariables variables, double from, double to, int pointCount) Returns the list of points resulting from evaluating the given variables in the specified block.final @org.jetbrains.annotations.NotNull double[][]evaluate(@NotNull String blockId, @NotNull MathEvaluationVariables variables, double from, double to, int pointCount, @Nullable ParameterSet overrideConfiguration) Returns the list of points resulting from evaluating the given variables in the specified block.protected voidfinalize()final @NotNull StringgetActionOutput(@NotNull String blockId, @NotNull String action, @NotNull MimeType mimeType) Returns the output for the given action and the specified block.final @NotNull StringgetActionOutput(@NotNull String blockId, @NotNull String action, @NotNull MimeType mimeType, @Nullable ParameterSet overrideConfiguration) Returns the output for the given action and the specified block.final @NotNull String[]getAvailableActions(@NotNull String blockId) Returns the available actions for the specified block.final @NotNull String[]getAvailableActions(@NotNull String blockId, @Nullable ParameterSet overrideConfiguration) Returns the available actions for the specified block.final @NotNull MathDiagnosticgetDiagnostic(@NotNull String blockId, @NotNull String task) Returns the diagnostic info for the given action and the specified block.final @NotNull MathDiagnosticgetDiagnostic(@NotNull String blockId, @NotNull String task, @Nullable ParameterSet overrideConfiguration) Returns the diagnostic info for the given task and the specified block.final @NotNull MathEvaluationVariables[]getEvaluables(@NotNull String blockId) Returns the list of variable names that can be evaluated in the specified block.final @NotNull MathVariableInfo[]getVariables(@NotNull String blockId) Returns the info of all the variables associated with the specified block.final doublegetVariableValue(@NotNull String blockId, @NotNull String name) Returns the value associated with the given variable name for the specified block.final booleanisClosed()Tells whether theclose()method has been called.final booleanremoveVariableValue(@NotNull String blockId, @NotNull String name) Removes the definition of the given variable name for the specified block.final voidsetVariableValue(@NotNull String blockId, @NotNull String name, double value) Sets the value associated with the given variable name for the specified block.
-
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.
-
getAvailableActions
@NotNull public final @NotNull String[] getAvailableActions(@NotNull @NotNull String blockId, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the available actions for the specified block.- Parameters:
blockId- the identifier of the block.overrideConfiguration- the extra configuration used.- Returns:
- an array of the available actions.
- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".
-
getAvailableActions
@NotNull public final @NotNull String[] getAvailableActions(@NotNull @NotNull String blockId) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the available actions for the specified block.- Parameters:
blockId- the identifier of the block.- Returns:
- an array of the available actions.
- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".
-
getActionOutput
@NotNull public final @NotNull String getActionOutput(@NotNull @NotNull String blockId, @NotNull @NotNull String action, @NotNull @NotNull MimeType mimeType, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the output for the given action and the specified block.- Parameters:
blockId- the identifier of the block.action- the action operated by the math solver.mimeType- the MIME type that specifies the output format, eitherJIIXorLATEX.overrideConfiguration- the extra configuration used.- Returns:
- a string representing the output formatted with the given MIME type.
- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- ifactionis null.IllegalArgumentException- whenactionis invalidNullPointerException- ifmimeTypeis null.IllegalArgumentException- when the specified MIME type is not supported.IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".
-
getActionOutput
@NotNull public final @NotNull String getActionOutput(@NotNull @NotNull String blockId, @NotNull @NotNull String action, @NotNull @NotNull MimeType mimeType) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the output for the given action and the specified block.- Parameters:
blockId- the identifier of the block.action- the action operated by the math solver.mimeType- the MIME type that specifies the output format, eitherJIIXorLATEX.- Returns:
- a string representing the output formatted with the given MIME type.
- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- ifactionis null.IllegalArgumentException- whenactionis invalidNullPointerException- ifmimeTypeis null.IllegalArgumentException- when the specified MIME type is not supported.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".
-
applyAction
public final void applyAction(@NotNull @NotNull String blockId, @NotNull @NotNull String action, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Applies the solved action of the specified block to the rendering.Note: Following limitation applies: incompatible with Offscreen interactivity service.
- Parameters:
blockId- the identifier of the block.action- the action used by the math solver.overrideConfiguration- the extra configuration used.- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- ifactionis null.IllegalArgumentException- whenactionis invalid.IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".
-
applyAction
public final void applyAction(@NotNull @NotNull String blockId, @NotNull @NotNull String action) throws NullPointerException, IllegalArgumentException, IllegalStateException Applies the solved action of the specified block to the rendering.Note: Following limitation applies: incompatible with Offscreen interactivity service.
- Parameters:
blockId- the identifier of the block.action- the action used by the math solver.- Throws:
IllegalStateException- when editor is closed.IllegalStateException- when editor is not associated with a part.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- ifactionis null.IllegalArgumentException- whenactionis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".IllegalStateException- when associated with an offscreen editor.
-
getDiagnostic
@NotNull public final @NotNull MathDiagnostic getDiagnostic(@NotNull @NotNull String blockId, @NotNull @NotNull String task, @Nullable @Nullable ParameterSet overrideConfiguration) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the diagnostic info for the given task and the specified block.- Parameters:
blockId- the identifier of the block.task- the task to diagnose: either"numerical-computation"or"evaluation".overrideConfiguration- the extra configuration used.- Returns:
- a diagnostic error code,
MathDiagnostic::ALLOWEDif none. - Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- iftaskis null.IllegalArgumentException- whentaskis invalid.IllegalArgumentException- whenoverrideConfigurationis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
getDiagnostic
@NotNull public final @NotNull MathDiagnostic getDiagnostic(@NotNull @NotNull String blockId, @NotNull @NotNull String task) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the diagnostic info for the given action and the specified block.- Parameters:
blockId- the identifier of the block.task- the task to diagnose: either"numerical-computation"or"evaluation".- Returns:
- a diagnostic error code,
MathDiagnostic::ALLOWEDif none. - Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- iftaskis null.IllegalArgumentException- whentaskis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
getEvaluables
@NotNull public final @NotNull MathEvaluationVariables[] getEvaluables(@NotNull @NotNull String blockId) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the list of variable names that can be evaluated in the specified block. A block 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 block cannot be evaluated. Example: a math block containing"y = x^3 + 2x + 1"can evaluate:{ in:"x", out:"y" }a math block containing"2 * y = x - 1"can evaluate:{{ in:"x", out:"y" }, { in:"y", out:"x" }}a math block containing"y = 3 * 4"can evaluate:{ in:"", out:"y" }a math block containing"sin(x) + x/2"can evaluate:{ in:"x", out:"" }Note: in case both variables can be evaluated interchangeably, the first returnedMathEvaluationVariableswill 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.- Parameters:
blockId- the identifier of the block.- Returns:
- a list of MathEvaluationVariables that can be evaluated.
- Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
evaluate
@NotNull public final @org.jetbrains.annotations.NotNull double[][] evaluate(@NotNull @NotNull String blockId, @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 in the specified block. Example: for"y = 2x",evaluate(blockId, { in:"x", out:"y" }, -1, 1, 3)returns{ {-1, -2, 0, 0, 1, 2} }, meaning{ {x0, y0, x1, y1, x2, y2} }.- Parameters:
blockId- the identifier of the block.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:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.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- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
evaluate
@NotNull public final @org.jetbrains.annotations.NotNull double[][] evaluate(@NotNull @NotNull String blockId, @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 in the specified block. Example: for"y = 2x",evaluate(blockId, { in:"x", out:"y" }, -1, 1, 3)returns{ {-1, -2, 0, 0, 1, 2} }, meaning{ {x0, y0, x1, y1, x2, y2} }.- Parameters:
blockId- the identifier of the block.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:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.NullPointerException- whenvariablesis null.IllegalArgumentException- whenvariablesare not evaluable.IllegalArgumentException- whenfromortois not a number.IllegalArgumentException- whenfromis greater thanto.IllegalArgumentException- whenpointCountis not in[1, 10000].IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
asVariableDefinition
@NotNull public final @NotNull MathVariableDefinition asVariableDefinition(@NotNull @NotNull String blockId) throws NullPointerException, IllegalArgumentException, IllegalStateException Checks if the specified block represents a variable definition and returns the associated information. A block represents a variable definition if it is an equation with a single variable on the left of the equal sign and a constant expression on the right. Example:"a = 1/2"- Parameters:
blockId- the identifier of the block.- Returns:
- the name and value of the defined variable if any, otherwise an object which
valid()method returnsfalse. - Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
getVariables
@NotNull public final @NotNull MathVariableInfo[] getVariables(@NotNull @NotNull String blockId) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the info of all the variables associated with the specified block.- Parameters:
blockId- the identifier of the block.- Returns:
- a list of variables info.
- Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
getVariableValue
public final double getVariableValue(@NotNull @NotNull String blockId, @NotNull @NotNull String name) throws NullPointerException, IllegalArgumentException, IllegalStateException Returns the value associated with the given variable name for the specified block.- Parameters:
blockId- the identifier of the block.name- the variable name.- Returns:
- a variable value.
- Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalArgumentException- ifnameis not an existing variable name.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
setVariableValue
public final void setVariableValue(@NotNull @NotNull String blockId, @NotNull @NotNull String name, double value) throws NullPointerException, IllegalArgumentException, IllegalStateException Sets the value associated with the given variable name for the specified block.- Parameters:
blockId- the identifier of the block.name- the variable name.value- the variable value.- Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalArgumentException- whennameis an invalid variable name.IllegalArgumentException- whenvalueis an invalid variable value.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-
removeVariableValue
public final boolean removeVariableValue(@NotNull @NotNull String blockId, @NotNull @NotNull String name) throws NullPointerException, IllegalArgumentException, IllegalStateException Removes the definition of the given variable name for the specified block.- Parameters:
blockId- the identifier of the block.name- the variable name.- Returns:
trueif the variable existed, otherwisefalse.- Throws:
IllegalStateException- when editor is closed.NullPointerException- ifblockIdis null.IllegalArgumentException- whenblockIdis invalid.IllegalStateException- when associated part type is not "Raw Content" or block type is not "Math".- Since:
- 4.1
-