Top Description Fields Constructors Methods
javax.money

public abstract Class NumberValue

extends Number
implements Comparable<NumberValue>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.math.BigDecimal, .MathContext

Instances of this class allow to externalize the numeric value of a MonetaryAmount. The class extends java.lang.Number for maximal compatibility with the JDK but also adds additional functionality to overcome some of the pitfalls of the JDK's Number class.

Implementation specification

Implementations of this interface must be :

Author
Anatole Tresch

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(NumberValue
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public abstract double

Returns:

the (possibly) truncated value of the MonetaryAmount.
doubleValueExact
()

Access the numeric value as double.

public abstract long

Returns:

the amount's fraction denominator.
getAmountFractionDenominator
()

This method allows to extract the denominator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
public abstract long

Returns:

the amount's fraction numerator..
getAmountFractionNumerator
()

This method allows to extract the numerator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
public abstract Class<?>

Returns:

the numeric implementation type, not null.
getNumberType
()

Get the numeric implementation type, that is the base of this number.

public abstract int

Returns:

the precision of this MonetaryAmount.
getPrecision
()

Returns the precision of this MonetaryAmount.

public abstract int

Returns:

the scale of this MonetaryAmount.
getScale
()

Returns the scale of this MonetaryAmount.

public abstract int

Returns:

the (possibly) truncated value of the MonetaryAmount.
intValueExact
()

Access the numeric value as int.

public abstract long

Returns:

the (possibly) truncated value of the MonetaryAmount.
longValueExact
()

Access the numeric value as long.

public abstract <T extends Number> T

Returns:

the (possibly) truncated value of the MonetaryAmount.
numberValue
(Class<T>
The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:
  • java.lang.Long
  • java.lang.Double
  • java.lang.Number
  • java.math.BigInteger, currently not available on all platforms.
  • java.math.BigDecimal, currently not available on all platforms.
numberType
)

Access the numeric value as Number.

public abstract <T extends Number> T

Returns:

the (possibly) truncated value of the MonetaryAmount.
numberValueExact
(Class<T>
The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:
  • java.lang.Long
  • java.lang.Double
  • java.lang.Number
  • java.math.BigInteger, currently not available on all platforms.
  • java.math.BigDecimal, currently not available on all platforms.
numberType
)

Access the numeric value as Number.

public abstract NumberValue

Returns:

the new NumberValue, never null.
round
(MathContext
the java.math.MathContext to be applied.
mathContext
)

Access the current NumberValue rounded using the given java.math.MathContext.

Inherited from java.lang.Number:
byteValuedoubleValuefloatValueintValuelongValueshortValue

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.Number.serialVersionUID.

serialVersionUID.

Constructor Detail

NumberValueback to summary
public NumberValue()

Method Detail

compareToback to summary
public int compareTo(NumberValue other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:NumberValue

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
doubleValueExactback to summary
public abstract double doubleValueExact()

Access the numeric value as double. Hereby no truncation will be performed to fit the value into the target data type.

Returns:double

the (possibly) truncated value of the MonetaryAmount.

Exceptions
ArithmeticException:
If the value must be truncated to fit the target datatype.
getAmountFractionDenominatorback to summary
public abstract long getAmountFractionDenominator()

This method allows to extract the denominator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:

!(w<0 && n>0)  and
!(w>0 && n<0)  and
d>0            and
|n| < d        // || = absolute value
.
Returns:long

the amount's fraction denominator.

getAmountFractionNumeratorback to summary
public abstract long getAmountFractionNumerator()

This method allows to extract the numerator part of the current fraction, hereby given


w = longValue()
n = getFractionNominator()
d = getFractionDenominator()
the following must be always true:

!(w<0 && n>0)  and
!(w>0 && n<0)  and
d>0            and
|n| < d        // || = absolute value
.
Returns:long

the amount's fraction numerator..

getNumberTypeback to summary
public abstract Class<?> getNumberType()

Get the numeric implementation type, that is the base of this number.

Returns:Class<?>

the numeric implementation type, not null.

getPrecisionback to summary
public abstract int getPrecision()

Returns the precision of this MonetaryAmount. (The precision is the number of digits in the unscaled value.)

The precision of a zero value is 1.

Returns:int

the precision of this MonetaryAmount.

getScaleback to summary
public abstract int getScale()

Returns the scale of this MonetaryAmount. If zero or positive, the scale is the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.

Returns:int

the scale of this MonetaryAmount.

intValueExactback to summary
public abstract int intValueExact()

Access the numeric value as int. Hereby no truncation will be performed to fit the value into the target data type.

Returns:int

the (possibly) truncated value of the MonetaryAmount.

Exceptions
ArithmeticException:
If the value must be truncated to fit the target datatype.
longValueExactback to summary
public abstract long longValueExact()

Access the numeric value as long. Hereby no truncation will be performed to fit the value into the target data type.

Returns:long

the (possibly) truncated value of the MonetaryAmount.

Exceptions
ArithmeticException:
If the value must be truncated to fit the target datatype.
numberValueback to summary
public abstract <T extends Number> T numberValue(Class<T> numberType)

Access the numeric value as Number. Hereby truncation may be performed as needed to fit the value into the target data type.

Parameters
numberType:Class<T>

The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:

  • java.lang.Long
  • java.lang.Double
  • java.lang.Number
  • java.math.BigInteger, currently not available on all platforms.
  • java.math.BigDecimal, currently not available on all platforms.
Returns:T

the (possibly) truncated value of the MonetaryAmount.

numberValueExactback to summary
public abstract <T extends Number> T numberValueExact(Class<T> numberType)

Access the numeric value as Number. Hereby no truncation will be performed to fit the value into the target data type.

Parameters
numberType:Class<T>

The concrete number class to be returned. Basically the following Number types, must be supported if available on the corresponding runtime platform:

  • java.lang.Long
  • java.lang.Double
  • java.lang.Number
  • java.math.BigInteger, currently not available on all platforms.
  • java.math.BigDecimal, currently not available on all platforms.
Returns:T

the (possibly) truncated value of the MonetaryAmount.

Exceptions
ArithmeticException:
If the value must be truncated to fit the target datatype.
roundback to summary
public abstract NumberValue round(MathContext mathContext)

Access the current NumberValue rounded using the given java.math.MathContext.

Parameters
mathContext:MathContext

the java.math.MathContext to be applied.

Returns:NumberValue

the new NumberValue, never null.

See Also
java.math.BigDecimal#round(java.math.MathContext)