com.apama.event.parser
Class DecimalFieldValue

java.lang.Object
  extended by com.apama.event.parser.DecimalFieldValue

public class DecimalFieldValue
extends java.lang.Object

Represents the value of an Apama decimal field. Values are stored/retrievable as 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

DecimalFieldValue

public DecimalFieldValue(java.lang.String value)
Create a new DecimalFieldValue from a 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.

Parameters:
value - the string value to create the DecimalFieldValue from.

DecimalFieldValue

public DecimalFieldValue(java.math.BigDecimal value)
Create a new DecimalFieldValue from a BigDecimal

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

Parameters:
value - the BigDecimal version, used to create the DecimalFieldValue from.
Method Detail

getValue

public java.math.BigDecimal getValue()
Get the value as a BigDecimal.

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()

Returns:
an object specifying the BigDecimal value.

getFloatValue

public double getFloatValue()
Get the floating point value.

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

Returns:
an object specifying the float value.

getStringValue

public java.lang.String getStringValue()
Get the string representation, This is the original string value(or the BigDecimal converted)

Returns:
an object specifying the string representation of the number.

isNaN

public boolean isNaN()
Test whether value is not a number

Helper method to indicate if this instance of a DecimalFieldValue represents a NaN value

Returns:
true if value is NaN (Not a Number)

isInfinity

public boolean isInfinity()
Test whether the value is an infinity

Helper method to indicate if this instance of a DecimalFieldValue represents an infinity value

Returns:
true if value is an Infinity

toString

public java.lang.String toString()
toString, stringify this instance of a DecimalFieldValue,

This uses the BigDecimal representation if it is not null, otherwise it uses the floating point representation, which could show NaN etc

Overrides:
toString in class java.lang.Object
Returns:
the stringified version of this DecimalFieldValue.


Submit a bug or feature
Copyright (c) 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG