Top Description Fields Constructors Methods
org.javamoney.moneta

public final Class RoundedMoney

extends Object
implements MonetaryAmount, Comparable<MonetaryAmount>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable, javax.money.MonetaryAmount, javax.money.NumberSupplier, javax.money.CurrencySupplier
Imports
org.javamoney.moneta.format.ToStringMonetaryAmountFormat, .ToStringMonetaryAmountFormat.ToStringMonetaryAmountFormatStyle, .MonetaryAmountDecimalFormat, org.javamoney.moneta.spi.RoundedMoneyAmountFactory, .DefaultNumberValue, .MonetaryConfig, .MoneyUtils, javax.money.*, javax.money.format.MonetaryAmountFormat, java.io.Serializable, java.math.BigDecimal, .BigInteger, .MathContext, .RoundingMode, java.util.Objects, .Optional, java.util.logging.Level, .Logger

Platform RI: Default immutable implementation of MonetaryAmount based on BigDecimal for the numeric representation.

As required by MonetaryAmount this class is final, thread-safe, immutable and serializable.

Authors
Anatole Tresch, Werner Keil, Otavio Santana
Version
1.0

Field Summary

Modifier and TypeField and Description
private final CurrencyUnit
currency

The currency of this amount.

public static final MonetaryContext
private final MonetaryContext
monetaryContext

the MonetaryContext used by this instance, e.g. on division.

private final BigDecimal
number

The numeric part of this amount.

private final MonetaryOperator
rounding

The rounding to be done.

private static final long
serialVersionUID

serialVersionUID.

Constructor Summary

AccessConstructor and Description
public
RoundedMoney(Number
the amount, not null.
number
,
CurrencyUnit
the currency, not null.
currency
,
MonetaryOperator rounding)

Creates a new instance of RoundedMoney.

public
RoundedMoney(Number number, CurrencyUnit currency, MathContext mathContext)
Deprecated

public
RoundedMoney(Number number, CurrencyUnit currency, MonetaryContext context, MonetaryOperator rounding)
Deprecated

Method Summary

Modifier and TypeMethod and Description
public RoundedMoney
abs()

Implements javax.money.MonetaryAmount.abs.

Returns a MonetaryAmount whose value is the absolute value of this MonetaryAmount, and whose scale is this.getContext().getMaxScale().

public RoundedMoney
add(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.add.

Returns a MonetaryAmount whose value is this + augend, and whose scale is max(this.getContext().getMaxScale(), augend.getContext().getMaxScale()).

public BigDecimal

Returns:

the stripped number value.
asNumberStripped
()

Method that returns BigDecimal.ZERO, if isZero(), and #number stripTrailingZeros() in all other cases.

public <T> T
asType(Class<T> type)
Deprecated

public <T> T
asType(Class<T> type, MonetaryOperator adjuster)
Deprecated

private void
checkNumber(Number
the number to check.
number
)

Internal method to check for correct number parameter.

public int
compareTo(MonetaryAmount o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

private static MonetaryAmountFormat
public RoundedMoney
divide(Number divisor)

Implements javax.money.MonetaryAmount.divide.

Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.

public RoundedMoney
divide(long divisor)

Implements javax.money.MonetaryAmount.divide.

Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.

public RoundedMoney
divide(double divisor)

Implements javax.money.MonetaryAmount.divide.

Returns a MonetaryAmount whose value is this / divisor, and whose preferred scale is this.getContext().getMaxScale() - divisor.getContext().getMaxScale(); if the exact quotient cannot be represented an ArithmeticException is thrown.

public RoundedMoney[]
divideAndRemainder(Number divisor)

Implements javax.money.MonetaryAmount.divideAndRemainder.

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public RoundedMoney[]
divideAndRemainder(long divisor)

Implements javax.money.MonetaryAmount.divideAndRemainder.

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public RoundedMoney[]
divideAndRemainder(double divisor)

Implements javax.money.MonetaryAmount.divideAndRemainder.

Returns a two-element MonetaryAmount array containing the result of divideToIntegralValue followed by the result of remainder on the two operands.

public RoundedMoney
divideToIntegralValue(Number divisor)

Implements javax.money.MonetaryAmount.divideToIntegralValue.

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public RoundedMoney
divideToIntegralValue(long divisor)

Implements javax.money.MonetaryAmount.divideToIntegralValue.

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public RoundedMoney
divideToIntegralValue(double divisor)

Implements javax.money.MonetaryAmount.divideToIntegralValue.

Returns a MonetaryAmount whose value is the integer part of the quotient this / divisor rounded down.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static RoundedMoney
public MonetaryContext

Returns:

the MathContext used, never null.
getContext
()

Implements javax.money.MonetaryAmount.getContext.

Access the MathContext used by this instance.

public CurrencyUnit
public MonetaryAmountFactory<RoundedMoney>
getFactory()

Implements javax.money.MonetaryAmount.getFactory.

Creates a new MonetaryAmountFactory, returning the same implementation type Hereby this given amount is used as a template, so reusing the CurrencyUnit, its numeric value, the algorithmic implementation as well as the current MonetaryContext.

public NumberValue
public int

Returns:

the precision of this RoundedMoney.
getPrecision
()

Returns the precision of this RoundedMoney.

public int

Returns:

the scale of this RoundedMoney.
getScale
()

Returns the scale of this RoundedMoney.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
isEqualTo(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.isEqualTo.

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean
isGreaterThan(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.isGreaterThan.

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean
isGreaterThanOrEqualTo(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.isGreaterThanOrEqualTo.

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean
isLessThan(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.isLessThan.

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean
isLessThanOrEqualTo(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.isLessThanOrEqualTo.

Compares two instances of MonetaryAmount, hereby ignoring non significant trailing zeroes and different numeric capabilities.

public boolean
isNegative()

Overrides default javax.money.MonetaryAmount.isNegative.

Checks if a MonetaryAmount is negative.

public boolean
isNegativeOrZero()

Overrides default javax.money.MonetaryAmount.isNegativeOrZero.

Checks if a MonetaryAmount is negative or zero.

public boolean
private boolean
isOne(Number number)

public boolean
isPositive()

Overrides default javax.money.MonetaryAmount.isPositive.

Checks if a MonetaryAmount is positive.

public boolean
isPositiveOrZero()

Overrides default javax.money.MonetaryAmount.isPositiveOrZero.

Checks if a MonetaryAmount is positive or zero.

public boolean
isZero()

Overrides default javax.money.MonetaryAmount.isZero.

Checks if an MonetaryAmount is zero.

public RoundedMoney
multiply(Number multiplicand)

Implements javax.money.MonetaryAmount.multiply.

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public RoundedMoney
multiply(long multiplicand)

Implements javax.money.MonetaryAmount.multiply.

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public RoundedMoney
multiply(double multiplicand)

Implements javax.money.MonetaryAmount.multiply.

Returns a MonetaryAmount whose value is (this × multiplicand), and whose scale is this.getContext().getMaxScale() + multiplicand.getContext().getMaxScale().

public RoundedMoney
negate()

Implements javax.money.MonetaryAmount.negate.

Returns a MonetaryAmount whose value is -this, and whose scale is this.getContext().getMaxScale(), with rounding according to the context settings.

public static RoundedMoney

Returns:

a Money combining the numeric value and currency unit.
of
(BigDecimal
numeric value of the Money.
number
,
CurrencyUnit
currency unit of the Money.
currency
)

Translates a BigDecimal value and a CurrencyUnit currency into a Money.

public static RoundedMoney

Returns:

a Money combining the numeric value and currency unit.
of
(BigDecimal
numeric value of the Money.
number
,
CurrencyUnit
currency unit of the Money.
currency
,
MonetaryOperator
The rounding to be applied.
rounding
)

Translates a BigDecimal value and a CurrencyUnit currency into a Money.

public static RoundedMoney

Returns:

a Money combining the numeric value and currency unit.
of
(BigDecimal
numeric value of the Money.
number
,
CurrencyUnit
currency unit of the Money.
currency
,
MathContext
the MathContext to be used.
mathContext
)

Translates a BigDecimal value and a CurrencyUnit currency into a Money.

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
CurrencyUnit
The target currency, not null.
currency
)
Deprecated

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
CurrencyUnit
The target currency, not null.
currency
,
MonetaryOperator
The rounding to be applied.
rounding
)

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
CurrencyUnit
The target currency, not null.
currency
,
MonetaryContext monetaryContext)

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(CurrencyUnit
The target currency, not null.
currency
,
Number
The numeric part, not null.
number
,
MonetaryContext
the MonetaryContext to be used.
monetaryContext
,
MonetaryOperator
The rounding to be applied.
rounding
)
Deprecated

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
String
The target currency as ISO currency code.
currencyCode
)
Deprecated

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
String
The target currency as ISO currency code.
currencyCode
,
MonetaryOperator
The rounding to be applied.
rounding
)

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(Number
The numeric part, not null.
number
,
String
The target currency as ISO currency code.
currencyCode
,
MonetaryContext monetaryContext)
Deprecated

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

A new instance of RoundedMoney.
of
(String
The target currency as ISO currency code.
currencyCode
,
Number
The numeric part, not null.
number
,
MonetaryContext monetaryContext, MonetaryOperator
The rounding to be applied.
rounding
)

Static factory method for creating a new instance of RoundedMoney .

public static RoundedMoney

Returns:

the Money from minor units
ofMinor
(CurrencyUnit
the currency, not null
currency
,
long
the amount of money in the minor division of the currency
amountMinor
)

Obtains an instance of RoundedMoney from an amount in minor units.

public static RoundedMoney

Returns:

the monetary amount from minor units
ofMinor
(CurrencyUnit
the currency, not null
currency
,
long
the amount of money in the minor division of the currency
amountMinor
,
int
number of digits
factionDigits
)

Obtains an instance of RoundedMoney from an amount in minor units.

public static RoundedMoney

Returns:

RoundedMoney instance
parse
(CharSequence
the input text, not null.
text
)

Obtains an instance of RoundedMoney from a text string such as 'EUR 25.25'.

public static RoundedMoney

Returns:

RoundedMoney instance
parse
(CharSequence
the text to parse not null
text
,
MonetaryAmountFormat
the formatter to use not null
formatter
)

Obtains an instance of FastMoney from a text using specific formatter.

public RoundedMoney
plus()

Implements javax.money.MonetaryAmount.plus.

Returns a MonetaryAmount whose value is +this.

public RoundedMoney
pow(int n)

public <T> T
query(MonetaryQuery<T> query)

Overrides default javax.money.MonetaryAmount.query.

Queries this monetary amount for a value.

public RoundedMoney
remainder(Number divisor)

Implements javax.money.MonetaryAmount.remainder.

Returns a MonetaryAmount whose value is this % divisor.

public RoundedMoney
remainder(long divisor)

Implements javax.money.MonetaryAmount.remainder.

Returns a MonetaryAmount whose value is this % divisor.

public RoundedMoney
remainder(double divisor)

Implements javax.money.MonetaryAmount.remainder.

Returns a MonetaryAmount whose value is this % divisor.

public RoundedMoney
scaleByPowerOfTen(int power)

Implements javax.money.MonetaryAmount.scaleByPowerOfTen.

Returns a MonetaryAmount whose numerical value is equal to ( this * 10n).

public int
signum()

Implements javax.money.MonetaryAmount.signum.

Returns the signum function of this MonetaryAmount.

public RoundedMoney
stripTrailingZeros()

Implements javax.money.MonetaryAmount.stripTrailingZeros.

Returns a MonetaryAmount which is numerically equal to this one but with any trailing zeros removed from the representation.

public RoundedMoney
subtract(MonetaryAmount amount)

Implements javax.money.MonetaryAmount.subtract.

Returns a MonetaryAmount whose value is this - amount, and whose scale is max(this.getContext().getMaxScale(), subtrahend.getContext().getMaxScale().

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public RoundedMoney
ulp()

public RoundedMoney
with(Number amount)

public RoundedMoney

Returns:

the new amount with the same numeric value and MathContext, but the new CurrencyUnit.
with
(CurrencyUnit
the currency unit to be replaced, not null
currency
)

Creates a new Money instance, by just replacing the CurrencyUnit.

public RoundedMoney
with(CurrencyUnit currency, Number amount)

public RoundedMoney
with(MonetaryOperator operator)

Overrides default javax.money.MonetaryAmount.with.

Returns an operated object of the same type as this object with the operation made.

public static RoundedMoney

Returns:

an instance of RoundedMoney representing zero.
zero
(CurrencyUnit
the currency, not null.
currency
)

Obtains an instance of RoundedMoney representing zero.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait