public abstract class BaseMonetaryAmountFactory<T extends javax.money.MonetaryAmount> extends Object implements javax.money.MonetaryAmountFactory<T>
MonetaryAmount
instances for a given type. It can be accessed, by
MonetaryAmount.getFactory()
, returning a BaseMonetaryAmountFactory
creating amounts of the same implementation type, which also provided the factory instance.Monetary.getAmountFactory(Class)
accessing a
BaseMonetaryAmountFactory
for a concrete type Class
.Monetary.getDefaultAmountFactory()
accessing a default
BaseMonetaryAmountFactory
.
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
).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).
Constructor and Description |
---|
BaseMonetaryAmountFactory() |
Modifier and Type | Method and Description |
---|---|
javax.money.MonetaryContext |
getMaximalMonetaryContext()
Returns the maximal
MonetaryContext supported, for requests that exceed these maximal
capabilities, an ArithmeticException must be thrown. |
javax.money.MonetaryAmountFactory<T> |
setAmount(javax.money.MonetaryAmount amount)
Uses an arbitrary
MonetaryAmount to initialize this factory. |
javax.money.MonetaryAmountFactory<T> |
setCurrency(String currencyCode)
Sets the
CurrencyUnit to be used. |
public BaseMonetaryAmountFactory()
public javax.money.MonetaryAmountFactory<T> setCurrency(String currencyCode)
CurrencyUnit
to be used.setCurrency
in interface javax.money.MonetaryAmountFactory<T extends javax.money.MonetaryAmount>
currencyCode
- the currencyCode of the currency to be used, not null
. The currency code
will be resolved using Monetary.getCurrency(String, String...)
.javax.money.UnknownCurrencyException
- if the currencyCode
is not resolvable.javax.money.UnknownCurrencyException
- if the currencyCode
is not resolvable.public javax.money.MonetaryAmountFactory<T> setAmount(javax.money.MonetaryAmount amount)
MonetaryAmount
to initialize this factory. Properties reused are:
setAmount
in interface javax.money.MonetaryAmountFactory<T extends javax.money.MonetaryAmount>
amount
- the amount to be used, not null
.javax.money.MonetaryException
- when the MonetaryContext
implied by amount.getContext()
exceeds the capabilities supported by this factory type.public javax.money.MonetaryContext getMaximalMonetaryContext()
MonetaryContext
supported, for requests that exceed these maximal
capabilities, an ArithmeticException
must be thrown.getMaximalMonetaryContext
in interface javax.money.MonetaryAmountFactory<T extends javax.money.MonetaryAmount>
MonetaryContext
supported, never null
Copyright © 2012-2015 JavaMoney. All Rights Reserved.