|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.apama.event.parser.DecimalFieldValue
public class DecimalFieldValue
Represents the value of an Apama BigDecimal
objects, and the double representation
is available for values that BigDecimal cannot represent.
Example usage:
Field<DecimalFieldValue> decimalField = FieldTypes.DECIMAL.newField("decimalField");
EventParser eventParser = new EventParser(new EventType("sample.MyEvent", decimalField));
Event e = eventParser.parse("sample.MyEvent(123.4750000001)");
DecimalFieldValue decimalValue = e.getField(decimalField);
// DecimalFieldValue.ToString() will automatically determine which of the BigDecimal or Float values are correct
System.out.println("Decimal ToString is: "+decimalValue.toString());
String decimalValueString;
if (decimalValue.getValue() != null)
{
// If the value is representable by BigDecimals then Value will return a non-null and correct value
decimalValueString = decimalValue.getValue().toString();
}
else
{
// If the value is not representable by BigDecimals, then getValue() will return null and
// getFloatValue() will return the float representation of the number, i.e. NaN, Infinity etc...
double decimalValueAsFloat = decimalValue.getFloatValue();
decimalValueString = String.format("%f", decimalValueAsFloat);
}
// The original number is stored as a string
System.out.println("Decimal original value was: " + decimalValue.getStringValue() + "; current decimal value is: " + decimalValueString);
Constructor Summary | |
---|---|
DecimalFieldValue(java.math.BigDecimal value)
Create a new DecimalFieldValue from a BigDecimal |
|
DecimalFieldValue(java.lang.String value)
Create a new DecimalFieldValue from a String value |
Method Summary | |
---|---|
double |
getFloatValue()
Get the floating point value. |
java.lang.String |
getStringValue()
Get the string representation, This is the original string value(or the BigDecimal converted) |
java.math.BigDecimal |
getValue()
Get the value as a BigDecimal. |
boolean |
isInfinity()
Test whether the value is an infinity |
boolean |
isNaN()
Test whether value is not a number |
java.lang.String |
toString()
toString, stringify this instance of a DecimalFieldValue, |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DecimalFieldValue(java.lang.String value)
This constructor can be used to create a value from a String.
This allows a range of values unrepresentable by the Java BigDecimal
class to be stored - namely Infinities and NaN (Not a Number) values.
If these values are created, they are stored internally using a double
which can be retrieved using getFloatValue()
and the BigDecimal representation obtained from getValue()
will be null.
If the value is storeable as a BigDecimal, then the double
representation will be stored as accurately as possible. If
it exceeds the range storeable by a double, the double value
will be set to + or -Infinity or 0 depending on the size of the value.
value
- the string value to create the DecimalFieldValue from.public DecimalFieldValue(java.math.BigDecimal value)
When using this constructor, note that a double's value is capped at
Infinity, so if the parameter value represents a value larger than a double
can represent then the getFloatValue()
function will return Infinity
and the getValue()
function will return the BigDecimalValue
value
- the BigDecimal version, used to create the DecimalFieldValue from.Method Detail |
---|
public java.math.BigDecimal getValue()
The BigDecimal representation can be null in the cases where
it is not representable by the BigDecimal type, i.e. if its NaN, Positive/Negative Infinity.
If this is so, then call getFloatValue()
public double getFloatValue()
If the BigDecimal representation is null then the float value will represent as near to an accurate value as possible i.e. it will be able to represent NaN, Infinity etc. Please note
getValue()
will return a more accurate representation.
public java.lang.String getStringValue()
public boolean isNaN()
Helper method to indicate if this instance of a DecimalFieldValue represents a NaN value
public boolean isInfinity()
Helper method to indicate if this instance of a DecimalFieldValue represents an infinity value
public java.lang.String toString()
This uses the BigDecimal representation if it is not null, otherwise it uses the floating point representation, which could show NaN etc
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |