public class Money extends Object implements Comparable<Money>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_COUNTRY
Default country code for locale
|
static String |
DEFAULT_LANGUAGE
Default Language used for locale
|
static RoundingMode |
DEFAULT_ROUNDING
Default rounding mode is HALF_UP
|
Constructor and Description |
---|
Money()
Create a new default money instance with a zero value using default rounding
|
Money(BigDecimal aAmount)
Create a new money instance with an amount using default currency and rounding mode
|
Money(BigDecimal aAmount,
Currency aCurrency)
Create a new money instance with custom currencies and rounding mode
|
Money(BigDecimal aAmount,
Locale locale,
Currency aCurrency,
RoundingMode aMode)
Create a new money instance with custom currencies and rounding mode
|
Money(double aAmount)
Create a new money instance
|
Money(int aAmount)
Create a new money instance
|
Money(Money m)
Create a copy of some other money instance
|
Money(String aAmount)
Create a new money instance
|
Modifier and Type | Method and Description |
---|---|
Money |
abs() |
BigDecimal |
asBigDecimal() |
int |
asDBInteger()
Multiply the current amount by 100 and return the integer value
|
int |
compareTo(Money aThat) |
static Money |
createFromStringOrZero(String money)
Create a new Money instance, and if something goes wrong return a money
instance with a zero amount.
|
boolean |
currencyMatch(Money aThat)
Check to see if currencies match
|
Money |
div(double divisor) |
Money |
div(int divisor) |
Money |
div(Money divisor) |
boolean |
equals(Money aThat)
Equals (insensitive to scale).
|
boolean |
equals(Object aThat) |
float |
floatValue() |
static Money |
fromDBInt(int val) |
Currency |
getCurrency() |
Locale |
getLocale() |
RoundingMode |
getRoundingMode() |
Locale[] |
getValidLocales()
Return a list of valid locales
|
String[] |
getValidLocaleStrings()
Return a list of valid locales by string representation
|
boolean |
greaterThan(Money aThat)
Greater than.
|
boolean |
greaterThanEqualToZero() |
boolean |
greaterThanOrEqualTo(Money aThat)
Greater than or equal to.
|
boolean |
greaterThanZero() |
int |
hashCode() |
int |
intVal()
Retrieve the exact value as an integer.
|
boolean |
isEmpty()
Check to see of money is zero
|
boolean |
isNegative()
Check to see if money is negative
|
boolean |
isPositive()
Check to see if money is positive
|
boolean |
lessThan(Money aThat)
Less than.
|
boolean |
lessThanEqualToZero() |
boolean |
lessThanOrEqualTo(Money aThat)
Less than or equal to.
|
boolean |
lessThanZero() |
Money |
minus(Money m)
Subtract money from money
|
int |
mod(int divisor) |
Money |
negate() |
Money |
plus(Money m)
Add 2 monies together
|
Money |
sum(Collection<Money> cm)
Add a collection of moneys together
|
Money |
times(double factor) |
Money |
times(int factor) |
Money |
times(Money factor) |
String |
toCurrencyString() |
String |
toPercentString() |
String |
toString() |
public static final RoundingMode DEFAULT_ROUNDING
public static final String DEFAULT_LANGUAGE
public static final String DEFAULT_COUNTRY
public Money()
public Money(Money m)
m
- public Money(BigDecimal aAmount, Locale locale, Currency aCurrency, RoundingMode aMode)
aAmount
- Amountlocale
- The localeaCurrency
- CurrencyaMode
- Rounding Modepublic Money(BigDecimal aAmount, Currency aCurrency)
aAmount
- AmountaCurrency
- Currencypublic Money(BigDecimal aAmount)
aAmount
- Amountpublic Money(int aAmount)
aAmount
- Amountpublic Money(String aAmount) throws ParseException
aAmount
- AmountParseException
public Money(double aAmount)
aAmount
- Amountpublic static Money createFromStringOrZero(String money)
money
- public static Money fromDBInt(int val)
public boolean currencyMatch(Money aThat)
aThat
- Money to checkpublic boolean isPositive()
public boolean isNegative()
public boolean isEmpty()
public Money plus(Money m) throws CurrencyMismatchException
m
- MoneyCurrencyMismatchException
- if currencies don't matchpublic Money sum(Collection<Money> cm) throws CurrencyMismatchException
cm
- Money collectionCurrencyMismatchException
- if currencies don't matchpublic Money minus(Money m) throws CurrencyMismatchException
m
- Amount to subtractCurrencyMismatchException
public Money times(double factor)
public Money times(int factor)
public Money times(Money factor) throws CurrencyMismatchException
CurrencyMismatchException
public Money div(int divisor)
public Money div(double divisor)
public int mod(int divisor)
public Money abs()
public Money negate()
public Currency getCurrency()
public Locale getLocale()
public RoundingMode getRoundingMode()
public BigDecimal asBigDecimal()
public float floatValue()
public String toCurrencyString()
public String toPercentString()
public Locale[] getValidLocales()
public String[] getValidLocaleStrings()
public boolean equals(Money aThat)
Return true only if the amounts are equal. Currencies must match. This method is not synonymous with the equals method.
public boolean greaterThan(Money aThat)
Return true only if 'this' amount is greater than 'that' amount. Currencies must match.
public boolean greaterThanZero()
public boolean greaterThanEqualToZero()
public boolean lessThanZero()
public boolean lessThanEqualToZero()
public boolean greaterThanOrEqualTo(Money aThat)
Return true only if 'this' amount is greater than or equal to 'that' amount. Currencies must match.
public boolean lessThan(Money aThat)
Return true only if 'this' amount is less than 'that' amount. Currencies must match.
public boolean lessThanOrEqualTo(Money aThat)
Return true only if 'this' amount is less than or equal to 'that' amount. Currencies must match.
public int intVal()
public int asDBInteger()
public int compareTo(Money aThat)
compareTo
in interface Comparable<Money>
Copyright © 2017. All rights reserved.