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 MonetaryContextfrom(MonetaryAmountFactoryQuery monetaryAmountFactoryQuery, java.lang.Class<? extends MonetaryAmount> amountClass)This method allows to easily of a new MonetaryContext instance from a given.MonetaryAmountFactoryQuery.static MonetaryContextfrom(MonetaryContext monetaryContext, java.lang.Class<? extends MonetaryAmount> amountClass)Creates a new MonetaryContext).java.lang.Class<? extends MonetaryAmount>getAmountType()Get the MonetaryAmount implementation class.intgetMaxScale()Get the maximal scale supported, always>= -1.intgetPrecision()Returns theprecisionsetting.booleanisFixedScale()Allows to check ifminScale == maxScale.MonetaryContextBuildertoBuilder()Creates a new builder instances, initialized with the data from this one.
-
Method Details
-
getPrecision
public int getPrecision()Returns theprecisionsetting. This value is always non-negative.- Returns:
- an
intwhich is the value of theprecisionsetting
-
isFixedScale
public boolean isFixedScale()Allows to check ifminScale == maxScale.- Returns:
trueifminScale == maxScale.
-
getMaxScale
public int getMaxScale()Get the maximal scale supported, always>= -1. Fixed scaled numbers will havescale==maxScalefor all values.-1declares 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
MonetaryContextBuilderinstance, never null.
-