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

pack-priv final Class PermilOperator

extends Object
implements MonetaryOperator
Class Inheritance
All Implemented Interfaces
javax.money.MonetaryOperator
Imports
java.math.BigDecimal, .MathContext, java.text.NumberFormat, java.util.Objects, javax.money.MonetaryAmount, .MonetaryOperator

This class allows to extract the permil of a MonetaryAmount instance.
Authors
Anatole Tresch, Werner Keil
Version
0.5
See Also
Wikipedia: Per mil

Field Summary

Modifier and TypeField and Description
private static final MathContext
private static final BigDecimal
private final BigDecimal

Constructor Summary

AccessConstructor and Description
pack-priv
PermilOperator(final BigDecimal decimal)

Access the shared instance of PermilOperator for use.

Method Summary

Modifier and TypeMethod and Description
public MonetaryAmount

Returns:

the permil result of the amount, never null
apply
(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Gets the permil of the amount.

private static BigDecimal

Returns:

java.math.BigDecimal
calcPermil
(BigDecimal
java.math.BigDecimal
decimal
)

Calculate a BigDecimal value for a Permil e.g. "3" (3 permil) will generate .003

private static MathContext

Returns:

the MathContext to be used, by default MathContext#DECIMAL64.
initDefaultMathContext
()

Get MathContext for PermilOperator instances.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_MATH_CONTEXTback to summary
private static final MathContext DEFAULT_MATH_CONTEXT
ONE_THOUSANDback to summary
private static final BigDecimal ONE_THOUSAND
permilValueback to summary
private final BigDecimal permilValue

Constructor Detail

PermilOperatorback to summary
pack-priv PermilOperator(final BigDecimal decimal)

Access the shared instance of PermilOperator for use.

Method Detail

applyback to summary
public MonetaryAmount apply(MonetaryAmount amount)

Implements javax.money.MonetaryOperator.apply.

Gets the permil of the amount.

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

This is returned as a MonetaryAmount.

Returns:MonetaryAmount

the permil result of the amount, never null

Annotations
@Override
calcPermilback to summary
private static BigDecimal calcPermil(BigDecimal decimal)

Calculate a BigDecimal value for a Permil e.g. "3" (3 permil) will generate .003

Parameters
decimal:BigDecimal

java.math.BigDecimal

Returns:BigDecimal

java.math.BigDecimal

initDefaultMathContextback to summary
private static MathContext initDefaultMathContext()

Get MathContext for PermilOperator instances.

Returns:MathContext

the MathContext to be used, by default MathContext#DECIMAL64.

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