Class NumberValue
java.lang.Object
com.aquima.interactions.foundation.types.AbstractValue
com.aquima.interactions.foundation.types.NumberValue
- All Implemented Interfaces:
IConvertable
,IPrimitiveValue
,ISingleValue
,IValue
,Serializable
,Comparable<Object>
- Direct Known Subclasses:
AttributeNumberValue
,Currency
,Percentage
This class contains a single number value.
- Since:
- 6.3
- Author:
- O. Kerpershoek
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
The margin used when comparing doubles.static final NumberValue
This member defines the UNKNOWN value for the number type. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
NumberValue
(double doubleValue) Constructs the NumberValue with a double containing the actual value.NumberValue
(IMultilingualText displayValue, double doubleValue) Constructs the NumberValue with a display text.NumberValue
(NumberValue other) Copy constructor.NumberValue
(String typeName, IMultilingualText displayValue, double doubleValue) Constructs the NumberValue as a domain value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
This method converts the internal value to a boolean primitive.protected int
compareSimple
(Object obj) boolean
This method returns a boolean indicating if the object passed to this method is entirely part of this value.This method converts the internal value to a date object.int
doubleCompare
(double a, double b) This method compares two doubles using a small margin to determine if the doubles are equal.double
This method converts the internal value to a double primitive.This method returns a deep copy of the value.boolean
forType
(String typeName, IMultilingualText displayValue) This method adds the type and display information to the value, and returns the value with this added information.This method returns the data type of the value.getValue()
This method returns the internal object of this instance without any conversion.int
hashCode()
int
This method converts the internal value to an integer primitive.boolean
This method returns a boolean indicating if the value is unknown.long
This method converts the internal value to a long primitive.static double
parseDouble
(Object obj) This method will attempt to convert the object to a primitive double value.This method converts the internal value to a String object.toString()
static NumberValue
This method attempts to convert the object to a NumberValue.Methods inherited from class com.aquima.interactions.foundation.types.AbstractValue
compareTo, getDisplayValue, getTypeName, isRangeValue, isSingleValue, toListValue, toRangeValue, toSingleValue
-
Field Details
-
UNKNOWN
This member defines the UNKNOWN value for the number type. -
EQUALS_MARGIN
public static final double EQUALS_MARGINThe margin used when comparing doubles. If the difference between two doubles is less than this margin, they are considered equal.- See Also:
-
-
Constructor Details
-
NumberValue
protected NumberValue() -
NumberValue
public NumberValue(double doubleValue) Constructs the NumberValue with a double containing the actual value.- Parameters:
doubleValue
- a double containing the actual value.
-
NumberValue
Constructs the NumberValue with a display text.- Parameters:
displayValue
- Text object containing the display value that should be used.doubleValue
- a double containing the actual value.
-
NumberValue
Constructs the NumberValue as a domain value.- Parameters:
typeName
- The name of the domain the value belongs to.displayValue
- Text object containing the display value that should be used.doubleValue
- a double containing the actual value.
-
NumberValue
Copy constructor.- Parameters:
other
- value to copy.
-
-
Method Details
-
valueOf
This method attempts to convert the object to a NumberValue. An empty string or null value is converted to UNKNOWN. Any number (int, long, double, BigDecimal, etc...) is directly converted the corresponding NumberValue. A non-empty string will be parsed using the default (system) locale/culture.- Parameters:
obj
- The object that should be converted to a NumberValue.- Returns:
- The NumberValue for the object.
- Throws:
ConversionException
- This exception is thrown when the object could not be converted.
-
parseDouble
This method will attempt to convert the object to a primitive double value.- Parameters:
obj
- The object that should be converted to the primitive type.- Returns:
- The primitive number for the object.
- Throws:
ConversionException
- This exception is thrown when the object could not be converted to a primitive number.
-
forType
Description copied from interface:IPrimitiveValue
This method adds the type and display information to the value, and returns the value with this added information. The method will not change the state of the value the method is invoked on, but it will return a copy of the current value with the added information.- Specified by:
forType
in interfaceIPrimitiveValue
- Specified by:
forType
in classAbstractValue
- Parameters:
typeName
- The type of the value.displayValue
- Multilingual text containing display values.- Returns:
- The value with the added information.
-
contains
Description copied from interface:IValue
This method returns a boolean indicating if the object passed to this method is entirely part of this value. This method will thus also return true when the object passed is equal to this value, but the method will return false when only part (or none) of the object is represented by this value. Note that for value types that are singular in nature (for instance, implementations of ISingleValue) the operation of this method is limited to an equality check.- Specified by:
contains
in interfaceIValue
- Specified by:
contains
in classAbstractValue
- Parameters:
objValue
- Object for which should be checked if it is entirely part of this value.- Returns:
- boolean indicating if the object passed is entirely part of this value.
-
getDataType
Description copied from interface:IValue
This method returns the data type of the value.- Specified by:
getDataType
in interfaceIValue
- Specified by:
getDataType
in classAbstractValue
- Returns:
- The data type of the value.
-
isUnknown
public boolean isUnknown()Description copied from interface:IValue
This method returns a boolean indicating if the value is unknown.- Specified by:
isUnknown
in interfaceIValue
- Specified by:
isUnknown
in classAbstractValue
- Returns:
- boolean indicating if the value is unknown.
-
compareSimple
- Specified by:
compareSimple
in classAbstractValue
-
doubleCompare
public int doubleCompare(double a, double b) This method compares two doubles using a small margin to determine if the doubles are equal.- Parameters:
a
- The first double value that should be compared.b
- The second double value that should be compared.- Returns:
- Integer containing the result of the compare.
-
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractValue
-
equals
- Overrides:
equals
in classAbstractValue
-
toString
-
getValue
Description copied from interface:IConvertable
This method returns the internal object of this instance without any conversion.- Specified by:
getValue
in interfaceIConvertable
- Specified by:
getValue
in classAbstractValue
- Returns:
- The internal Object of this attribute value.
-
booleanValue
public boolean booleanValue()Description copied from interface:IConvertable
This method converts the internal value to a boolean primitive.- Specified by:
booleanValue
in interfaceIConvertable
- Specified by:
booleanValue
in classAbstractValue
- Returns:
- Boolean primitive of the internal value.
-
dateValue
Description copied from interface:IConvertable
This method converts the internal value to a date object.- Specified by:
dateValue
in interfaceIConvertable
- Specified by:
dateValue
in classAbstractValue
- Returns:
- Date object of the internal value.
-
doubleValue
public double doubleValue()Description copied from interface:IConvertable
This method converts the internal value to a double primitive.- Specified by:
doubleValue
in interfaceIConvertable
- Specified by:
doubleValue
in classAbstractValue
- Returns:
- Double primitive of the internal value.
-
integerValue
public int integerValue()Description copied from interface:IConvertable
This method converts the internal value to an integer primitive.- Specified by:
integerValue
in interfaceIConvertable
- Specified by:
integerValue
in classAbstractValue
- Returns:
- Integer primitive of the internal value.
-
longValue
public long longValue()Description copied from interface:IConvertable
This method converts the internal value to a long primitive.- Specified by:
longValue
in interfaceIConvertable
- Specified by:
longValue
in classAbstractValue
- Returns:
- Long primitive of the internal value.
-
stringValue
Description copied from interface:IConvertable
This method converts the internal value to a String object.- Specified by:
stringValue
in interfaceIConvertable
- Specified by:
stringValue
in classAbstractValue
- Returns:
- String object of the internal value.
-
duplicate
Description copied from interface:IValue
This method returns a deep copy of the value.- Specified by:
duplicate
in interfaceIValue
- Specified by:
duplicate
in classAbstractValue
- Returns:
- A deep clone.
-