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.Monetary.getAmountFactory(Class) accessing a
MonetaryAmountFactory for a concrete type Class.Monetary.getDefaultAmountFactory() 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
Monetary).MonetaryContextMonetaryAmount 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. |
Class<? extends MonetaryAmount> |
getAmountType()
Access the
MonetaryAmount implementation type. |
MonetaryContext |
getDefaultMonetaryContext()
Returns the default
MonetaryContext used, when no MonetaryContext is
provided. |
default MonetaryContext |
getMaximalMonetaryContext()
Returns the maximal
MonetaryContext supported, for requests that exceed these maximal
capabilities, an ArithmeticException must be thrown. |
NumberValue |
getMaxNumber()
Get the maximum possible number that this type can represent.
|
NumberValue |
getMinNumber()
Get the minimum possible number that this type can represent.
|
default 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. |
default MonetaryAmountFactory<T> |
setCurrency(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(Number number)
Sets the number to be used.
|
Class<? extends MonetaryAmount> getAmountType()
MonetaryAmount implementation type.MonetaryAmount implementation type, never null.default MonetaryAmountFactory<T> setCurrency(String currencyCode)
CurrencyUnit to be used.currencyCode - the currencyCode of the currency to be used, not null. The currency code
will be resolved using Monetary.getCurrency(String, String...).UnknownCurrencyException - if the currencyCode is not resolvable.MonetaryAmountFactory<T> setCurrency(CurrencyUnit currency)
CurrencyUnit to be used.currency - the CurrencyUnit to be used, not nullMonetaryAmountFactory<T> setNumber(double number)
number - the number to be usedMonetaryAmountFactory<T> setNumber(long number)
number - the number to be usedMonetaryAmountFactory<T> setNumber(Number number)
number - the number to be used, not null.NumberValue getMaxNumber()
MonetaryContext.getPrecision() returns a value > 0 this
method is required to provide a maximal amount.NumberValue getMinNumber()
MonetaryContext.getPrecision() returns a value > 0 this
method is required to provide a maximal amount.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()default 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.getContext()
exceeds the capabilities supported by this factory type.T create()
MonetaryAmount, using the current data set on this factory.MonetaryAmount.getAmountType()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()default MonetaryContext getMaximalMonetaryContext()
MonetaryContext supported, for requests that exceed these maximal
capabilities, an ArithmeticException must be thrown.MonetaryContext supported, never nullCopyright © 2012–2016 JSR 354 - Expert Group. All rights reserved.