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

public final Class MonetaryOperators

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .MathContext, .RoundingMode, java.util.Objects, javax.money.CurrencyUnit, .MonetaryAmount, .MonetaryOperator, org.javamoney.moneta.spi.DefaultNumberValue

This singleton class provides access to the predefined monetary functions.

The class is thread-safe, which is also true for all functions returned by this class.

MonetaryAmount money = Money.parse("EUR 2.35");
 MonetaryAmount result = operator.apply(money);

Or using:

MonetaryAmount money = Money.parse("EUR 2.35");
 MonetaryAmount result = money.with(operator);

Authors
Anatole Tresch, Otavio Santana, Werner Keil
Since
1.0.1
Version
1.1
See Also
MonetaryAmount#with(MonetaryOperator), MonetaryOperator, MonetaryOperator#apply(MonetaryAmount)

Field Summary

Modifier and TypeField and Description
private static final MathContext
private static final ExtractorMajorPartOperator
private static final ExtractorMinorPartOperator
private static final ReciprocalOperator
private static final RoundingMonetaryAmountOperator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static MonetaryOperator

Returns:

the major part as MonetaryOperator
majorPart
()

Extract major part of MonetaryAmount

This returns the monetary amount in terms of the major units of the currency.

public static MonetaryOperator

Returns:

the minor part as MonetaryOperator
minorPart
()

Extract minor part of MonetaryAmount

This returns the monetary amount in terms of the minor units of the currency, truncating the whole part if necessary.

public static MonetaryOperator

Returns:

the percent of MonetaryOperator
percent
(BigDecimal
the value to percent
decimal
)

Gets the percentage of the amount.

public static MonetaryOperator

Returns:

the percent of MonetaryOperator
percent
(Number
to be used in percent
number
)

Gets the percentage of the amount.

public static MonetaryOperator

Returns:

the permil as MonetaryOperator
permil
(BigDecimal decimal)

Gets the permil of the amount.

public static MonetaryOperator

Returns:

the permil MonetaryOperator
permil
(Number
to be converted to BigDecimal
number
)

Returns the percent(BigDecimal) converting this number to BigDecimal and using the DEFAULT_MATH_CONTEXT

public static MonetaryOperator

Returns:

the permil MonetaryOperator
permil
(Number
to be converted to BigDecimal
number
,
MathContext
the mathContext to be used
mathContext
)

Returns the percent(BigDecimal) converting this number to BigDecimal and using the MathContext in parameters

public static MonetaryOperator

Returns:

the reciprocal part as MonetaryOperator
reciprocal
()

Gets the reciprocal of MonetaryAmount

Gets the amount as reciprocal, multiplicative inverse value (1/n).

public static MonetaryOperator
public static MonetaryOperator

Returns:

the major part as MonetaryOperator
rounding
(RoundingMode
rounding to be used
roundingMode
)

Rounding the MonetaryAmount using CurrencyUnit#getDefaultFractionDigits() and RoundingMode.

public static MonetaryOperator

Returns:

the major part as MonetaryOperator
rounding
(RoundingMode
rounding to be used
roundingMode
,
int
to be used
scale
)

Rounding the MonetaryAmount using CurrencyUnit#getDefaultFractionDigits() and RoundingMode.

public static MonetaryOperator

Returns:

the major part as MonetaryOperator
rounding
(int
scale to be used
scale
)

Rounding the MonetaryAmount using the scale informed and RoundingMode#HALF_EVEN.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_MATH_CONTEXTback to summary
private static final MathContext DEFAULT_MATH_CONTEXT
EXTRACTOR_MAJOR_PARTback to summary
private static final ExtractorMajorPartOperator EXTRACTOR_MAJOR_PART
EXTRACTOR_MINOR_PARTback to summary
private static final ExtractorMinorPartOperator EXTRACTOR_MINOR_PART
RECIPROCALback to summary
private static final ReciprocalOperator RECIPROCAL
ROUNDING_MONETARY_AMOUNTback to summary
private static final RoundingMonetaryAmountOperator ROUNDING_MONETARY_AMOUNT

Constructor Detail

MonetaryOperatorsback to summary
private MonetaryOperators()

Method Detail

majorPartback to summary
public static MonetaryOperator majorPart()

Extract major part of MonetaryAmount

This returns the monetary amount in terms of the major units of the currency. For example, 'EUR 2.35' will return 'EUR 2.0', and 'BHD -1.345' will return 'BHD -1.0'.

MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = ConversionOperators.majorPart().apply(money);//EUR 2.0

Returns:MonetaryOperator

the major part as MonetaryOperator

minorPartback to summary
public static MonetaryOperator minorPart()

Extract minor part of MonetaryAmount

This returns the monetary amount in terms of the minor units of the currency, truncating the whole part if necessary. For example, 'EUR 2.35' will return 'EUR 0.35', and 'BHD -1.345' will return 'BHD -0.345'.

MonetaryAmount money = Money.parse("EUR 2.35");
MonetaryAmount result = ConversionOperators.minorPart().apply(money);//EUR 0.35

Returns:MonetaryOperator

the minor part as MonetaryOperator

percentback to summary
public static MonetaryOperator percent(BigDecimal decimal)

Gets the percentage of the amount.

This returns the monetary amount in percent. For example, for 10% 'EUR 2.35' will return 0.235.

MonetaryAmount money = Money.parse("EUR 200.0");
MonetaryAmount result = ConversionOperators.percent(BigDecimal.TEN).apply(money);//EUR 20.0

Parameters
decimal:BigDecimal

the value to percent

Returns:MonetaryOperator

the percent of MonetaryOperator

percentback to summary
public static MonetaryOperator percent(Number number)

Gets the percentage of the amount.

Parameters
number:Number

to be used in percent

Returns:MonetaryOperator

the percent of MonetaryOperator

See Also
percent(BigDecimal)}
permilback to summary
public static MonetaryOperator permil(BigDecimal decimal)

Gets the permil of the amount.

This returns the monetary amount in permil. For example, for 10% 'EUR 2.35' will return 0.235.

MonetaryAmount money = Money.parse("EUR EUR 2.35");
MonetaryAmount result = ConversionOperators.permil(BigDecimal.TEN).apply(money);//EUR 0.0235

Returns:MonetaryOperator

the permil as MonetaryOperator

permilback to summary
public static MonetaryOperator permil(Number number)

Returns the percent(BigDecimal) converting this number to BigDecimal and using the DEFAULT_MATH_CONTEXT

Parameters
number:Number

to be converted to BigDecimal

Returns:MonetaryOperator

the permil MonetaryOperator

See Also
permil(BigDecimal)
permilback to summary
public static MonetaryOperator permil(Number number, MathContext mathContext)

Returns the percent(BigDecimal) converting this number to BigDecimal and using the MathContext in parameters

Parameters
number:Number

to be converted to BigDecimal

mathContext:MathContext

the mathContext to be used

Returns:MonetaryOperator

the permil MonetaryOperator

See Also
permil(BigDecimal)
reciprocalback to summary
public static MonetaryOperator reciprocal()

Gets the reciprocal of MonetaryAmount

Gets the amount as reciprocal, multiplicative inverse value (1/n).

MonetaryAmount money = Money.parse("EUR 2.0");
MonetaryAmount result = ConversionOperators.reciprocal().apply(money);//EUR 0.5

Returns:MonetaryOperator

the reciprocal part as MonetaryOperator

roundingback to summary
public static MonetaryOperator rounding()

Rounding the MonetaryAmount using CurrencyUnit#getDefaultFractionDigits() and RoundingMode#HALF_EVEN.

For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.

MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding().apply(money);//EUR 2.36

Returns:MonetaryOperator

the major part as MonetaryOperator

roundingback to summary
public static MonetaryOperator rounding(RoundingMode roundingMode)

Rounding the MonetaryAmount using CurrencyUnit#getDefaultFractionDigits() and RoundingMode.

For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.

MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(RoundingMode.HALF_EVEN).apply(money);//EUR 2.35

Parameters
roundingMode:RoundingMode

rounding to be used

Returns:MonetaryOperator

the major part as MonetaryOperator

roundingback to summary
public static MonetaryOperator rounding(RoundingMode roundingMode, int scale)

Rounding the MonetaryAmount using CurrencyUnit#getDefaultFractionDigits() and RoundingMode.

For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.

MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(RoundingMode.HALF_EVEN, 3).apply(money);//EUR 2.352

Parameters
roundingMode:RoundingMode

rounding to be used

scale:int

to be used

Returns:MonetaryOperator

the major part as MonetaryOperator

roundingback to summary
public static MonetaryOperator rounding(int scale)

Rounding the MonetaryAmount using the scale informed and RoundingMode#HALF_EVEN.

For example, 'EUR 2.3523' will return 'EUR 2.35', and 'BHD -1.34534432' will return 'BHD -1.345'.

MonetaryAmount money = Money.parse("EUR 2.355432");
MonetaryAmount result = ConversionOperators.rounding(2).apply(money);//EUR 2.35

Parameters
scale:int

scale to be used

Returns:MonetaryOperator

the major part as MonetaryOperator