Package org.mariuszgromada.math.mxparser
Class Constant
- java.lang.Object
-
- org.mariuszgromada.math.mxparser.PrimitiveElement
-
- org.mariuszgromada.math.mxparser.Constant
-
- All Implemented Interfaces:
Serializable
public class Constant extends PrimitiveElement implements Serializable
Constant class provides ability to declare constants. Constants can be used in further processing by any expression, dependent or recursive argument, function, etc...When creating a constant you should avoid names reserved as parser keywords, in general words known in mathematical language as function names, operators (for example: sin, cos, +, -, pi, e, etc...). Please be informed that after associating the constant with the expression, function or dependent/recursive argument its name will be recognized by the parser as reserved key word. It means that it could not be the same as any other key word known by the parser for this particular expression.
- Version:
- 5.2.0
- Author:
- Mariusz Gromada
MathParser.org - mXparser project page
mXparser on GitHub
INFIMA place to purchase a commercial MathParser.org-mXparser software license
info@mathparser.org
ScalarMath.org - a powerful math engine and math scripting language
Scalar Lite
Scalar Pro
MathSpace.pl - See Also:
RecursiveArgument
,Expression
,Function
,Argument
, Serialized Form
Buy me a cup of coffee via donation
or support me purchasing the license via ORDER Page , or INFIMA online store
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
NO_SYNTAX_ERRORS
Status of the syntax - no syntax errorstatic int
NOT_FOUND
When constant could not be foundstatic boolean
SYNTAX_ERROR
Status of the syntax - syntax errorstatic boolean
SYNTAX_ERROR_OR_STATUS_UNKNOWN
Deprecated.Planned to be removed, useSYNTAX_ERROR
insteadstatic String
TYPE_DESC
static int
TYPE_ID
Type identifier for constants
-
Constructor Summary
Constructors Constructor Description Constant(String constantName, double constantValue)
Constructor - creates constant with a given name and given valueConstant(String constantName, double constantValue, String description)
Constructor - creates constant with a given name and given value.Constant(String constantDefinitionString, PrimitiveElement... elements)
Constructor for function definition in natural math language, for instance providing on string "f(x,y) = sin(x) + cos(x)" is enough to define function "f" with parameters "x and y" and function body "sin(x) + cos(x)".
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Constant
cloneForThreadSafe()
Creates a completely independent 1-1 clone that can be safely used by a separate thread.String
getConstantName()
Gets constant namedouble
getConstantValue()
Gets constant value.String
getDescription()
Gets constant description.String
getErrorMessage()
Method return error message afterboolean
getSyntaxStatus()
Gets syntax status of the expression.void
setConstantName(String constantName)
Sets constant name.void
setConstantValue(double constantValue)
Sets constant valuevoid
setDescription(String description)
Sets constant description.-
Methods inherited from class org.mariuszgromada.math.mxparser.PrimitiveElement
getMyTypeId
-
-
-
-
Field Detail
-
NOT_FOUND
public static final int NOT_FOUND
When constant could not be found- See Also:
- Constant Field Values
-
TYPE_ID
public static final int TYPE_ID
Type identifier for constants- See Also:
- Constant Field Values
-
TYPE_DESC
public static String TYPE_DESC
-
NO_SYNTAX_ERRORS
public static final boolean NO_SYNTAX_ERRORS
Status of the syntax - no syntax error- See Also:
- Constant Field Values
-
SYNTAX_ERROR
public static final boolean SYNTAX_ERROR
Status of the syntax - syntax error- See Also:
- Constant Field Values
-
SYNTAX_ERROR_OR_STATUS_UNKNOWN
@Deprecated public static final boolean SYNTAX_ERROR_OR_STATUS_UNKNOWN
Deprecated.Planned to be removed, useSYNTAX_ERROR
insteadStatus of the syntax - syntax error- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Constant
public Constant(String constantName, double constantValue)
Constructor - creates constant with a given name and given value- Parameters:
constantName
- the constant nameconstantValue
- the constant value
-
Constant
public Constant(String constantName, double constantValue, String description)
Constructor - creates constant with a given name and given value. Additionally, description is being set.- Parameters:
constantName
- the constant nameconstantValue
- the constant valuedescription
- the constant description
-
Constant
public Constant(String constantDefinitionString, PrimitiveElement... elements)
Constructor for function definition in natural math language, for instance providing on string "f(x,y) = sin(x) + cos(x)" is enough to define function "f" with parameters "x and y" and function body "sin(x) + cos(x)".- Parameters:
constantDefinitionString
- Constant definition in the form of one String, ie "c = 2" or "c = 2*sin(pi/3)"elements
- Optional parameters (comma separated) such as Arguments, Constants, Functions
-
-
Method Detail
-
getConstantName
public String getConstantName()
Gets constant name- Returns:
- the constant name as string.
-
setConstantName
public void setConstantName(String constantName)
Sets constant name. If constant is associated with any expression then this operation will set modified flag to each related expression.- Parameters:
constantName
- the constant name
-
setConstantValue
public void setConstantValue(double constantValue)
Sets constant value- Parameters:
constantValue
- constant value
-
getConstantValue
public double getConstantValue()
Gets constant value.- Returns:
- constant value as double
-
getDescription
public String getDescription()
Gets constant description.- Returns:
- constant description as string.
-
setDescription
public void setDescription(String description)
Sets constant description.- Parameters:
description
- the constant description
-
getErrorMessage
public String getErrorMessage()
Method return error message after- Returns:
- Error message as string.
-
getSyntaxStatus
public boolean getSyntaxStatus()
Gets syntax status of the expression.- Returns:
- Constant.NO_SYNTAX_ERRORS if there are no syntax errors, Const.SYNTAX_ERROR when syntax error was found or syntax status is unknown
-
cloneForThreadSafe
public Constant cloneForThreadSafe()
Creates a completely independent 1-1 clone that can be safely used by a separate thread. If the cloned element contains references to other elements (e.g. arguments, functions, constants), then they will also be cloned and the newly created element will contain references to the corresponding clones. Important - the API allows you to extract all these clones.- Returns:
- Cloned object.
-
-