Class USDCurrency
java.lang.Object
net.okapia.osid.primordium.financials.spi.AbstractCurrency
net.okapia.osid.primordium.financials.USDCurrency
- All Implemented Interfaces:
Serializable, Comparable<Currency>, Currency, OsidPrimitive, Currency, OsidPrimitive
USD Currency with arbitrary precision. The amounts can be any
decimal number greater than or equal to zero.
A USDCurrency may have a Precision where input amounts are rounded
to DOLLAR, CENT, or MILL. ARBITRARY Precision will leave the
input amounts alone.
A USDCurrency supports two output formats. One using the $ SYMBOL
and the other using a USD suffix.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFormat is used to specify the outputtoString()format of a USD currency value.static enumPrecision is used to specify the rounding of input values to a USD currency. -
Constructor Summary
ConstructorsConstructorDescriptionUSDCurrency(BigDecimal amount) Constructs a newUSDCurrency.USDCurrency(BigDecimal amount, USDCurrency.Precision precision, USDCurrency.Format format) Constructs a newUSDCurrencyof the specified precision and format. -
Method Summary
Modifier and TypeMethodDescriptionstatic Currencycurrency(long cents) Makes a USDCurrency from a number of cents.static CurrencyMakes a USDCurrency from a string.static Currencycurrency(BigDecimal amount) Makes a USDCurrency from a BigDecimal.toString()Returns a string representation of this Currency.static CurrencyvalueOf(long cents) Makes a USDCurrency from a number of cents.static CurrencyvalueOf(long cents, USDCurrency.Format format) Makes a USDCurrency from a number of cents.static CurrencyMakes a USDCurrency from a string.static CurrencyvalueOf(BigDecimal amount) Makes a USDCurrency from a BigDecimal.static CurrencyvalueOf(BigDecimal amount, USDCurrency.Format format) Makes a USDCurrency from a BigDecimal.Methods inherited from class AbstractCurrency
compare, compareTo, equals, getAmount, getCurrencyType, hashCode, isLarger, isSmallerModifier and TypeMethodDescriptionprotected static intCompares two Currencies for performing value comparisons.intCompares this currency with the specified Currency for order.final booleanDetermines if the givenCurrencyis equal to this one.final BigDecimalGets the total amount.final TypeGets the currency type.final inthashCode()Returns a hash code value for thisCurrency.final booleanTests if this Currency is greater than the given Currency.final booleanTests if this Currency is less than the given Currency.
-
Constructor Details
-
USDCurrency
Constructs a newUSDCurrency. The default precision is Precision.CENT and default output format is Format.SYMBOL.- Parameters:
amount- the currency amount in cents- Throws:
InvalidArgumentException-amountis negativeNullArgumentException-amountisnull
-
USDCurrency
Constructs a newUSDCurrencyof the specified precision and format.- Parameters:
amount- the currency amount in decimal dollarsprecision- the precisionformat- the output format- Throws:
InvalidArgumentException-amountis negativeNullArgumentException-amount,precisionorformatisnull
-
-
Method Details
-
toString
Returns a string representation of this Currency.- Specified by:
toStringin interfaceOsidPrimitive- Overrides:
toStringin classAbstractCurrency- Returns:
- a string
-
currency
Makes a USDCurrency from a string. The Precision is based on the decimal places in the supplied string and the output format is determined by the symbols in the supplied string. Formats are:- $D ($1,500)
- D USD (1,500 USD)
- $D.CC ($1,500.00)
- D.CC USD (1,500.00 USD)
- $D.CCCCC ($1,500.00000)
- D.CCCCC USD (1,500.00000 USD)
- Parameters:
str- a string representation of the amount- Returns:
- a Currency
- Throws:
InvalidArgumentException- cannot parsestrNullArgumentException-strisnull- See Also:
-
valueOf
Makes a USDCurrency from a string. The Precision is based on the decimal places in the supplied string and the output format is determined by the symbols in the supplied string. Formats are:- $D ($1,500)
- D USD (1,500 USD)
- $D.CC ($1,500.00)
- D.CC USD (1,500.00 USD)
- $D.CCCCC ($1,500.00000)
- D.CCCCC USD (1,500.00000 USD)
- Parameters:
str- a string representation of the amount- Returns:
- a Currency
- Throws:
InvalidArgumentException- cannot parsestrNullArgumentException-strisnull- See Also:
-
valueOf
Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal and the output format is Format.SYMBOL.- Parameters:
amount- the currency amount- Returns:
- a Currency
- Throws:
InvalidArgumentException- amount is negativeNullArgumentException-amountisnull- See Also:
-
currency
Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal and the output format is Format.SYMBOL.- Parameters:
amount- the currency amount- Returns:
- a Currency
- Throws:
InvalidArgumentException- amount is negativeNullArgumentException-amountisnull- See Also:
-
valueOf
Makes a USDCurrency from a BigDecimal. The Precision is based on the scale of the BigDecimal.- Parameters:
amount- the currency amountformat- the output format- Returns:
- a Currency
- Throws:
InvalidArgumentException- amount is negativeNullArgumentException-amountorformatisnull
-
valueOf
Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT and the output format is Format.SYMBOL.- Parameters:
cents- the number of cents- Returns:
- a Currency
- Throws:
InvalidArgumentException- cents is negative- See Also:
-
currency
Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT and the output format is Format.SYMBOL.- Parameters:
cents- the number of cents- Returns:
- a Currency
- Throws:
InvalidArgumentException- cents is negative- See Also:
-
valueOf
Makes a USDCurrency from a number of cents. The Precision is set to Precision.CENT.- Parameters:
cents- the currency centsformat- the output format- Returns:
- a Currency
- Throws:
InvalidArgumentException- cents is negative
-