public interface MonetaryAmountFactory<T extends MonetaryAmount>
MonetaryAmount
instances for a given type. It can be accessed, by
MonetaryAmount.getFactory()
, returning a MonetaryAmountFactory
creating amounts of the same implementation type, which also provided the factory instance.MonetaryAmounts.getAmountFactory(Class)
accessing a
MonetaryAmountFactory
for a concrete type Class
.MonetaryAmounts.getAmountFactory()
accessing a default
MonetaryAmountFactory
.
Implementations of this interface allow to get MonetaryAmount
instances providing
different data as required:
CurrencyUnit
, or the corresponding currency code (must be solvable by
MonetaryCurrencies
).MonetaryContext
MonetaryAmount
instance, it is possible to convert an arbitrary amount
implementation to the implementation provided by this factory. If the current factory cannot
support the precision/scale as required by the current NumberValue
a
MonetaryException
must be thrown.MonetaryContext
is used, which can also be configured by adding
configuration to a file /javamoney.properties
to the classpath.
Hereby the entries. e.g. for a class MyMoney
should start with a.b.MyMoney.ctx
. The entries valid must be documented
on the according implementation class, where the following entries are defined for all implementation types
(example below given for a class a.b.MyMoney
:
a.b.MyMoney.ctx.precision
to define the maximal supported precision.a.b.MyMoney.ctx.maxScale
to define the maximal supported scale.a.b.MyMoney.ctx.fixedScale
to define the scale to be fixed (constant).
Modifier and Type | Method and Description |
---|---|
T |
create()
Creates a new instance of
MonetaryAmount , using the current data set on this factory. |
java.lang.Class<? extends MonetaryAmount> |
getAmountType()
Access the
MonetaryAmount implementation type. |
MonetaryContext |
getDefaultMonetaryContext()
Returns the default
MonetaryContext used, when no MonetaryContext is
provided. |
MonetaryContext |
getMaximalMonetaryContext()
Returns the maximal
MonetaryContext supported, for requests that exceed these maximal
capabilities, an ArithmeticException must be thrown. |
MonetaryAmountFactory<T> |
setAmount(MonetaryAmount amount)
Uses an arbitrary
MonetaryAmount to initialize this factory. |
MonetaryAmountFactory<T> |
setContext(MonetaryContext monetaryContext)
Sets the
MonetaryContext to be used. |
MonetaryAmountFactory<T> |
setCurrency(CurrencyUnit currency)
Sets the
CurrencyUnit to be used. |
MonetaryAmountFactory<T> |
setCurrency(java.lang.String currencyCode)
Sets the
CurrencyUnit to be used. |
MonetaryAmountFactory<T> |
setNumber(double number)
Sets the number to be used.
|
MonetaryAmountFactory<T> |
setNumber(long number)
Sets the number to be used.
|
MonetaryAmountFactory<T> |
setNumber(java.lang.Number number)
Sets the number to be used.
|
T create()
MonetaryAmount
, using the current data set on this factory.MonetaryAmount
.getAmountType()
java.lang.Class<? extends MonetaryAmount> getAmountType()
MonetaryAmount
implementation type.MonetaryAmount
implementation type, never null
.MonetaryContext getDefaultMonetaryContext()
MonetaryContext
used, when no MonetaryContext
is
provided.
The default context is not allowed to exceed the capabilities of the maximal
MonetaryContext
supported.
MonetaryContext
, never null
.getMaximalMonetaryContext()
MonetaryContext getMaximalMonetaryContext()
MonetaryContext
supported, for requests that exceed these maximal
capabilities, an ArithmeticException
must be thrown.MonetaryContext
supported, never null
MonetaryAmountFactory<T> setAmount(MonetaryAmount amount)
MonetaryAmount
to initialize this factory. Properties reused are:
amount
- the amount to be used, not null
.MonetaryException
- when the MonetaryContext
implied by amount.getMonetaryContext()
exceeds the capabilities supported by this factory type.MonetaryAmountFactory<T> setContext(MonetaryContext monetaryContext)
MonetaryContext
to be used.monetaryContext
- the MonetaryContext
to be used, not null
.MonetaryException
- when the MonetaryContext
given exceeds the capabilities supported by this
factory type.getMaximalMonetaryContext()
MonetaryAmountFactory<T> setCurrency(CurrencyUnit currency)
CurrencyUnit
to be used.currency
- the CurrencyUnit
to be used, not null
MonetaryAmountFactory<T> setCurrency(java.lang.String currencyCode)
CurrencyUnit
to be used.currencyCode
- the currencyCode of the currency to be used, not null
. The currency code
will be resolved using MonetaryCurrencies.getCurrency(String)
.UnknownCurrencyException
- if the currencyCode
is not resolvable.MonetaryAmountFactory<T> setNumber(double number)
number
- the number to be usedMonetaryAmountFactory<T> setNumber(long number)
number
- the number to be usedMonetaryAmountFactory<T> setNumber(java.lang.Number number)
number
- the number to be used, not null
.