Class 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

      Constructors 
      Constructor Description
      DecimalFieldValue​(java.lang.Number value)
      Create a new DecimalFieldValue from a Number
      DecimalFieldValue​(java.lang.String value)
      Create a new DecimalFieldValue from a String value
      DecimalFieldValue​(java.math.BigDecimal value)
      Create a new DecimalFieldValue from a BigDecimal
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      • DecimalFieldValue

        public DecimalFieldValue​(java.lang.Number value)
        Create a new DecimalFieldValue from a Number
        Parameters:
        value - the Number 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

        • in the case where the BigDecimal value exceeds Double.MAX_VALUE either positively or negatively, the value returned from this function will be + or - Infinity, but isInfinity() will return false as the BigDecimal will still represent the proper value.
        • if the value is extremely close to zero, this function may return 0 where getValue() will return a more accurate representation.

        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.