Top Description Fields Constructors Methods
org.javamoney.moneta.function

public final Class PrecisionScaleRoundedOperator

extends Object
implements MonetaryOperator
Class Inheritance
All Implemented Interfaces
javax.money.MonetaryOperator
Static Imports
java.util.Objects.requireNonNull

This implementation uses a scale and RoundingMode and precision to does the rounding operations. The implementation will use both the scale and precision, in other words, the number of digits to the right of the decimal point and the number of digits.

The derived class will implements the org.javamoney.moneta.RoundedMoney with this rounding monetary operator

  int scale = 3;
    int precision = 5;
    MathContext mathContext = new MathContext(precision, RoundingMode.HALF_EVEN);
    MonetaryOperator monetaryOperator = PrecisionScaleRoundedOperator.of(scale, mathContext);
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
    MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.346

   

Case the parameter in MonetaryOperator#apply(MonetaryAmount) be null, the apply will return a NullPointerException

Author
Otavio Santana
Since
1.0.1
See Also
PrecisionScaleRoundedOperator#of(int, MathContext), org.javamoney.moneta.RoundedMoney, MonetaryOperator, BigDecimal#scale(), MathContext, BigDecimal#precision()

Field Summary

Modifier and TypeField and Description
private final MathContext
private final PrecisionContextRoundedOperator
private final int
private final ScaleRoundedOperator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public MonetaryAmount
apply(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Applies the operator on the given amount.

public MathContext
public int
public static PrecisionScaleRoundedOperator

Returns:

the MonetaryOperator using the scale and RoundingMode used in parameter
of
(int scale, MathContext
the math context, not null.
mathContext
)

Creates the rounded Operator from scale and roundingMode

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

mathContextback to summary
private final MathContext mathContext
mathContextOperatorback to summary
private final PrecisionContextRoundedOperator mathContextOperator
scaleback to summary
private final int scale
scaleRoundedOperatorback to summary
private final ScaleRoundedOperator scaleRoundedOperator

Constructor Detail

PrecisionScaleRoundedOperatorback to summary
private PrecisionScaleRoundedOperator(int scale, MathContext mathContext)

Method Detail

applyback to summary
public MonetaryAmount apply(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Doc from javax.money.MonetaryOperator.apply.

Applies the operator on the given amount.

Annotations
@Override
getMathContextback to summary
public MathContext getMathContext()
getScaleback to summary
public int getScale()
ofback to summary
public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext)

Creates the rounded Operator from scale and roundingMode

Parameters
mathContext:MathContext

the math context, not null.

Returns:PrecisionScaleRoundedOperator

the MonetaryOperator using the scale and RoundingMode used in parameter

Exceptions
NullPointerException:
when the MathContext is null
IllegalArgumentException:
See Also
RoundingMode
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override