Package com.ezylang.evalex.data
Class EvaluationValue
- java.lang.Object
-
- com.ezylang.evalex.data.EvaluationValue
-
- All Implemented Interfaces:
java.lang.Comparable<EvaluationValue>
public class EvaluationValue extends java.lang.Object implements java.lang.Comparable<EvaluationValue>
The representation of the final or intermediate evaluation result value. The representation consists of a data type and data value. Depending on the type, the value will be stored in a corresponding object type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEvaluationValue.DataTypeThe supported data types.
-
Constructor Summary
Constructors Constructor Description EvaluationValue(double value, java.math.MathContext mathContext)Deprecated, for removal: This API element is subject to removal in a future version.EvaluationValue(java.lang.Object value)Deprecated, for removal: This API element is subject to removal in a future version.EvaluationValue(java.lang.Object value, ExpressionConfiguration configuration)Creates a new evaluation value by using the configured converter and configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static EvaluationValuearrayValue(java.util.List<?> value)Creates a new array value.static EvaluationValuebooleanValue(java.lang.Boolean value)Creates a new boolean value.intcompareTo(EvaluationValue toCompare)static EvaluationValuedateTimeValue(java.time.Instant value)Creates a new date-time value.static EvaluationValuedurationValue(java.time.Duration value)Creates a new duration value.static EvaluationValueexpressionNodeValue(ASTNode value)Creates a new expression node value.java.util.List<EvaluationValue>getArrayValue()Gets aListrepresentation of the value.java.lang.BooleangetBooleanValue()Gets aBooleanrepresentation of the value.java.time.InstantgetDateTimeValue()Gets aInstantrepresentation of the value.java.time.DurationgetDurationValue()Gets aDurationrepresentation of the value.ASTNodegetExpressionNode()Gets the expression node, if this value is of typeEvaluationValue.DataType.EXPRESSION_NODE.java.math.BigDecimalgetNumberValue()Gets aBigDecimalrepresentation of the value.java.lang.StringgetStringValue()Gets aStringrepresentation of the value.java.util.Map<java.lang.String,EvaluationValue>getStructureValue()Gets aMaprepresentation of the value.booleanisArrayValue()Checks if the value is of typeEvaluationValue.DataType.ARRAY.booleanisBooleanValue()Checks if the value is of typeEvaluationValue.DataType.BOOLEAN.booleanisDateTimeValue()Checks if the value is of typeEvaluationValue.DataType.DATE_TIME.booleanisDurationValue()Checks if the value is of typeEvaluationValue.DataType.DURATION.booleanisExpressionNode()Checks if the value is of typeEvaluationValue.DataType.EXPRESSION_NODE.booleanisNullValue()booleanisNumberValue()Checks if the value is of typeEvaluationValue.DataType.NUMBER.booleanisStringValue()Checks if the value is of typeEvaluationValue.DataType.STRING.booleanisStructureValue()Checks if the value is of typeEvaluationValue.DataType.STRUCTURE.static EvaluationValuenullValue()Creates a new null value.static EvaluationValuenumberOfString(java.lang.String value, java.math.MathContext mathContext)Creates aEvaluationValue.DataType.NUMBERvalue from aString.static EvaluationValuenumberValue(java.math.BigDecimal value)Creates a new number value.static EvaluationValuestringValue(java.lang.String value)Creates a new string value.static EvaluationValuestructureValue(java.util.Map<?,?> value)Creates a new structure value.
-
-
-
Constructor Detail
-
EvaluationValue
@Deprecated(since="3.1.0", forRemoval=true) public EvaluationValue(java.lang.Object value)Deprecated, for removal: This API element is subject to removal in a future version.Creates a new evaluation value by using the default converter and configuration.- Parameters:
value- Any object that the default converter can convert.- Throws:
java.lang.IllegalArgumentException- if the data type can't be mapped.- See Also:
DefaultEvaluationValueConverter
-
EvaluationValue
public EvaluationValue(java.lang.Object value, ExpressionConfiguration configuration)Creates a new evaluation value by using the configured converter and configuration.- Parameters:
value- One of the supported data types.configuration- The expression configuration to use.- Throws:
java.lang.IllegalArgumentException- if the data type can't be mapped.- See Also:
ExpressionConfiguration#getEvaluationValueConverter()
-
EvaluationValue
@Deprecated(since="3.1.0", forRemoval=true) public EvaluationValue(double value, java.math.MathContext mathContext)Deprecated, for removal: This API element is subject to removal in a future version.Creates a new evaluation value from a double value using the specifiedMathContext.- Parameters:
value- The double value.mathContext- The math context to use.
-
-
Method Detail
-
nullValue
public static EvaluationValue nullValue()
Creates a new null value.- Returns:
- A new null value.
-
numberValue
public static EvaluationValue numberValue(java.math.BigDecimal value)
Creates a new number value.- Parameters:
value- The BigDecimal value to use.- Returns:
- the new number value.
-
stringValue
public static EvaluationValue stringValue(java.lang.String value)
Creates a new string value.- Parameters:
value- The String value to use.- Returns:
- the new string value.
-
booleanValue
public static EvaluationValue booleanValue(java.lang.Boolean value)
Creates a new boolean value.- Parameters:
value- The Boolean value to use.- Returns:
- the new boolean value.
-
dateTimeValue
public static EvaluationValue dateTimeValue(java.time.Instant value)
Creates a new date-time value.- Parameters:
value- The Instant value to use.- Returns:
- the new date-time value.
-
durationValue
public static EvaluationValue durationValue(java.time.Duration value)
Creates a new duration value.- Parameters:
value- The Duration value to use.- Returns:
- the new duration value.
-
expressionNodeValue
public static EvaluationValue expressionNodeValue(ASTNode value)
Creates a new expression node value.- Parameters:
value- The ASTNode value to use.- Returns:
- the new expression node value.
-
arrayValue
public static EvaluationValue arrayValue(java.util.List<?> value)
Creates a new array value.- Parameters:
value- The List value to use.- Returns:
- the new array value.
-
structureValue
public static EvaluationValue structureValue(java.util.Map<?,?> value)
Creates a new structure value.- Parameters:
value- The Map value to use.- Returns:
- the new structure value.
-
isNumberValue
public boolean isNumberValue()
Checks if the value is of typeEvaluationValue.DataType.NUMBER.- Returns:
trueorfalse.
-
isStringValue
public boolean isStringValue()
Checks if the value is of typeEvaluationValue.DataType.STRING.- Returns:
trueorfalse.
-
isBooleanValue
public boolean isBooleanValue()
Checks if the value is of typeEvaluationValue.DataType.BOOLEAN.- Returns:
trueorfalse.
-
isDateTimeValue
public boolean isDateTimeValue()
Checks if the value is of typeEvaluationValue.DataType.DATE_TIME.- Returns:
trueorfalse.
-
isDurationValue
public boolean isDurationValue()
Checks if the value is of typeEvaluationValue.DataType.DURATION.- Returns:
trueorfalse.
-
isArrayValue
public boolean isArrayValue()
Checks if the value is of typeEvaluationValue.DataType.ARRAY.- Returns:
trueorfalse.
-
isStructureValue
public boolean isStructureValue()
Checks if the value is of typeEvaluationValue.DataType.STRUCTURE.- Returns:
trueorfalse.
-
isExpressionNode
public boolean isExpressionNode()
Checks if the value is of typeEvaluationValue.DataType.EXPRESSION_NODE.- Returns:
trueorfalse.
-
isNullValue
public boolean isNullValue()
-
numberOfString
public static EvaluationValue numberOfString(java.lang.String value, java.math.MathContext mathContext)
Creates aEvaluationValue.DataType.NUMBERvalue from aString.- Parameters:
value- TheStringvalue.mathContext- The math context to use for creation of theBigDecimalstorage.
-
getNumberValue
public java.math.BigDecimal getNumberValue()
Gets aBigDecimalrepresentation of the value. If possible and needed, a conversion will be made.- Boolean
truewill return aBigDecimal.ONE, elseBigDecimal.ZERO.
- Returns:
- The
BigDecimalrepresentation of the value, orBigDecimal.ZEROif conversion is not possible.
- Boolean
-
getStringValue
public java.lang.String getStringValue()
Gets aStringrepresentation of the value. If possible and needed, a conversion will be made.- Number values will be returned as
BigDecimal.toPlainString(). - The
Object.toString()will be used in all other cases.
- Returns:
- The
Stringrepresentation of the value.
- Number values will be returned as
-
getBooleanValue
public java.lang.Boolean getBooleanValue()
Gets aBooleanrepresentation of the value. If possible and needed, a conversion will be made.- Any non-zero number value will return true.
- Any string with the value
"true"(case ignored) will return true.
- Returns:
- The
Booleanrepresentation of the value.
-
getDateTimeValue
public java.time.Instant getDateTimeValue()
Gets aInstantrepresentation of the value. If possible and needed, a conversion will be made.- Any number value will return the instant from the epoc value.
- Any string with the string representation of a LocalDateTime (ex:
"2018-11-30T18:35:24.00") (case ignored) will return the current LocalDateTime. - The date
Instant.EPOCHwill return if a conversion error occurs or in all other cases.
- Returns:
- The
Instantrepresentation of the value.
-
getDurationValue
public java.time.Duration getDurationValue()
Gets aDurationrepresentation of the value. If possible and needed, a conversion will be made.- Any non-zero number value will return the duration from the millisecond.
- Any string with the string representation of an
Duration(ex:"PnDTnHnMn.nS") (case ignored) will return the current instant. - The
Duration.ZEROwill return if a conversion error occurs or in all other cases.
- Returns:
- The
Durationrepresentation of the value.
-
getArrayValue
public java.util.List<EvaluationValue> getArrayValue()
Gets aListrepresentation of the value.- Returns:
- The
Listrepresentation of the value or an empty list, if no conversion is possible.
-
getStructureValue
public java.util.Map<java.lang.String,EvaluationValue> getStructureValue()
Gets aMaprepresentation of the value.- Returns:
- The
Maprepresentation of the value or an empty list, if no conversion is possible.
-
getExpressionNode
public ASTNode getExpressionNode()
Gets the expression node, if this value is of typeEvaluationValue.DataType.EXPRESSION_NODE.- Returns:
- The expression node, or null for any other data type.
-
compareTo
public int compareTo(EvaluationValue toCompare)
- Specified by:
compareToin interfacejava.lang.Comparable<EvaluationValue>
-
-