java.lang.Object
javax.money.AbstractContext
javax.money.MonetaryContext
- All Implemented Interfaces:
java.io.Serializable
public final class MonetaryContext extends AbstractContext implements java.io.Serializable
This class models the meta data (mostly the numeric capabilities) of a
MonetaryAmount
in a
platform independent way. It provides information about
- the maximal precision supported (0, for unlimited precision).
- the minimum scale (>=0)
- the maximal scale (>= -1, -1 for unlimited scale).
- the numeric representation class.
- any other attributes, identified by the attribute type, e.g.
RoundingMode
.
This class is immutable, serializable and thread-safe.
- Author:
- Anatole Tresch, Werner Keil
- See Also:
- Serialized Form
-
Field Summary
-
Method Summary
Modifier and Type Method Description static MonetaryContext
from(MonetaryAmountFactoryQuery monetaryAmountFactoryQuery, java.lang.Class<? extends MonetaryAmount> amountClass)
This method allows to easily of a new MonetaryContext instance from a given.MonetaryAmountFactoryQuery
.static MonetaryContext
from(MonetaryContext monetaryContext, java.lang.Class<? extends MonetaryAmount> amountClass)
Creates a new MonetaryContext).java.lang.Class<? extends MonetaryAmount>
getAmountType()
Get the MonetaryAmount implementation class.int
getMaxScale()
Get the maximal scale supported, always>= -1
.int
getPrecision()
Returns theprecision
setting.boolean
isFixedScale()
Allows to check ifminScale == maxScale
.MonetaryContextBuilder
toBuilder()
Creates a new builder instances, initialized with the data from this one.
-
Method Details
-
getPrecision
public int getPrecision()Returns theprecision
setting. This value is always non-negative.- Returns:
- an
int
which is the value of theprecision
setting
-
isFixedScale
public boolean isFixedScale()Allows to check ifminScale == maxScale
.- Returns:
true
ifminScale == maxScale
.
-
getMaxScale
public int getMaxScale()Get the maximal scale supported, always>= -1
. Fixed scaled numbers will havescale==maxScale
for all values.-1
declares the maximal scale to be unlimited.- Returns:
- the maximal scale supported, always
>= -1
-
getAmountType
Get the MonetaryAmount implementation class.- Returns:
- the implementation class of the containing amount instance, never null.
- See Also:
MonetaryAmount.getContext()
-
from
public static MonetaryContext from(MonetaryAmountFactoryQuery monetaryAmountFactoryQuery, java.lang.Class<? extends MonetaryAmount> amountClass)This method allows to easily of a new MonetaryContext instance from a given.MonetaryAmountFactoryQuery
.- Parameters:
monetaryAmountFactoryQuery
- the monetary amount factory query, not null.amountClass
- the targeted implementation type.- Returns:
- a new corresponding MonetaryContext instance.
-
from
public static MonetaryContext from(MonetaryContext monetaryContext, java.lang.Class<? extends MonetaryAmount> amountClass)Creates a new MonetaryContext).- Parameters:
monetaryContext
- the base context, not null.amountClass
- the target amount class.- Returns:
- a new corresponding MonetaryContext instance.
-
toBuilder
Creates a new builder instances, initialized with the data from this one.- Returns:
- a new
MonetaryContextBuilder
instance, never null.
-