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

public final Class PrecisionContextRoundedOperator

extends Object
implements MonetaryOperator
Class Inheritance
All Implemented Interfaces
javax.money.MonetaryOperator
Imports
java.math.BigDecimal, .MathContext, .RoundingMode, java.util.Objects, javax.money.MonetaryAmount, .MonetaryOperator, org.javamoney.moneta.RoundedMoney

This implementation uses a MathContext to does the rounding operations. The implementation will use the precision, in other words, the total number of digits in a number

The derived class will implements the RoundedMoney with this rounding monetary operator

  MathContext mathContext = new MathContext(4, RoundingMode.HALF_EVEN);
    MonetaryOperator monetaryOperator = PrecisionContextRoundedOperator.of(mathContext);
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
    MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.35

   

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

Author
Otavio Santana
Since
1.0.1
See Also
PrecisionContextRoundedOperator#of(MathContext), RoundedMoney, MonetaryOperator, BigDecimal#precision()

Field Summary

Modifier and TypeField and Description
private final MathContext

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 static PrecisionContextRoundedOperator

Returns:

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

Creates the rounded Operator from mathContext

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

Constructor Detail

PrecisionContextRoundedOperatorback to summary
private PrecisionContextRoundedOperator(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()
ofback to summary
public static PrecisionContextRoundedOperator of(MathContext mathContext)

Creates the rounded Operator from mathContext

Parameters
mathContext:MathContext

the math context, not null.

Returns:PrecisionContextRoundedOperator

the MonetaryOperator using the MathContext used in parameter

Exceptions
NullPointerException:
when the MathContext is null
IllegalArgumentException:
See Also
MathContext
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