|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Number
com.antelmann.math.Money
public final class Money
represents an immutable monetary value that allows exact calculations on currencies. Money instances are immutable and always exact values rounded to the scale of the currency. The value is internally represented as a rounded BigDecimal with a scale corresponding to the given currency.
MoneyConverter,
MoneyFormatFactory,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.antelmann.math.Measurable |
|---|
Measurable.Adapter |
| Field Summary | |
|---|---|
static Money |
NO_MONEY
a convenient instance that equals new Money(BigDecimal.ZERO). |
| Constructor Summary | |
|---|---|
Money()
Deprecated. use NO_MONEY instead |
|
Money(BigDecimal value)
uses the Currency of the default Locale |
|
Money(BigDecimal value,
Currency currency)
|
|
Money(BigDecimal value,
CurrencyUnit currency)
constructor that is called by all others |
|
Money(BigDecimal value,
String currencyCode)
|
|
Money(double d)
convenience constructor using the default currency |
|
Money(Number value)
|
|
Money(Number number,
Currency currency)
|
|
Money(Number value,
CurrencyUnit currency)
|
|
| Method Summary | ||
|---|---|---|
Money |
abs()
returns Money with an absolute (non-negative) value |
|
Money |
add(BigDecimal bd)
|
|
Money |
add(double d)
|
|
Money |
add(Money m)
adds this instance to the other given one and returns the result; this entry itself remains untouched |
|
Money |
add(Number n)
|
|
static
|
aggregate(Map<T,Money> data,
PatternExtractor<T,P> pattern)
utility function |
|
int |
compareTo(Money m)
only compares value of the same currency |
|
Money |
convertTo(Currency c,
BigDecimal exchangeRate)
the given exchangeRage is multiplied with the value |
|
Money |
convertTo(Currency c,
double exchangeRate)
the given exchangeRage is multiplied with the value |
|
Money |
divide(double divisor)
|
|
Money |
divide(Money divisor)
|
|
Money |
divide(Number divisor)
|
|
double |
doubleValue()
|
|
boolean |
equals(Object obj)
note that if the value is zero, it's considered the same even if the currency is different. |
|
float |
floatValue()
|
|
BigDecimal |
getAmount()
represents the quantity of this measurable entity |
|
Currency |
getCurrency()
|
|
static Money |
getSmallestPositiveAmountFor(Currency cur)
|
|
CurrencyUnit |
getUnit()
represents the unit type of this measurable entity |
|
BigDecimal |
getValue()
sames as getAmount() |
|
int |
hashCode()
|
|
int |
intValue()
|
|
boolean |
isCompatibleTo(Money money)
returns true only if the currency is the same or either money value is zero. |
|
boolean |
isNegative()
|
|
boolean |
isPositive()
|
|
boolean |
isZero()
|
|
long |
longValue()
|
|
Money |
multiply(double factor)
|
|
Money |
multiply(long factor)
|
|
Money |
multiply(Money m)
|
|
Money |
multiply(Number factor)
|
|
Money |
negate()
|
|
static BigDecimal |
round(Number n,
Currency c)
|
|
Money |
roundToScale(Number scale)
|
|
int |
signum()
|
|
Money |
subtract(double d)
|
|
Money |
subtract(Money m)
|
|
Money |
subtract(Number b)
|
|
String |
toHtml(Locale l)
provides an HTML encoded String that uses Strings.HTML_SPACE to ensure that
the amount is always displayed in a single line |
|
String |
toHtml(Object context)
returns a String that contains valid HTML to be embedded in other HTML content |
|
Measure<CurrencyUnit> |
toMeasure()
|
|
String |
toString()
uses the currency instance of the default Locale from NumberFormat and applies the applicable currency. |
|
String |
toString(Locale l)
|
|
| Methods inherited from class java.lang.Number |
|---|
byteValue, shortValue |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Money NO_MONEY
equals(Object)| Constructor Detail |
|---|
@Deprecated public Money()
NO_MONEY instead
public Money(double d)
public Money(Number value)
public Money(BigDecimal value)
public Money(Number number,
Currency currency)
public Money(BigDecimal value,
String currencyCode)
throws NullPointerException,
IllegalArgumentException
currencyCode - the ISO 4217 code of the currency
NullPointerException
IllegalArgumentException
public Money(BigDecimal value,
Currency currency)
public Money(Number value,
CurrencyUnit currency)
public Money(BigDecimal value,
CurrencyUnit currency)
| Method Detail |
|---|
public static BigDecimal round(Number n,
Currency c)
public final BigDecimal getAmount()
Measurable
getAmount in interface Measurablepublic final CurrencyUnit getUnit()
Measurable
getUnit in interface Measurablepublic final BigDecimal getValue()
getAmount()
public final double doubleValue()
doubleValue in class Numberpublic final Currency getCurrency()
public final boolean isZero()
public final boolean isNegative()
public final boolean isPositive()
public Measure<CurrencyUnit> toMeasure()
public boolean isCompatibleTo(Money money)
public int compareTo(Money m)
throws WrongCurrencyException
compareTo in interface Comparable<Money>WrongCurrencyException - if the currency is not the sameMoneyConverterpublic boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Objectpublic String toString(Locale l)
public String toHtml(Object context)
HtmlSupported
toHtml in interface HtmlSupportedcontext - depending on the caller, this value may denote the servlet request, JSF context or a null valuepublic String toHtml(Locale l)
Strings.HTML_SPACE to ensure that
the amount is always displayed in a single line
Strings.encodeXML(String)public final Money abs()
public int signum()
public Money add(Money m)
throws WrongCurrencyException
Addable
add in interface Addable<Money>WrongCurrencyExceptionpublic Money add(Number n)
public final Money add(double d)
public final Money add(BigDecimal bd)
public Money subtract(Money m)
throws WrongCurrencyException
WrongCurrencyExceptionpublic final Money subtract(Number b)
public final Money subtract(double d)
public Money multiply(double factor)
public Money multiply(long factor)
public Money multiply(Number factor)
public Money multiply(Money m)
throws WrongCurrencyException
WrongCurrencyExceptionpublic Money divide(double divisor)
public Money divide(Number divisor)
public Money divide(Money divisor)
throws WrongCurrencyException
WrongCurrencyExceptionpublic Money negate()
public Money roundToScale(Number scale)
public Money convertTo(Currency c,
double exchangeRate)
public Money convertTo(Currency c,
BigDecimal exchangeRate)
public float floatValue()
floatValue in class Numberpublic int intValue()
intValue in class Numberpublic long longValue()
longValue in class Number
public static <P,T> HashMap<P,Money> aggregate(Map<T,Money> data,
PatternExtractor<T,P> pattern)
throws WrongCurrencyException
WrongCurrencyExceptionpublic static Money getSmallestPositiveAmountFor(Currency cur)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||