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)EvaluationValue(java.lang.Object value)Creates a new evaluation value by taking a good guess on the provided Java class and converting it to one of the supported types.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(EvaluationValue toCompare)java.util.List<EvaluationValue>getArrayValue()Gets aListrepresentation of the value.java.lang.BooleangetBooleanValue()Gets aBooleanrepresentation 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.booleanisExpressionNode()Checks if the value is of typeEvaluationValue.DataType.EXPRESSION_NODE.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 EvaluationValuenumberOfString(java.lang.String value, java.math.MathContext mathContext)Creates aEvaluationValue.DataType.NUMBERvalue from aString.
-
-
-
Constructor Detail
-
EvaluationValue
public EvaluationValue(java.lang.Object value)
Creates a new evaluation value by taking a good guess on the provided Java class and converting it to one of the supported types.
* Be careful with conversion problems when using float or double, which are fractional numbers. A (float)0.1 is e.g. converted to 0.10000000149011612Input type Storage Type BigDecimal BigDecimal Long, long BigDecimal Integer, int BigDecimal Short, short BigDecimal Byte, byte BigDecimal Double, double BigDecimal * Float, float BigDecimal * CharSequence , String String Boolean, boolean Boolean ASTNode ASTNode List<?> List<EvaluationValue> - each entry will be converted Map<?,?> Map<String><EvaluationValue> - each entry will be converted. - Parameters:
value- One of the supported data types.- Throws:
java.lang.IllegalArgumentException- if the data type can't be mapped.
-
EvaluationValue
public EvaluationValue(double value, java.math.MathContext mathContext)
-
-
Method Detail
-
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.
-
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.
-
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.
-
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>
-
-