Module java.money
Package javax.money

Class MonetaryContext

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
  • Method Details

    • getPrecision

      public int getPrecision()
      Returns the precision setting. This value is always non-negative.
      Returns:
      an int which is the value of the precision setting
    • isFixedScale

      public boolean isFixedScale()
      Allows to check if minScale == maxScale.
      Returns:
      true if minScale == maxScale.
    • getMaxScale

      public int getMaxScale()
      Get the maximal scale supported, always >= -1. Fixed scaled numbers will have scale==maxScale for all values. -1 declares 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 MonetaryContextBuilder instance, never null.