public final class Money
extends java.lang.Object
Constructor and Description |
---|
Money(long amount,
CurrencyCode currencyCode)
Creates a new Money object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
java.lang.String |
format()
Calls
format(Locale) with the default locale. |
java.lang.String |
format(java.util.Locale locale)
Formats this
Money into a human-readable string, taking into account the
associated currency and the provided Locale . |
long |
getAmount()
The amount of money, in the smallest denomination of the specified currency.
|
CurrencyCode |
getCurrencyCode()
The currency code.
|
int |
hashCode() |
Money |
minus(Money amountMoneyToSubtract)
Returns a new
Money instance with the specified money amount subtracted from
this money amount. |
Money |
plus(Money amountMoneyToAdd)
Returns a new money instance with the specified money amount added to this money amount.
|
java.lang.String |
toString() |
public Money(long amount, @NonNull CurrencyCode currencyCode)
amount
- The amount of money, in the smallest denomination of the specified currency.
For example, when the currency is USD, the amount is in cents.currencyCode
- the currency code of the currency associated with the amount.public long getAmount()
@NonNull public CurrencyCode getCurrencyCode()
@NonNull public Money plus(@NonNull Money amountMoneyToAdd) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException
Returns a new money instance with the specified money amount added to this money amount.
This instance is immutable and unaffected by this method call.
amountMoneyToAdd
- The money to add, positive or negative, not null, with the same
currency code as this money.Money
based on this money with the specified money added, not nulljava.lang.IllegalArgumentException
- if the currency code of amountMoneyToAdd is different from
the currency code of this money.java.lang.ArithmeticException
- if numeric overflow occurs@NonNull public Money minus(@NonNull Money amountMoneyToSubtract) throws java.lang.IllegalArgumentException, java.lang.ArithmeticException
Returns a new Money
instance with the specified money amount subtracted from
this money amount.
This instance is immutable and unaffected by this method call.
amountMoneyToSubtract
- The money to subtract, positive or negative, not null, with the
same currency code as this money.Money
based on this money with the specified money subtracted, not nulljava.lang.IllegalArgumentException
- if the currency code of amountMoneyToSubtract is different
from the currency code of this money.java.lang.ArithmeticException
- if numeric overflow occurs@NonNull public java.lang.String format()
format(Locale)
with the default locale.@NonNull public java.lang.String format(@NonNull java.util.Locale locale)
Formats this Money
into a human-readable string, taking into account the
associated currency and the provided Locale
.
new Money(1000, CurrencyCode.USD).format(Locale.US)
returns "$10.00"
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object