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

public final Class ScaleRoundedOperator

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 scale and RoundingMode to does the rounding operations. The implementation will use the scale, in other words, the number of digits to the right of the decimal point

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

  MonetaryOperator monetaryOperator = ScaleRoundedOperator.of(scale, RoundingMode.HALF_EVEN);
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(BigDecimal.valueOf(35.34567), real);
    MonetaryAmount result = monetaryOperator.apply(money); // BRL 35.3457

   

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

Author
Otavio Santana
See Also
ScaleRoundedOperator(MathContext), RoundedMoney, MonetaryOperator, BigDecimal#scale()

Field Summary

Modifier and TypeField and Description
private final RoundingMode
private final int

Constructor Summary

AccessConstructor and Description
private
ScaleRoundedOperator(int scale, RoundingMode roundingMode)

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 RoundingMode
public int
public static ScaleRoundedOperator

Returns:

the MonetaryOperator using the scale and RoundingMode used in parameter
of
(int
the scale to be used
scale
,
RoundingMode
the rounding mode to be used
roundingMode
)

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

roundingModeback to summary
private final RoundingMode roundingMode
scaleback to summary
private final int scale

Constructor Detail

ScaleRoundedOperatorback to summary
private ScaleRoundedOperator(int scale, RoundingMode roundingMode)

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
getRoundingModeback to summary
public RoundingMode getRoundingMode()
getScaleback to summary
public int getScale()
ofback to summary
public static ScaleRoundedOperator of(int scale, RoundingMode roundingMode)

Creates the rounded Operator from scale and roundingMode

Parameters
scale:int

the scale to be used

roundingMode:RoundingMode

the rounding mode to be used

Returns:ScaleRoundedOperator

the MonetaryOperator using the scale and RoundingMode used in parameter

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