java.lang.Object
javax.money.AbstractContext
javax.money.MonetaryContext
- All Implemented Interfaces:
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringConstant that defines under which key the amount type is stored in the context map.private static final StringKey name for the fixed scale.private static final StringKey name for the max scale.private static final StringKey name for the precision.private static final longFields inherited from class javax.money.AbstractContext
data, KEY_PROVIDER -
Constructor Summary
ConstructorsConstructorDescriptionMonetaryContext(MonetaryContextBuilder builder) Constructor, used from the Builder. -
Method Summary
Modifier and TypeMethodDescriptionstatic MonetaryContextfrom(MonetaryAmountFactoryQuery monetaryAmountFactoryQuery, Class<? extends MonetaryAmount> amountClass) This method allows to easily of a new MonetaryContext instance from a given.MonetaryAmountFactoryQuery.static MonetaryContextfrom(MonetaryContext monetaryContext, Class<? extends MonetaryAmount> amountClass) Creates a new invalid input: '{@link /*missing*/}'MonetaryContext).Class<? extends MonetaryAmount> Get the MonetaryAmount implementation class.intGet the maximal scale supported, always>= -1.intReturns theprecisionsetting.booleanAllows to check ifminScale == maxScale.Creates a new builder instances, initialized with the data from this one.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
AMOUNT_TYPE
Constant that defines under which key the amount type is stored in the context map.- See Also:
-
PRECISION
Key name for the precision.- See Also:
-
FIXED_SCALE
Key name for the fixed scale.- See Also:
-
MAX_SCALE
Key name for the max scale.- See Also:
-
-
Constructor Details
-
MonetaryContext
MonetaryContext(MonetaryContextBuilder builder) Constructor, used from the Builder.- Parameters:
builder- the corresponding builder, not null.
-
-
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:
-
from
public static MonetaryContext from(MonetaryAmountFactoryQuery monetaryAmountFactoryQuery, 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, Class<? extends MonetaryAmount> amountClass) Creates a new invalid input: '{@link /*missing*/}'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.
-