Package org.mariuszgromada.math.mxparser
Class Constant
- java.lang.Object
-
- org.mariuszgromada.math.mxparser.PrimitiveElement
-
- org.mariuszgromada.math.mxparser.Constant
-
- All Implemented Interfaces:
java.io.Serializable
public class Constant extends PrimitiveElement implements java.io.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:
- 6.1.0
- See Also:
RecursiveArgument,Expression,Function,Argument, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringconstantNameName of the constantprivate doubleconstantValueConstant valueprivate java.lang.StringdescriptionConstant descriptionprivate java.lang.StringerrorMessageMessage after checking the syntaxstatic booleanNO_SYNTAX_ERRORSStatus of the syntax - no syntax errorstatic intNOT_FOUNDWhen constant could not be foundprivate java.util.List<Expression>relatedExpressionsListDependent expression listprivate static intserialClassIDprivate static longserialVersionUIDstatic booleanSYNTAX_ERRORStatus of the syntax - syntax errorstatic booleanSYNTAX_ERROR_OR_STATUS_UNKNOWNDeprecated.Planned to be removed, useSYNTAX_ERRORinsteadprivate booleansyntaxStatusStatus of the expression syntax Please referet to the: - NO_SYNTAX_ERRORS - SYNTAX_ERRORstatic java.lang.StringTYPE_DESCstatic intTYPE_IDType identifier for constants
-
Constructor Summary
Constructors Modifier Constructor Description Constant(java.lang.String constantName, double constantValue)Constructor - creates constant with a given name and given valueConstant(java.lang.String constantName, double constantValue, java.lang.String description)Constructor - creates constant with a given name and given value.Constant(java.lang.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)".privateConstant(Constant constantToClone)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddRelatedExpression(Expression expression)Adds related expression.private static java.lang.StringbuildErrorMessageInvalidConstantDefinitionString(java.lang.String constantDefinitionString)private static java.lang.StringbuildErrorMessageInvalidConstantName(java.lang.String constantName)ConstantcloneForThreadSafe()Creates a completely independent 1-1 clone that can be safely used by a separate thread.(package private) ConstantcloneForThreadSafeInternal(CloneCache cloneCache)(package private) ConstantcloneForThreadSafeInternal(Expression relatedExpressionThatInitiatedClone, CloneCache cloneCache)java.lang.StringgetConstantName()Gets constant namedoublegetConstantValue()Gets constant value.java.lang.StringgetDescription()Gets constant description.java.lang.StringgetErrorMessage()Method return error message afterbooleangetSyntaxStatus()Gets syntax status of the expression.private voidregisterNoSyntaxErrorInDefinition()private voidregisterSyntaxErrorInDefinition(java.lang.String errorMessage)(package private) voidremoveRelatedExpression(Expression expression)Removes related expression.voidsetConstantName(java.lang.String constantName)Sets constant name.voidsetConstantValue(double constantValue)Sets constant valuevoidsetDescription(java.lang.String description)Sets constant description.(package private) voidsetExpressionModifiedFlags()Sets expression modified flag to each related expression.-
Methods inherited from class org.mariuszgromada.math.mxparser.PrimitiveElement
getMyTypeId
-
-
-
-
Field Detail
-
serialClassID
private static final int serialClassID
- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
-
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 java.lang.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_ERRORinsteadStatus of the syntax - syntax error- See Also:
- Constant Field Values
-
constantName
private java.lang.String constantName
Name of the constant
-
constantValue
private double constantValue
Constant value
-
description
private java.lang.String description
Constant description
-
relatedExpressionsList
private java.util.List<Expression> relatedExpressionsList
Dependent expression list
-
syntaxStatus
private boolean syntaxStatus
Status of the expression syntax Please referet to the: - NO_SYNTAX_ERRORS - SYNTAX_ERROR
-
errorMessage
private java.lang.String errorMessage
Message after checking the syntax
-
-
Constructor Detail
-
Constant
public Constant(java.lang.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(java.lang.String constantName, double constantValue, java.lang.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(java.lang.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
-
Constant
private Constant(Constant constantToClone)
-
-
Method Detail
-
buildErrorMessageInvalidConstantName
private static java.lang.String buildErrorMessageInvalidConstantName(java.lang.String constantName)
-
buildErrorMessageInvalidConstantDefinitionString
private static java.lang.String buildErrorMessageInvalidConstantDefinitionString(java.lang.String constantDefinitionString)
-
registerNoSyntaxErrorInDefinition
private void registerNoSyntaxErrorInDefinition()
-
registerSyntaxErrorInDefinition
private void registerSyntaxErrorInDefinition(java.lang.String errorMessage)
-
getConstantName
public java.lang.String getConstantName()
Gets constant name- Returns:
- the constant name as string.
-
setConstantName
public void setConstantName(java.lang.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 java.lang.String getDescription()
Gets constant description.- Returns:
- constant description as string.
-
setDescription
public void setDescription(java.lang.String description)
Sets constant description.- Parameters:
description- the constant description
-
getErrorMessage
public java.lang.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
-
addRelatedExpression
void addRelatedExpression(Expression expression)
Adds related expression.- Parameters:
expression- the related expression.
-
removeRelatedExpression
void removeRelatedExpression(Expression expression)
Removes related expression.- Parameters:
expression- the related expression.
-
setExpressionModifiedFlags
void setExpressionModifiedFlags()
Sets expression modified flag to each related expression.
-
cloneForThreadSafeInternal
Constant cloneForThreadSafeInternal(CloneCache cloneCache)
-
cloneForThreadSafeInternal
Constant cloneForThreadSafeInternal(Expression relatedExpressionThatInitiatedClone, CloneCache cloneCache)
-
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.
-
-