public class BD extends CU
BigDecimals.
The name of this class is an abbreviation of BigDecimal. We have intentionally used a short name for readability because this class is intended to be used in calculations and algebraic statements, for example:
double a = ...; double b = ...; BigDecimal c = ...; if( BD.lt(a,BD.sum(b,c) ) // Do something...instead of
double a = ...; double b = ...; BigDecimal c = ...; if( BigDecimal.valueOf(a).compareTo(BigDecimal.valueOf(b).add(c)) < 0 ) // Do something...
The aim of this utility class is to facilitate operations with BigDecimals.
| Modifier and Type | Field and Description |
|---|---|
static BinaryOperator<BigDecimal> |
DIV
Performs the division of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
MAX
Finds the maximum of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
MIN
Finds the minimum of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
MUL
Performs the multiplication of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
REM
Performs the reminder of the division of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
SUB
Performs the subtraction of two
non-null BigDecimal values. |
static BinaryOperator<BigDecimal> |
SUM
Performs the sum of two
non-null BigDecimal values. |
| Modifier and Type | Method and Description |
|---|---|
static BigDecimal |
apply(BinaryOperator<BigDecimal> operator,
BigDecimal a,
BigDecimal b)
This is a
null-safe method that, given two BigDecimal
values a and b, returns the result of the given operator. |
static BigDecimal |
div(BigDecimal a,
BigDecimal b)
|
static BigDecimal |
div(BigDecimal a,
double b)
|
static BigDecimal |
div(double a,
BigDecimal b)
|
static BigDecimal |
div(double a,
double b)
|
static boolean |
eq(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a == b. |
static boolean |
eq(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a == b. |
static boolean |
eq(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a == b. |
static boolean |
eq(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a == b. |
static boolean |
ge(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a >= b. |
static boolean |
ge(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a >= b. |
static boolean |
ge(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a >= b. |
static boolean |
ge(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a >= b. |
static boolean |
gt(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a > b. |
static boolean |
gt(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a > b. |
static boolean |
gt(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a > b. |
static boolean |
gt(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a > b. |
static boolean |
le(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a <= b. |
static boolean |
le(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a <= b. |
static boolean |
le(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a <= b. |
static boolean |
le(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a <= b. |
static boolean |
lt(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a < b. |
static boolean |
lt(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a < b. |
static boolean |
lt(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a < b. |
static boolean |
lt(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a < b. |
static BigDecimal |
max(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns the
maximum value between them. |
static BigDecimal |
max(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns the
maximum value between them. |
static BigDecimal |
max(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b, returns the
maximum value between them. |
static BigDecimal |
max(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b, returns the
maximum value between them. |
static BigDecimal |
max(double a,
double b)
|
static BigDecimal |
min(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns the
minimum value between them. |
static BigDecimal |
min(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns the
minimum value between them. |
static BigDecimal |
min(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b, returns the
minimum value between them. |
static BigDecimal |
min(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b, returns the
minimum value between them. |
static BigDecimal |
min(double a,
double b)
|
static BigDecimal |
mul(BigDecimal a,
BigDecimal b)
|
static BigDecimal |
mul(BigDecimal a,
double b)
|
static BigDecimal |
mul(double a,
BigDecimal b)
|
static BigDecimal |
mul(double a,
double b)
|
static boolean |
ne(BigDecimal a,
double b)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if {@code a ! |
static boolean |
ne(BigDecimal a,
double b,
boolean nullLast)
This is a
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if {@code a ! |
static boolean |
ne(double a,
BigDecimal b)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if {@code a ! |
static boolean |
ne(double a,
BigDecimal b,
boolean nullLast)
This is a
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if {@code a ! |
static BigDecimal |
of(BigInteger value)
Transforms the given
BigInteger
into a BigDecimal. |
static BigDecimal |
of(double value)
Wrapper for the method
BigDecimal.valueOf(double). |
static BigDecimal |
of(long value)
Wrapper for the method
BigDecimal.valueOf(long). |
static BigDecimal |
of(String value)
Transforms the string representation of a number
into a
BigDecimal. |
static BigDecimal |
rem(BigDecimal a,
BigDecimal b)
|
static BigDecimal |
rem(BigDecimal a,
double b)
|
static BigDecimal |
rem(double a,
BigDecimal b)
|
static BigDecimal |
rem(double a,
double b)
|
static BigDecimal |
sub(BigDecimal a,
BigDecimal b)
|
static BigDecimal |
sub(BigDecimal a,
double b)
|
static BigDecimal |
sub(double a,
BigDecimal b)
|
static BigDecimal |
sub(double a,
double b)
|
static BigDecimal |
sum(BigDecimal a,
BigDecimal b)
|
static BigDecimal |
sum(BigDecimal a,
double b)
|
static BigDecimal |
sum(double a,
BigDecimal b)
|
static BigDecimal |
sum(double a,
double b)
|
nullFirstNaturalOrderComparator, nullLastNaturalOrderComparator, nullSafeNaturalOrderComparatorpublic static BinaryOperator<BigDecimal> SUM
non-null BigDecimal values.public static BinaryOperator<BigDecimal> SUB
non-null BigDecimal values.public static BinaryOperator<BigDecimal> MUL
non-null BigDecimal values.public static BinaryOperator<BigDecimal> DIV
non-null BigDecimal values.public static BinaryOperator<BigDecimal> REM
non-null BigDecimal values.public static BinaryOperator<BigDecimal> MIN
non-null BigDecimal values.public static BinaryOperator<BigDecimal> MAX
non-null BigDecimal values.public static BigDecimal of(double value)
BigDecimal.valueOf(double).value - value of the BigDecimal to return.public static BigDecimal of(long value)
BigDecimal.valueOf(long).value - value of the BigDecimal to return.public static BigDecimal of(String value)
BigDecimal.
If the argument is null or empty
this method returns null.
If the argument is not empty and does not represent a number this method throws an exception.
value - decimal String representation of BigDecimal.NumberFormatException - if value is not a valid
representation of a BigDecimal.public static BigDecimal of(BigInteger value)
BigInteger
into a BigDecimal.
If the argument is null
this method returns null.
value - the BigInteger to be converted into a BigDecimal.public static BigDecimal sum(BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns a + b.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
a - value to add.b - value to add.BigDecimal representing a + b.public static BigDecimal sum(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns a + b.
If the BigDecimal values is null, the other will be returned.
a - value to add.b - value to add.BigDecimal representing a + b.public static BigDecimal sum(double a, BigDecimal b)
null-safe method that, given a double value
a and a BigDecimal value b, returns a + b.
If the BigDecimal values is null, the other will be returned.
a - value to add.b - value to add.BigDecimal representing a + b.public static BigDecimal sum(double a, double b)
a - value to add.b - value to add.BigDecimal representing a + b.public static BigDecimal sub(BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns a - b.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
a - value to subtract from.b - value to be subtracted.BigDecimal representing a - b.public static BigDecimal sub(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns a - b.
If the BigDecimal values is null, the other will be returned.
a - value to subtract from.b - value to be subtracted.BigDecimal representing a - b.public static BigDecimal sub(double a, BigDecimal b)
null-safe method that, given a double value
a and a BigDecimal value b, returns a - b.
If the BigDecimal values is null, the other will be returned.
a - value to subtract from.b - value to be subtracted.BigDecimal representing a - b.public static BigDecimal sub(double a, double b)
a - value to subtract from.b - value to be subtracted.BigDecimal representing a - b.public static BigDecimal mul(BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns a * b.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
a - value to multiply.b - value to multiply.BigDecimal representing a * b.public static BigDecimal mul(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns a * b.
If the BigDecimal values is null, the other will be returned.
a - value to multiply.b - value to multiply.BigDecimal representing a * b.public static BigDecimal mul(double a, BigDecimal b)
null-safe method that, given a double value
a and a BigDecimal value b, returns a * b.
If the BigDecimal values is null, the other will be returned.
a - value to multiply.b - value to multiply.BigDecimal representing a * b.public static BigDecimal mul(double a, double b)
a - value to multiply.b - value to multiply.BigDecimal representing a * b.public static BigDecimal div(BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns a / b.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a / b.public static BigDecimal div(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns a / b.
If the BigDecimal values is null, the other will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a / b.public static BigDecimal div(double a, BigDecimal b)
null-safe method that, given a double value
a and a BigDecimal value b, returns a / b.
If the BigDecimal values is null, the other will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a / b.public static BigDecimal div(double a, double b)
a - value to be divided.b - the divider value.BigDecimal representing a / b.public static BigDecimal rem(BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns a % b.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a % b.public static BigDecimal rem(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns a % b.
If the BigDecimal values is null, the other will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a % b.public static BigDecimal rem(double a, BigDecimal b)
null-safe method that, given a double value
a and a BigDecimal value b, returns a % b.
If the BigDecimal values is null, the other will be returned.
a - value to be divided.b - the divider value.BigDecimal representing a % b.public static BigDecimal rem(double a, double b)
a - value to be divided.b - the divider value.BigDecimal representing a % b.public static BigDecimal min(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns the
minimum value between them. If the values are equal returns a.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a and b.public static BigDecimal min(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns the
minimum value between them. If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.public static BigDecimal min(double a, BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b, returns the
minimum value between them. If the values are equal returns a.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a and b.public static BigDecimal min(double a, BigDecimal b, boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b, returns the
minimum value between them. If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.public static BigDecimal min(double a, double b)
a - value to compare.b - value to compare.a and b.public static BigDecimal max(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns the
maximum value between them. If the values are equal returns a.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a and b.public static BigDecimal max(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns the
maximum value between them. If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.public static BigDecimal max(double a, BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b, returns the
maximum value between them. If the values are equal returns a.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a and b.public static BigDecimal max(double a, BigDecimal b, boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b, returns the
maximum value between them. If the values are equal returns a.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a and b.public static BigDecimal max(double a, double b)
a - value to compare.b - value to compare.a and b.public static boolean lt(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a < b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a < b.public static boolean lt(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a < b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a < b.public static boolean lt(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a < b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a < b.public static boolean lt(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a < b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a < b.public static boolean le(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a <= b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a <= b.public static boolean le(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a <= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a <= b.public static boolean le(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a <= b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a <= b.public static boolean le(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a <= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a <= b.public static boolean eq(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a == b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a == b.public static boolean eq(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a == b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a == b.public static boolean eq(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a == b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a == b.public static boolean eq(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a == b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a == b.public static boolean ne(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a != b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a != b.public static boolean ne(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a != b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a != b.public static boolean ne(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a != b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a != b.public static boolean ne(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a != b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a != b.public static boolean ge(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a >= b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a >= b.public static boolean ge(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a >= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a >= b.public static boolean ge(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a >= b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a >= b.public static boolean ge(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a >= b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a >= b.public static boolean gt(BigDecimal a, double b)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a > b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a > b.public static boolean gt(BigDecimal a, double b, boolean nullLast)
null-safe method that, given a BigDecimal
value a and a double value b, returns true
if a > b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a > b.public static boolean gt(double a,
BigDecimal b)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a > b.
This method considers null to be less than non-null.
a - value to compare.b - value to compare.a > b.public static boolean gt(double a,
BigDecimal b,
boolean nullLast)
null-safe method that, given a double
value a and a BigDecimal value b,
returns true if a > b.
This method considers null to be less than or greater
than non-null based on the value of nullLast.
a - value to compare.b - value to compare.nullLast - tells if null is greater than non-null.a > b.public static BigDecimal apply(BinaryOperator<BigDecimal> operator, BigDecimal a, BigDecimal b)
null-safe method that, given two BigDecimal
values a and b, returns the result of the given operator.
If one of the values is null, the other will be returned.
If both values are null, then null will be returned.
operator - the operator to be applied.a - an operand.b - an operand.Copyright © 2011–2020 Nerd4j. All rights reserved.