com.crystaldecisions.reports.common.value
Class NumericValue

java.lang.Object
  extended by CrystalValue
      extended by com.crystaldecisions.reports.common.value.FormulaValue
          extended by com.crystaldecisions.reports.common.value.NumericValue
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
CurrencyValue, NumberValue

public abstract class NumericValue
extends FormulaValue
implements java.lang.Comparable

Provides methods for converting native Java types to a format understood by the Crystal Reports Formula Language. All Java user defined functions must return a FormulaValue object.


Field Summary
static int nExactDecimalPlaces
           Two decimal places are used for a NumericValue.
static double scalingFactor
           The actual value of a NumericValue is multiplied by the scalingFactor in order to produce a scaled value.
 
Method Summary
 int compareTo(java.lang.Object obj)
           Internal use only.
 int compareTo(java.lang.Object obj, java.util.Comparator stringComparator)
           Internal use only.
 boolean equals(java.lang.Object obj, boolean caseInsensitive)
           Returns true if obj has the same class and value as this NumericValue object.
static NumericValue fromDouble(double value, FormulaValueType valueType)
           Returns a NumberValue or CurrencyValue which represents the given double value.
static NumericValue fromLong(long value, FormulaValueType valueType)
           Returns a NumberValue or CurrencyValue which represents the given long value.
static NumericValue fromNumericValue(NumericValue numericValue, FormulaValueType valueType)
           Returns a NumberValue or CurrencyValue that represents the given NumericValue object.
static NumericValue fromScaledDouble(double scaledDouble, FormulaValueType valueType)
           Returns a NumericValue object that represents the value of scaledDouble / scalingFactor.
static NumericValue fromScaledLong(long scaledLong, FormulaValueType valueType)
           Returns a NumericValue object that represents the value of scaledLong / scalingFactor.
static double getAsDouble(CrystalValue value, double defaultValue)
           
static int getAsInteger(CrystalValue value, int defaultValue)
           
 double getDouble()
           Gets the unscaled value as a double.
 int getInt()
           Gets the unscaled value as an int.
 long getLong()
           Gets the unscaled value as a long.
 NumericValue getNormalizedNumericValue()
           Returns a NumericValue object that contains a normalized double value.
 double getScaledDouble()
           Gets the scaled value as a double.
 int getScaledInt()
           Gets the scaled value as an int.
 long getScaledLong()
           Gets the scaled value as a long.
 int hashCode(boolean caseInsensitive)
           Returns a hash code for this NumericValue object.
 boolean isIntegerValue()
           Returns true if the value of this NumericValue object can be represented as an integer without any loss of magnitude or precision.
 java.lang.String toString()
           Returns a String representation of this NumericValue object.
 
Methods inherited from class com.crystaldecisions.reports.common.value.FormulaValue
coerce, coerceToArray, coerceToArray, coerceToBoolean, coerceToBoolean, coerceToCurrency, coerceToCurrency, coerceToDate, coerceToDate, coerceToDateTime, coerceToDateTime, coerceToNumber, coerceToNumber, coerceToRange, coerceToRange, coerceToRangeArray, coerceToRangeArray, coerceToString, coerceToString, coerceToTime, coerceToTime, getFormulaValueType, Load, LoadFromArchive, makeZeroValue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

scalingFactor

public static final double scalingFactor

The actual value of a NumericValue is multiplied by the scalingFactor in order to produce a scaled value.

See Also:
Constant Field Values

nExactDecimalPlaces

public static final int nExactDecimalPlaces

Two decimal places are used for a NumericValue.

See Also:
Constant Field Values
Method Detail

fromScaledDouble

public static NumericValue fromScaledDouble(double scaledDouble,
                                            FormulaValueType valueType)

Returns a NumericValue object that represents the value of scaledDouble / scalingFactor.

Parameters:
scaledDouble - a double with a value equal to actualValue * scalingFactor
valueType - either FormulaValueType.number or FormulaValueType.currency
Returns:
a NumericValue object that represents the value of scaledDouble / scalingFactor
Throws:
java.lang.UnsupportedOperationException - if valueType is neither FormulaValueType.number nor FormulaValueType.currency

fromScaledLong

public static NumericValue fromScaledLong(long scaledLong,
                                          FormulaValueType valueType)

Returns a NumericValue object that represents the value of scaledLong / scalingFactor.

Parameters:
scaledLong - a long with a value equal to actualValue * scalingFactor
valueType - either FormulaValueType.number or FormulaValueType.currency
Returns:
a NumericValue object that represents the value of scaledLong / scalingFactor
Throws:
java.lang.UnsupportedOperationException - if valueType is neither FormulaValueType.number nor FormulaValueType.currency

fromDouble

public static NumericValue fromDouble(double value,
                                      FormulaValueType valueType)

Returns a NumberValue or CurrencyValue which represents the given double value.

Parameters:
value - the double value to be represented (no scaling has been applied)
valueType - either FormulaValueType.number or FormulaValueType.currency
Returns:
a NumericValue that represents the given double value
Throws:
java.lang.UnsupportedOperationException - if valueType is neither FormulaValueType.number nor FormulaValueType.currency

fromLong

public static NumericValue fromLong(long value,
                                    FormulaValueType valueType)

Returns a NumberValue or CurrencyValue which represents the given long value.


Note: the current implementation of NumericValue uses a double to store its value. As a result, there is a potential for a loss of precision when creating a NumericValue from a large long value.

Parameters:
value - the long value to be represented (no scaling has been applied)
valueType - either FormulaValueType.number or FormulaValueType.currency
Returns:
a NumericValue that represents the given long value
Throws:
java.lang.UnsupportedOperationException - if valueType is neither FormulaValueType.number nor FormulaValueType.currency

fromNumericValue

public static NumericValue fromNumericValue(NumericValue numericValue,
                                            FormulaValueType valueType)

Returns a NumberValue or CurrencyValue that represents the given NumericValue object.

Parameters:
numericValue - the NumericValue to be represented
valueType - either FormulaValueType.number or FormulaValueType.currency
Returns:
a NumericValue object
Throws:
java.lang.UnsupportedOperationException - if valueType is neither FormulaValueType.number nor FormulaValueType.currency

getNormalizedNumericValue

public final NumericValue getNormalizedNumericValue()

Returns a NumericValue object that contains a normalized double value.

Returns:
a NumericValue object that contains a normalized double value

getScaledDouble

public final double getScaledDouble()

Gets the scaled value as a double.

Returns:
the scaled value as a double

getScaledLong

public final long getScaledLong()

Gets the scaled value as a long.

Returns:
the scaled value as a long

getScaledInt

public final int getScaledInt()

Gets the scaled value as an int.

Returns:
the scaled value as an int

getDouble

public final double getDouble()

Gets the unscaled value as a double.

Returns:
the unscaled value as a double

getLong

public final long getLong()

Gets the unscaled value as a long.

Returns:
the unscaled value as a long

getInt

public final int getInt()

Gets the unscaled value as an int.

Returns:
the unscaled value as an int

isIntegerValue

public final boolean isIntegerValue()

Returns true if the value of this NumericValue object can be represented as an integer without any loss of magnitude or precision.

Returns:
true if the value of this NumericValue object can be represented as an integer without any loss of magnitude or precision, otherwise false

hashCode

public int hashCode(boolean caseInsensitive)

Returns a hash code for this NumericValue object.

Returns:
an int that is a hash code for this NumericValue object

equals

public boolean equals(java.lang.Object obj,
                      boolean caseInsensitive)

Returns true if obj has the same class and value as this NumericValue object.

Parameters:
obj - the Object to compare this NumericValue object to
Returns:
true if obj has the same class and value as this NumericValue object, otherwise false

compareTo

public int compareTo(java.lang.Object obj,
                     java.util.Comparator stringComparator)

Internal use only.


compareTo

public int compareTo(java.lang.Object obj)

Internal use only.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()

Returns a String representation of this NumericValue object. The String is of the form: "(42.37)".

Returns:
a String representation of this NumericValue object

getAsInteger

public static int getAsInteger(CrystalValue value,
                               int defaultValue)

getAsDouble

public static double getAsDouble(CrystalValue value,
                                 double defaultValue)