|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.pcauto.util.Quantity com.pcauto.util.Currency
Currency
objects used to hold currency information. Objects
can only be instantiated using the CurrencyFormat
class.
A Currency
object's concept of unit is hidden from class
users, and instead inferred from the formatter class at instantiation.
The baseUnit is used to store the unit with which Currency
objects will be printed using the overrided toString() method.
A set of arithmetic operations have been included to compare, add, subtract,
divide and multiply currency objects. All arithmetic operations have been
designed to be null
safe.
Field Summary | |
protected static CurrencyUnits |
baseUnit
|
static Currency |
ZERO
Instance of Currency with zero value. |
Fields inherited from class com.pcauto.util.Quantity |
quantity, unit |
Constructor Summary | |
protected |
Currency(double quantity,
CurrencyUnits unit)
Creates new Currency with an initial value
double value and int unit. |
Method Summary | |
Currency |
add(Currency quant)
Adds this Currency to the supplied
Currency . |
static Currency |
add(Currency a,
Currency b)
Adds supplied Currency to other supplied
Currency . |
static boolean |
areEqual(Currency quant1,
Currency quant2)
Determines if two Currency objects passed
to the fuction are equal. |
java.lang.Object |
clone()
Creates new Currency using an instance
of Currency . |
int |
compareTo(Currency quant)
Compares this Currency with the specified
Currency . |
Currency |
divide(java.math.BigDecimal divisor)
Divides this Currency by supplied
BigDecimal . |
java.math.BigDecimal |
divide(Currency quant)
Divides this Currency by supplied
Currency . |
boolean |
equals(Currency quant)
Compares this Currency to the specified
Currency . |
static CurrencyUnits |
getBaseUnit()
Gets base unit with which this currency is printed. |
boolean |
greaterThan(Currency quant)
Compares this Currency to the specified
Currency . |
boolean |
lessThan(Currency quant)
Compares this Currency to the specified
Currency . |
Currency |
multiply(java.math.BigDecimal multiplier)
Multiplies this Currency by supplied
BigDecimal . |
static void |
setBaseUnit(CurrencyUnits unit)
Sets the "toString" representation of any Currency objects
to be of type unit . |
Currency |
subtract(Currency quant)
Subtracts supplied Currency from
this Currency . |
Methods inherited from class com.pcauto.util.Quantity |
add, add, areEqual, compareTo, compareTo, divide, equals, equals, getQuantity, getUnit, greaterThan, lessThan, myDivide, myMultiply, setQuantity, setUnit, setZERO, subtract |
Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static CurrencyUnits baseUnit
public static final Currency ZERO
Currency
with zero value.
Constructor Detail |
protected Currency(double quantity, CurrencyUnits unit)
Currency
with an initial value
double
value and int
unit.
quantity
- double
currency
& @param unit CurrencyUnits
Method Detail |
public static CurrencyUnits getBaseUnit()
this
currency is printed.
CurrencyUnits
unit with which currencies are printed.public static void setBaseUnit(CurrencyUnits unit)
Currency
objects
to be of type unit
.
public java.lang.Object clone()
Currency
using an instance
of Currency
.
clone
in class Quantity
Quantity
objectpublic boolean equals(Currency quant)
this
Currency
to the specified
Currency
.
The result is true
if and only if the argument is not
null
and is a Currency
object that has
the same value. null
parameter returns false.
quant
- Currency
with which to compare
true
if Currencies are equivalent;
false
othewise.public int compareTo(Currency quant)
this
Currency
with the specified
Currency
. null
parameter returns 1.
quant
- Currency
object with which to compare.
this
Currency
is larger.
-1 if this
Currency
is smaller.public boolean greaterThan(Currency quant)
this
Currency
to the specified
Currency
.
quant
- Currency
object with which to compare.
true
if this
is greater
than quant
;
false
otherwisepublic boolean lessThan(Currency quant)
this
Currency
to the specified
Currency
.
quant
- Currency
object with which to compare.
true
if this
is less
than quant
; false
otherwisepublic static boolean areEqual(Currency quant1, Currency quant2)
Currency
objects passed
to the fuction are equal. Two null
are considered equal.
public Currency add(Currency quant)
this
Currency
to the supplied
Currency
.
null
parameter is considered equal
to Currency
with ZERO quantity.
quant
- Currency
object to add
Currency
object resulting from addition operationpublic static Currency add(Currency a, Currency b)
Currency
to other supplied
Currency
. null
parameter(s) is considered
to be equal to ZERO quantity.
a
- first Currency
objectb
- second Currency
object
Currency
object resulting from addition of a
and b in Currency
a's unitpublic Currency subtract(Currency quant)
Currency
from
this
Currency
.
null
parameter is considered equal
to Currency
with zero quantity
quant
- Currency
object to subtract
Currency
object resulting from subtraction
operation in this
unitpublic java.math.BigDecimal divide(Currency quant)
this
Currency
by supplied
Currency
.
quant
- Currency
object to divide by
BigDecimal
object resulting from division operation
ArithmeticException
- on the attempt to divide
by null
or zeropublic Currency multiply(java.math.BigDecimal multiplier)
this
Currency
by supplied
BigDecimal
.
Currency
object resulting
from multiplication operation
ArithmeticException
- on the attempt
to multiply by null
public Currency divide(java.math.BigDecimal divisor)
this
Currency
by supplied
BigDecimal
.
Currency
object resulting from division operation
ArithmeticException
- on the attempt
to divide by null
or zero
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |