- 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 aMonetaryAmountin 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.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringAMOUNT_TYPEConstant that defines under which key the amount type is stored in the context map.private static java.lang.StringFIXED_SCALEKey name for the fixed scale.private static java.lang.StringMAX_SCALEKey name for the max scale.private static java.lang.StringPRECISIONKey name for the precision.private static longserialVersionUID-
Fields inherited from class javax.money.AbstractContext
data, KEY_PROVIDER
-
-
Constructor Summary
Constructors Constructor Description MonetaryContext(MonetaryContextBuilder builder)Constructor, used from the Builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
AMOUNT_TYPE
static final java.lang.String AMOUNT_TYPE
Constant that defines under which key the amount type is stored in the context map.- See Also:
- Constant Field Values
-
PRECISION
private static final java.lang.String PRECISION
Key name for the precision.- See Also:
- Constant Field Values
-
FIXED_SCALE
private static final java.lang.String FIXED_SCALE
Key name for the fixed scale.- See Also:
- Constant Field Values
-
MAX_SCALE
private static final java.lang.String MAX_SCALE
Key name for the max scale.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MonetaryContext
MonetaryContext(MonetaryContextBuilder builder)
Constructor, used from the Builder.- Parameters:
builder- the corresponding builder, not null.
-
-
Method Detail
-
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
public java.lang.Class<? extends MonetaryAmount> 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
public MonetaryContextBuilder toBuilder()
Creates a new builder instances, initialized with the data from this one.- Returns:
- a new
MonetaryContextBuilderinstance, never null.
-
-