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

public final Class MoneyUtils

extends Object
Class Inheritance
Imports
javax.money.CurrencyUnit, .MonetaryAmount, .MonetaryContext, .MonetaryException, java.math.BigDecimal, .MathContext, .RoundingMode, java.util.Objects, .Optional, java.util.logging.Logger

Platform RI: This utility class simplifies implementing MonetaryAmount, by providing the common functionality. The different explicitly typed methods are all reduced to methods using BigDecimal as input, hereby performing any conversion to BigDecimal as needed. Obviously this takes some time, so implementors that want to avoid this overhead should implement MonetaryAmount directly.
Author
Anatole Tresch

Field Summary

Modifier and TypeField and Description
private static final Logger
public static final char
public static final String
public static final char
public static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
checkAmountParameter(MonetaryAmount
The monetary amount to be compared to, never null.
amount
,
CurrencyUnit
the currency unit to compare, never null.
currencyUnit
)

Method to check if a currency is compatible with this amount instance.

public static void
checkNumberParameter(Number
the number to be checked.
number
)

Internal method to check for correct number parameter.

public static BigDecimal

Returns:

the corresponding BigDecimal
getBigDecimal
(long
the number type
num
)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

public static BigDecimal

Returns:

the corresponding BigDecimal
getBigDecimal
(double
the number type
num
)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

public static BigDecimal

Returns:

the corresponding BigDecimal
getBigDecimal
(Number
the number type
num
)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

public static BigDecimal

Returns:

the corresponding BigDecimal
getBigDecimal
(Number
the number type
num
,
MonetaryContext moneyContext)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given, if a MonetaryContext is given, it is applied to the number returned.

public static MathContext

Returns:

the corresponding MathContext
getMathContext
(MonetaryContext monetaryContext, RoundingMode
the default RoundingMode, to be used if no one is set in MonetaryContext.
defaultMode
)

Evaluates the MathContext from the given MonetaryContext.

public static String
replaceNbspWithSpace(String s)

Replaces the non-breaking space character U+00A0 and Narrow non-breaking space U+202F from the string with usual space.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG
NBSPback to summary
public static final char NBSP
NBSP_STRINGback to summary
public static final String NBSP_STRING
NNBSPback to summary
public static final char NNBSP
NNBSP_STRINGback to summary
public static final String NNBSP_STRING

Constructor Detail

MoneyUtilsback to summary
private MoneyUtils()

Method Detail

checkAmountParameterback to summary
public static void checkAmountParameter(MonetaryAmount amount, CurrencyUnit currencyUnit)

Method to check if a currency is compatible with this amount instance.

Parameters
amount:MonetaryAmount

The monetary amount to be compared to, never null.

currencyUnit:CurrencyUnit

the currency unit to compare, never null.

Exceptions
MonetaryException:
If the amount is null, or the amount's CurrencyUnit is not compatible, meaning has a different value of CurrencyUnit#getCurrencyCode()).
checkNumberParameterback to summary
public static void checkNumberParameter(Number number)

Internal method to check for correct number parameter.

Parameters
number:Number

the number to be checked.

Exceptions
IllegalArgumentException:
If the number is null
getBigDecimalback to summary
public static BigDecimal getBigDecimal(long num)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

Parameters
num:long

the number type

Returns:BigDecimal

the corresponding BigDecimal

getBigDecimalback to summary
public static BigDecimal getBigDecimal(double num)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

Parameters
num:double

the number type

Returns:BigDecimal

the corresponding BigDecimal

getBigDecimalback to summary
public static BigDecimal getBigDecimal(Number num)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given.

Parameters
num:Number

the number type

Returns:BigDecimal

the corresponding BigDecimal

getBigDecimalback to summary
public static BigDecimal getBigDecimal(Number num, MonetaryContext moneyContext)

Creates a BigDecimal from the given Number doing the valid conversion depending the type given, if a MonetaryContext is given, it is applied to the number returned.

Parameters
num:Number

the number type

Returns:BigDecimal

the corresponding BigDecimal

getMathContextback to summary
public static MathContext getMathContext(MonetaryContext monetaryContext, RoundingMode defaultMode)

Evaluates the MathContext from the given MonetaryContext.

Parameters
monetaryContext:MonetaryContext

the MonetaryContext

defaultMode:RoundingMode

the default RoundingMode, to be used if no one is set in MonetaryContext.

Returns:MathContext

the corresponding MathContext

replaceNbspWithSpaceback to summary
public static String replaceNbspWithSpace(String s)

Replaces the non-breaking space character U+00A0 and Narrow non-breaking space U+202F from the string with usual space. https://en.wikipedia.org/wiki/Non-breaking_space}