- java.lang.Object
-
- javax.money.AbstractContext
-
- javax.money.AbstractQuery
-
- javax.money.RoundingQuery
-
- All Implemented Interfaces:
java.io.Serializable,CurrencySupplier
public final class RoundingQuery extends AbstractQuery implements CurrencySupplier
Query for accessing instances ofMonetaryRounding. In general it is determined by the implementation, what roundings are provided. Nevertheless the following queries must be supported:- Accessing roundings using rounding names and/or regular expressions.
- Accessing mathematical rounding by setting a scale and (optionally) a
MathContextas additional generic attribute. - Accessing default roundings for a
CurrencyUnit. This method should return the most appropriate rounding for a currency. If no currency specific rounding is available, it should return a rounding withscale==currency .getDefaultFractionUnits(), java.math.RoundingMode = RoundingMode.HALF_EVEN.
This class is immutable, thread-safe and serializable.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.StringKEY_QUERY_ROUNDING_NAMEAttribute key used for the rounding name attribute.(package private) static java.lang.StringKEY_QUERY_SCALEAttribute key used for the scale attribute.private static longserialVersionUID-
Fields inherited from class javax.money.AbstractQuery
KEY_QUERY_PROVIDERS, KEY_QUERY_TARGET_TYPE, KEY_QUERY_TIMESTAMP
-
Fields inherited from class javax.money.AbstractContext
data, KEY_PROVIDER
-
-
Constructor Summary
Constructors Constructor Description RoundingQuery(RoundingQueryBuilder builder)Constructor, used from theRoundingQueryBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CurrencyUnitgetCurrency()Sets the target CurrencyUnit.java.lang.StringgetRoundingName()Gets the target rounding name.java.lang.IntegergetScale()Gets the target scale.RoundingQueryBuildertoBuilder()Creates a new builder instances, initialized with the data from this one.-
Methods inherited from class javax.money.AbstractQuery
getProviderNames, getTargetType
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
KEY_QUERY_ROUNDING_NAME
static final java.lang.String KEY_QUERY_ROUNDING_NAME
Attribute key used for the rounding name attribute.- See Also:
- Constant Field Values
-
KEY_QUERY_SCALE
static final java.lang.String KEY_QUERY_SCALE
Attribute key used for the scale attribute.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RoundingQuery
RoundingQuery(RoundingQueryBuilder builder)
Constructor, used from theRoundingQueryBuilder.- Parameters:
builder- the corresponding builder, not null.
-
-
Method Detail
-
getRoundingName
public java.lang.String getRoundingName()
Gets the target rounding name. This method allows to access theMonetaryRoundinginstances by passing a name, which most of the time identifies a certain rounding instance. Each entry is first matched as name on equality. If no instance with such a name exists, the value passed is interpreted as a regular expression to lookup roundings.- Returns:
- the rounding id or null.
-
getScale
public java.lang.Integer getScale()
Gets the target scale. This allows to define the scale required. If not specified as additional attribute, by default, RoundingMode.HALF_EVEN is used hereby.- Returns:
- the target scale or null.
-
getCurrency
public CurrencyUnit getCurrency()
Sets the target CurrencyUnit. Typically this determines all other properties, such as scale and the concrete rounding algorithm. With rounding names, depending on the implementation, additional sub-selections are possible. Similarly additional attributes can be used to select special rounding instances, e.g. for cash rounding.- Specified by:
getCurrencyin interfaceCurrencySupplier- Returns:
- the CurrencyUnit, or null.
-
toBuilder
public RoundingQueryBuilder toBuilder()
Creates a new builder instances, initialized with the data from this one.- Returns:
- a new
RoundingQueryBuilderinstance, never null.
-
-