- java.lang.Object
-
- life.expert.value.numeric.utils.NumberUtils
-
public class NumberUtils extends java.lang.ObjectThis utility class simplifies implementingAmount, by providing the common functionality. The different explicitly typed methods are all reduced to methods usingBigDecimalas input, hereby performing any conversion toBigDecimalas needed. Obviously this takes some time, so implementors that want to avoid this overhead should implementAmountdirectly.
-
-
Constructor Summary
Constructors Constructor Description NumberUtils()
-
Method Summary
Modifier and Type Method Description static voidcheckAmountParameter(Quantity amount, Unit unit)Method to check if a unit is compatible with this amount instance.static voidcheckNoInfinityOrNaN(java.lang.Number number)Check no infinity or na n.static voidcheckNumberParameter(java.lang.Number number)Internal method to check for correct number parameter.static java.math.BigDecimalgetBigDecimal(double num)Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.static java.math.BigDecimalgetBigDecimal(long num)Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.static java.math.BigDecimalgetBigDecimal(java.lang.Number num)Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.static java.math.BigDecimalgetBigDecimal(java.lang.Number num, AmountContext amountContext)Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given, if aAmountContextis given, it is applied to the number returned.static java.math.MathContextgetMathContext(AmountContext amountContext, java.math.RoundingMode defaultMode)Evaluates theMathContextfrom the givenAmountContext.static booleanisInfinityAndNotNaN(java.lang.Number number)Is infinity and not na n boolean.
-
-
-
Method Detail
-
getBigDecimal
public static java.math.BigDecimal getBigDecimal(long num)
Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.- Parameters:
num- the number type- Returns:
- the corresponding
BigDecimal
-
getBigDecimal
public static java.math.BigDecimal getBigDecimal(double num)
Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.- Parameters:
num- the number type- Returns:
- the corresponding
BigDecimal
-
getBigDecimal
public static java.math.BigDecimal getBigDecimal(java.lang.Number num)
Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given.- Parameters:
num- the number type- Returns:
- the corresponding
BigDecimal
-
getBigDecimal
public static java.math.BigDecimal getBigDecimal(java.lang.Number num, AmountContext amountContext)Creates aBigDecimalfrom the givenNumberdoing the valid conversion depending the type given, if aAmountContextis given, it is applied to the number returned.- Parameters:
num- the number typeamountContext- the money context- Returns:
- the corresponding
BigDecimal
-
getMathContext
public static java.math.MathContext getMathContext(AmountContext amountContext, java.math.RoundingMode defaultMode)
Evaluates theMathContextfrom the givenAmountContext.- Parameters:
amountContext- theAmountContextdefaultMode- the defaultRoundingMode, to be used if no one is set inAmountContext.- Returns:
- the corresponding
MathContext
-
checkAmountParameter
public static void checkAmountParameter(Quantity amount, Unit unit)
Method to check if a unit is compatible with this amount instance.- Parameters:
amount- The amount to be compared to, never null.unit- the amount's unit to compare, never null.- Throws:
ValueException- If the amount is null, or the amount'sUnitis not compatible, meaning has a different value ofUnit.getCode()()}).
-
checkNumberParameter
public static void checkNumberParameter(java.lang.Number number)
Internal method to check for correct number parameter.- Parameters:
number- the number to be checked.- Throws:
java.lang.IllegalArgumentException- If the number is null
-
checkNoInfinityOrNaN
public static void checkNoInfinityOrNaN(java.lang.Number number)
Check no infinity or na n.- Parameters:
number- the number
-
isInfinityAndNotNaN
public static boolean isInfinityAndNotNaN(java.lang.Number number)
Is infinity and not na n boolean.- Parameters:
number- the number- Returns:
- the boolean
-
-