@Immutable public final class MathHelper extends Object
| Modifier and Type | Method and Description |
|---|---|
static BigDecimal |
abs(BigDecimal aValue)
This is a sanity method wrapping
BigDecimal.abs (double), so
that you don't have to think whether you need to invoke the abs method from
this class or the one from BigDecimal directly. |
static BigInteger |
abs(BigInteger aValue)
This is a sanity method wrapping
BigInteger.abs (double), so
that you don't have to think whether you need to invoke the abs method from
this class or the one from BigInteger directly. |
static double |
abs(double dValue)
This is a sanity method wrapping
Math.abs (double), so that
you don't have to think whether you need to invoke the abs method from this
class or the one from Math directly. |
static float |
abs(float fValue)
This is a sanity method wrapping
Math.abs (float), so that you
don't have to think whether you need to invoke the abs method from this
class or the one from Math directly. |
static int |
abs(int nValue)
This is a fix for
Math.abs as it would return
Integer.MIN_VALUE for Integer.MIN_VALUE which is very
unexpected. |
static long |
abs(long nValue)
This is a fix for
Math.abs as it would return
Long.MIN_VALUE for Long.MIN_VALUE which is very unexpected. |
static BigDecimal |
addPercent(BigDecimal aBase,
BigDecimal aPercentage)
Add x% to base
|
static boolean |
canConvertLongToInt(long nValue) |
static BigDecimal |
getDividedBigDecimal(int nDividend,
int nDivisor)
Get the division result using
BigDecimal. |
static double |
getDividedDouble(int nDividend,
int nDivisor)
Divides the passed int dividend through the passed divisor (nDividend /
nDivisor)
|
static int |
getFractionDigits(BigDecimal aBD)
Get the number of effective fraction digits by the specified BigDecimal.
|
static int |
getIntDivided(int nDividend,
int nDivisor,
RoundingMode eRoundingMode) |
static int |
getIntDividedCeil(int nDividend,
int nDivisor) |
static int |
getIntDividedFloor(int nDividend,
int nDivisor) |
static int |
getLongAsInt(long nValue,
int nFallback) |
static long |
getLongDivided(long nDividend,
long nDivisor,
RoundingMode eRoundingMode) |
static long |
getLongDividedCeil(long nDividend,
long nDivisor) |
static long |
getLongDividedFloor(long nDividend,
long nDivisor) |
static BigDecimal |
getMaxBigDecimal(BigDecimal aValue,
BigDecimal... aValues) |
static BigInteger |
getMaxBigInteger(BigInteger aValue,
BigInteger... aValues) |
static double |
getMaxDouble(double dValue,
double... aValues) |
static double |
getMaxFloat(float fValue,
float... aValues) |
static int |
getMaxInt(int nValue,
int... aValues) |
static long |
getMaxLong(long nValue,
long... aValues) |
static BigDecimal |
getMinBigDecimal(BigDecimal aValue,
BigDecimal... aValues) |
static BigInteger |
getMinBigInteger(BigInteger aValue,
BigInteger... aValues) |
static double |
getMinDouble(double dValue,
double... aValues) |
static double |
getMinFloat(float fValue,
float... aValues) |
static int |
getMinInt(int nValue,
int... aValues) |
static long |
getMinLong(long nValue,
long... aValues) |
static BigDecimal |
getPercentValue(BigDecimal aBase,
BigDecimal aPercentage)
Get x% from base
|
static BigDecimal |
getPercentValue(BigDecimal aBase,
BigDecimal aPercentage,
int nScale,
RoundingMode eRoundingMode)
Get x% from base with rounding etc.
|
static int |
getRoundedUp(int nToRound,
int nMultiple)
Round up to the nearest multiple of the value to round.
|
static long |
getUnsignedInt(int n)
Converts the passed signed integer to an unsigned long
|
static BigDecimal |
getWithoutTrailingZeroes(BigDecimal aValue)
Get the passed BigDecimal without any trailing zeroes.
|
static BigDecimal |
getWithoutTrailingZeroes(String sValue)
Get the passed String as a BigDecimal without any trailing zeroes.
|
static double |
hypot(double a,
double b) |
static boolean |
isEqualTo100(BigDecimal aValue) |
static boolean |
isEqualTo100(BigInteger aValue) |
static boolean |
isEqualToOne(BigDecimal aValue) |
static boolean |
isEqualToOne(BigInteger aValue) |
static boolean |
isEqualToTen(BigDecimal aValue) |
static boolean |
isEqualToTen(BigInteger aValue) |
static boolean |
isEqualToZero(BigDecimal aValue) |
static boolean |
isEqualToZero(BigInteger aValue) |
static boolean |
isGreaterOrEqualThan100(BigDecimal aValue) |
static boolean |
isGreaterOrEqualThan100(BigInteger aValue) |
static boolean |
isGreaterOrEqualThanOne(BigDecimal aValue) |
static boolean |
isGreaterOrEqualThanOne(BigInteger aValue) |
static boolean |
isGreaterOrEqualThanTen(BigDecimal aValue) |
static boolean |
isGreaterOrEqualThanTen(BigInteger aValue) |
static boolean |
isGreaterOrEqualThanZero(BigDecimal aValue) |
static boolean |
isGreaterOrEqualThanZero(BigInteger aValue) |
static boolean |
isGreaterThan100(BigDecimal aValue) |
static boolean |
isGreaterThan100(BigInteger aValue) |
static boolean |
isGreaterThanOne(BigDecimal aValue) |
static boolean |
isGreaterThanOne(BigInteger aValue) |
static boolean |
isGreaterThanTen(BigDecimal aValue) |
static boolean |
isGreaterThanTen(BigInteger aValue) |
static boolean |
isGreaterThanZero(BigDecimal aValue) |
static boolean |
isGreaterThanZero(BigInteger aValue) |
static boolean |
isLowerOrEqualThan100(BigDecimal aValue) |
static boolean |
isLowerOrEqualThan100(BigInteger aValue) |
static boolean |
isLowerOrEqualThanOne(BigDecimal aValue) |
static boolean |
isLowerOrEqualThanOne(BigInteger aValue) |
static boolean |
isLowerOrEqualThanTen(BigDecimal aValue) |
static boolean |
isLowerOrEqualThanTen(BigInteger aValue) |
static boolean |
isLowerOrEqualThanZero(BigDecimal aValue) |
static boolean |
isLowerOrEqualThanZero(BigInteger aValue) |
static boolean |
isLowerThan100(BigDecimal aValue) |
static boolean |
isLowerThan100(BigInteger aValue) |
static boolean |
isLowerThanOne(BigDecimal aValue) |
static boolean |
isLowerThanOne(BigInteger aValue) |
static boolean |
isLowerThanTen(BigDecimal aValue) |
static boolean |
isLowerThanTen(BigInteger aValue) |
static boolean |
isLowerThanZero(BigDecimal aValue) |
static boolean |
isLowerThanZero(BigInteger aValue) |
static boolean |
isNotEqualTo100(BigDecimal aValue) |
static boolean |
isNotEqualTo100(BigInteger aValue) |
static boolean |
isNotEqualToOne(BigDecimal aValue) |
static boolean |
isNotEqualToOne(BigInteger aValue) |
static boolean |
isNotEqualToTen(BigDecimal aValue) |
static boolean |
isNotEqualToTen(BigInteger aValue) |
static boolean |
isNotEqualToZero(BigDecimal aValue) |
static boolean |
isNotEqualToZero(BigInteger aValue) |
static BigDecimal |
subtractPercent(BigDecimal aBase,
BigDecimal aPercentage)
Subtract x% from base
|
static BigDecimal |
toBigDecimal(double d) |
static BigDecimal |
toBigDecimal(float f) |
static BigDecimal |
toBigDecimal(int n) |
static BigDecimal |
toBigDecimal(long n) |
static BigDecimal |
toBigDecimal(Number aNumber) |
static BigInteger |
toBigInteger(int n) |
static BigInteger |
toBigInteger(long n) |
static BigInteger |
toBigInteger(Number aNumber) |
public static int getRoundedUp(int nToRound,
@Nonnegative
int nMultiple)
nToRound - Value to round. May be positive or negative.nMultiple - Multiple to use. Must be ≥ 0.public static double getDividedDouble(int nDividend,
int nDivisor)
nDividend - the dividendnDivisor - the divisorDouble.NaN if the divisor is 0.@Nonnull public static BigDecimal getDividedBigDecimal(int nDividend, int nDivisor) throws ArithmeticException
BigDecimal.nDividend - the dividendnDivisor - the divisorArithmeticException - if the divisor is 0.public static int getIntDividedCeil(int nDividend,
int nDivisor)
public static int getIntDividedFloor(int nDividend,
int nDivisor)
public static int getIntDivided(int nDividend,
int nDivisor,
@Nonnull
RoundingMode eRoundingMode)
public static long getLongDividedCeil(long nDividend,
long nDivisor)
public static long getLongDividedFloor(long nDividend,
long nDivisor)
public static long getLongDivided(long nDividend,
long nDivisor,
@Nonnull
RoundingMode eRoundingMode)
public static boolean canConvertLongToInt(long nValue)
@CheckReturnValue public static int getLongAsInt(long nValue, int nFallback)
public static int getMaxInt(int nValue,
@Nonnull
int... aValues)
public static long getMaxLong(long nValue,
@Nonnull
long... aValues)
public static double getMaxFloat(float fValue,
@Nonnull
float... aValues)
public static double getMaxDouble(double dValue,
@Nonnull
double... aValues)
@Nonnull public static BigDecimal getMaxBigDecimal(@Nonnull BigDecimal aValue, @Nonnull BigDecimal... aValues)
@Nonnull public static BigInteger getMaxBigInteger(@Nonnull BigInteger aValue, @Nonnull BigInteger... aValues)
public static int getMinInt(int nValue,
@Nonnull
int... aValues)
public static long getMinLong(long nValue,
@Nonnull
long... aValues)
public static double getMinFloat(float fValue,
@Nonnull
float... aValues)
public static double getMinDouble(double dValue,
@Nonnull
double... aValues)
@Nonnull public static BigDecimal getMinBigDecimal(@Nonnull BigDecimal aValue, @Nonnull BigDecimal... aValues)
@Nonnull public static BigInteger getMinBigInteger(@Nonnull BigInteger aValue, @Nonnull BigInteger... aValues)
@Nonnegative public static int abs(int nValue)
Math.abs as it would return
Integer.MIN_VALUE for Integer.MIN_VALUE which is very
unexpected. Instead an exception is thrown.nValue - Input valueIllegalArgumentException - if the input value is Integer.MIN_VALUE@Nonnegative public static long abs(long nValue)
Math.abs as it would return
Long.MIN_VALUE for Long.MIN_VALUE which is very unexpected.
Instead an exception is thrown.nValue - Input valueIllegalArgumentException - if the input value is Long.MIN_VALUE@Nonnegative public static float abs(float fValue)
Math.abs (float), so that you
don't have to think whether you need to invoke the abs method from this
class or the one from Math directly.fValue - Input value@Nonnegative public static double abs(double dValue)
Math.abs (double), so that
you don't have to think whether you need to invoke the abs method from this
class or the one from Math directly.dValue - Input value@Nonnull public static BigDecimal abs(@Nonnull BigDecimal aValue)
BigDecimal.abs (double), so
that you don't have to think whether you need to invoke the abs method from
this class or the one from BigDecimal directly.aValue - Input value@Nonnull public static BigInteger abs(@Nonnull BigInteger aValue)
BigInteger.abs (double), so
that you don't have to think whether you need to invoke the abs method from
this class or the one from BigInteger directly.aValue - Input valuepublic static boolean isEqualToZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is = 0.public static boolean isNotEqualToZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is != 0.public static boolean isLowerThanZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is < 0.public static boolean isLowerOrEqualThanZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 0.public static boolean isGreaterThanZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is > 0.public static boolean isGreaterOrEqualThanZero(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 0.public static boolean isEqualToOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is = 1.public static boolean isNotEqualToOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is != 1.public static boolean isLowerThanOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is < 1.public static boolean isLowerOrEqualThanOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 1.public static boolean isGreaterThanOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is > 1.public static boolean isGreaterOrEqualThanOne(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 1.public static boolean isEqualToTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is = 10.public static boolean isNotEqualToTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is != 10.public static boolean isLowerThanTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is < 10.public static boolean isLowerOrEqualThanTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 10.public static boolean isGreaterThanTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is > 10.public static boolean isGreaterOrEqualThanTen(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 10.public static boolean isEqualTo100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is = 100.public static boolean isNotEqualTo100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is != 100.public static boolean isLowerThan100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is < 100.public static boolean isLowerOrEqualThan100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 100.public static boolean isGreaterThan100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is > 100.public static boolean isGreaterOrEqualThan100(@Nonnull BigDecimal aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 100.public static boolean isEqualToZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is = 0.public static boolean isNotEqualToZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is != 0.public static boolean isLowerThanZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is < 0.public static boolean isLowerOrEqualThanZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 0.public static boolean isGreaterThanZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is > 0.public static boolean isGreaterOrEqualThanZero(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 0.public static boolean isEqualToOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is = 1.public static boolean isNotEqualToOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is != 1.public static boolean isLowerThanOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is < 1.public static boolean isLowerOrEqualThanOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 1.public static boolean isGreaterThanOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is > 1.public static boolean isGreaterOrEqualThanOne(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 1.public static boolean isEqualToTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is = 10.public static boolean isNotEqualToTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is != 10.public static boolean isLowerThanTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is < 10.public static boolean isLowerOrEqualThanTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 10.public static boolean isGreaterThanTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is > 10.public static boolean isGreaterOrEqualThanTen(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 10.public static boolean isEqualTo100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is = 100.public static boolean isNotEqualTo100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is != 100.public static boolean isLowerThan100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is < 100.public static boolean isLowerOrEqualThan100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≤ 100.public static boolean isGreaterThan100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is > 100.public static boolean isGreaterOrEqualThan100(@Nonnull BigInteger aValue)
aValue - Value to compare. May not be null.true if the value is ≥ 100.@Nullable @CheckReturnValue public static BigDecimal getWithoutTrailingZeroes(@Nullable String sValue)
sValue - The String to be used as a BigDecimal to be modified. May be
null.null if the input value is null.@Nullable @CheckReturnValue public static BigDecimal getWithoutTrailingZeroes(@Nullable BigDecimal aValue)
aValue - The BigDecimal to be modified. May be null.null if the input value is null.@Nonnegative public static int getFractionDigits(@Nonnull BigDecimal aBD)
aBD - The BigDecimal to check. May not be null.@Nonnull public static BigDecimal addPercent(@Nonnull BigDecimal aBase, @Nonnull BigDecimal aPercentage)
aBase - Base value. May not be null.aPercentage - Percentage value (0-100). May not be null.=aBase * (100 + perc) / 100). Never
null.@Nonnull public static BigDecimal subtractPercent(@Nonnull BigDecimal aBase, @Nonnull BigDecimal aPercentage)
aBase - Base value. May not be null.aPercentage - Percentage value (0-100). May not be null.=aBase * (100 - perc) / 100). Never
null.@Nonnull public static BigDecimal getPercentValue(@Nonnull BigDecimal aBase, @Nonnull BigDecimal aPercentage)
aBase - Base value. May not be null.aPercentage - Percentage value (0-100). May not be null.=aBase * perc / 100). Never
null.@Nonnull public static BigDecimal getPercentValue(@Nonnull BigDecimal aBase, @Nonnull BigDecimal aPercentage, @Nonnegative int nScale, @Nonnull RoundingMode eRoundingMode)
aBase - Base value. May not be null.aPercentage - Percentage value (0-100). May not be null.nScale - Maximum scale to achieve.eRoundingMode - Rounding mode to used. May not be null.=aBase * perc / 100). Never
null.public static double hypot(double a,
double b)
a - ab - bpublic static long getUnsignedInt(int n)
n - Source int@Nonnull public static BigDecimal toBigDecimal(int n)
@Nonnull public static BigDecimal toBigDecimal(long n)
@Nonnull public static BigDecimal toBigDecimal(float f)
@Nonnull public static BigDecimal toBigDecimal(double d)
@Nonnull public static BigDecimal toBigDecimal(@Nonnull Number aNumber)
@Nonnull public static BigInteger toBigInteger(int n)
@Nonnull public static BigInteger toBigInteger(long n)
@Nonnull public static BigInteger toBigInteger(@Nonnull Number aNumber)
Copyright © 2014–2016 Philip Helger. All rights reserved.