Top Description Methods
javax.money

public Interface MonetaryAmountFactory<T extends javax.money.MonetaryAmount>


Factory for MonetaryAmount instances for a given type. It can be accessed, by

Implementations of this interface allow to get MonetaryAmount instances providing different data as required:

If not defined a default 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:

Implementation specification

Instances of this interface are not required to be thread-safe!
Authors
Anatole Tresch, Werner Keil
Version
1.0.0

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

the corresponding MonetaryAmount.
create
()

Creates a new instance of MonetaryAmount, using the current data set on this factory.

public Class<? extends MonetaryAmount>

Returns:

the MonetaryAmount implementation type, never null.
getAmountType
()

Access the MonetaryAmount implementation type.

public MonetaryContext

Returns:

the default MonetaryContext, never null.
getDefaultMonetaryContext
()

Returns the default MonetaryContext used, when no MonetaryContext is provided.

public default MonetaryContext

Returns:

the maximal MonetaryContext supported, never null
getMaximalMonetaryContext
()

Returns the maximal MonetaryContext supported, for requests that exceed these maximal capabilities, an ArithmeticException must be thrown.

public NumberValue

Returns:

the maximum possible number, or null.
getMaxNumber
()

Get the maximum possible number that this type can represent.

public NumberValue

Returns:

the minimum possible number, or null.
getMinNumber
()

Get the minimum possible number that this type can represent.

public default MonetaryAmountFactory<T>

Returns:

this factory instance, for chaining.
setAmount
(MonetaryAmount
the amount to be used, not null.
amount
)

Uses an arbitrary MonetaryAmount to initialize this factory.

public MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setContext
(MonetaryContext
the MonetaryContext to be used, not null.
monetaryContext
)

Sets the MonetaryContext to be used.

public default MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setCurrency
(String
the currencyCode of the currency to be used, not null. The currency code will be resolved using Monetary#getCurrency(String, String...).
currencyCode
)

Sets the CurrencyUnit to be used.

public MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setCurrency
(CurrencyUnit
the CurrencyUnit to be used, not null
currency
)

Sets the CurrencyUnit to be used.

public MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setNumber
(double
the number to be used
number
)

Sets the number to be used.

public MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setNumber
(long
the number to be used
number
)

Sets the number to be used.

public MonetaryAmountFactory<T>

Returns:

This factory instance, for chaining.
setNumber
(Number
the number to be used, not null.
number
)

Sets the number to be used.

Method Detail

createback to summary
public T create()

Creates a new instance of MonetaryAmount, using the current data set on this factory.

Returns:T

the corresponding MonetaryAmount.

See Also
getAmountType()
getAmountTypeback to summary
public Class<? extends MonetaryAmount> getAmountType()

Access the MonetaryAmount implementation type.

Returns:Class<? extends MonetaryAmount>

the MonetaryAmount implementation type, never null.

getDefaultMonetaryContextback to summary
public MonetaryContext getDefaultMonetaryContext()

Returns the default MonetaryContext used, when no MonetaryContext is provided.

The default context is not allowed to exceed the capabilities of the maximal MonetaryContext supported.

Returns:MonetaryContext

the default MonetaryContext, never null.

See Also
getMaximalMonetaryContext()
getMaximalMonetaryContextback to summary
public default MonetaryContext getMaximalMonetaryContext()

Returns the maximal MonetaryContext supported, for requests that exceed these maximal capabilities, an ArithmeticException must be thrown.

Returns:MonetaryContext

the maximal MonetaryContext supported, never null

getMaxNumberback to summary
public NumberValue getMaxNumber()

Get the maximum possible number that this type can represent. If the numeric model has no limitations on the numeric range, null should be returned. If MonetaryContext#getPrecision() returns a value > 0 this method is required to provide a maximal amount.

Returns:NumberValue

the maximum possible number, or null.

getMinNumberback to summary
public NumberValue getMinNumber()

Get the minimum possible number that this type can represent. If the numeric model has no limitations on the numeric range, null should be returned. If MonetaryContext#getPrecision() returns a value > 0 this method is required to provide a maximal amount.

Returns:NumberValue

the minimum possible number, or null.

setAmountback to summary
public default MonetaryAmountFactory<T> setAmount(MonetaryAmount amount)

Uses an arbitrary MonetaryAmount to initialize this factory. Properties reused are:

  • CurrencyUnit,
  • Number value,
  • MonetaryContext.
Parameters
amount:MonetaryAmount

the amount to be used, not null.

Returns:MonetaryAmountFactory<T>

this factory instance, for chaining.

Exceptions
MonetaryException:
when the MonetaryContext implied by amount.getContext() exceeds the capabilities supported by this factory type.
setContextback to summary
public MonetaryAmountFactory<T> setContext(MonetaryContext monetaryContext)

Sets the MonetaryContext to be used.

Parameters
monetaryContext:MonetaryContext

the MonetaryContext to be used, not null.

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.

Exceptions
MonetaryException:
when the MonetaryContext given exceeds the capabilities supported by this factory type.
See Also
getMaximalMonetaryContext()
setCurrencyback to summary
public default MonetaryAmountFactory<T> setCurrency(String currencyCode)

Sets the CurrencyUnit to be used.

Parameters
currencyCode:String

the currencyCode of the currency to be used, not null. The currency code will be resolved using Monetary#getCurrency(String, String...).

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.

Exceptions
UnknownCurrencyException:
if the currencyCode is not resolvable.
setCurrencyback to summary
public MonetaryAmountFactory<T> setCurrency(CurrencyUnit currency)

Sets the CurrencyUnit to be used.

Parameters
currency:CurrencyUnit

the CurrencyUnit to be used, not null

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.

setNumberback to summary
public MonetaryAmountFactory<T> setNumber(double number)

Sets the number to be used.

Parameters
number:double

the number to be used

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.

setNumberback to summary
public MonetaryAmountFactory<T> setNumber(long number)

Sets the number to be used.

Parameters
number:long

the number to be used

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.

setNumberback to summary
public MonetaryAmountFactory<T> setNumber(Number number)

Sets the number to be used.

Parameters
number:Number

the number to be used, not null.

Returns:MonetaryAmountFactory<T>

This factory instance, for chaining.