|
Venice 0.7beta | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.mov.util.Money
public class Money
An immutable representation of Money. This class was created to reference
sums of money. Due to rounding issues, the use of float
and to a lesser
extent double
are not recommended to represent money. Therefore
money should be represented by an integer type, which would require conversion
from the more natural floating point type. This class was created to handle
all this conversion work and provide a nice simple abstraction.
Currency
Field Summary | |
---|---|
static Money |
ZERO
Immutable representation of zero money in the default currency. |
Constructor Summary | |
---|---|
Money(Currency currency,
double amount)
Create a new Money instance from the given amount using the
given currency. |
|
Money(Currency currency,
java.lang.String string)
Create a new Money instance by parsing the given string. |
|
Money(double amount)
Create a new Money instance from the given amount using the
default currency. |
Method Summary | |
---|---|
Money |
add(double money)
Add the given money to this money. |
Money |
add(Money money)
Add the given money to this money. |
java.lang.Object |
clone()
Return a clone of this object. |
int |
compareTo(java.lang.Object object)
Compare this money to the specified money. |
Money |
divide(int number)
Divide this money by the given number. |
double |
doubleValue()
Return the value of this Money as a double . |
boolean |
equals(java.lang.Object object)
Compare this money for equality with the specified money. |
Money |
exchange(Currency currency,
double exchangeRate)
Exchange this money for another currency at the given exchange rate. |
Currency |
getCurrency()
Return the currency of this money. |
int |
hashCode()
Return a hash code representation of this money. |
boolean |
isGreaterThan(Money money)
Return whether this money is greater than to the given money. |
boolean |
isGreaterThanEqual(Money money)
Return whether this money is greater than or equal to the given money. |
boolean |
isLessThan(Money money)
Return whether this money is less than the given money. |
boolean |
isLessThanEqual(Money money)
Return whether this money is less than or equal to the given money. |
Money |
multiply(int number)
Multiply this money by the given number. |
Money |
subtract(Money money)
Subtract the given money from this money. |
java.lang.String |
toString()
Returns a String object representing this Money 's value. |
static java.lang.String |
toString(double value)
Return a String representation of the given amount of money
in the default currency. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Money ZERO
Constructor Detail |
---|
public Money(Currency currency, double amount)
Money
instance from the given amount using the
given currency.
currency
- the currency of the money.amount
- the amount of money.public Money(double amount)
Money
instance from the given amount using the
default currency.
amount
- the amount of money.public Money(Currency currency, java.lang.String string) throws MoneyFormatException
Money
instance by parsing the given string.
string
- the string to parse.
MoneyFormatException
- if there was an error parsing the string.Method Detail |
---|
public Currency getCurrency()
public Money add(Money money)
money
- the money to add.
Money
.public Money add(double money)
money
- the money to add.
Money
.public Money subtract(Money money)
money
- the money to subtract.
Money
.public Money divide(int number)
number
- the number to divide by.
Money
.public Money multiply(int number)
number
- the number to multiply by.
Money
.public java.lang.Object clone()
Money
is immutable,
this function simply returns this object.
clone
in class java.lang.Object
public boolean isLessThan(Money money)
money
- the money to compare with
true
if this money is less than the given money.public boolean isLessThanEqual(Money money)
money
- the money to compare with
true
if this money is less than or equal to the given money.public boolean isGreaterThan(Money money)
money
- the money to compare with
true
if this money is greater than the given money.public boolean isGreaterThanEqual(Money money)
money
- the money to compare with
true
if this money is greater than or equal to the given money.public int compareTo(java.lang.Object object)
compareTo
in interface java.lang.Comparable
object
- the money to compare
0
if the monies are equal;
1
if this money is more than the specified money or
-1
if this money is less than the specified money.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- the money to compare
true
iff the monies are equal.public int hashCode()
hashCode
in class java.lang.Object
public Money exchange(Currency currency, double exchangeRate)
currency
- the currency to exchange this money forexchangeRate
- the exchange rate
public java.lang.String toString()
String
object representing this Money
's value.
toString
in class java.lang.Object
public static java.lang.String toString(double value)
String
representation of the given amount of money
in the default currency.
value
- the value of the money
public double doubleValue()
Money
as a double
.
double
.
|
Venice 0.7beta | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |