public final class Numbers extends Object
Modifier and Type | Method and Description |
---|---|
static int |
safeIntValueOf(long aLong)
Safely convert a long to an int.
|
static long |
safeLongValueOfMultiply(long... longs)
Safely compute the product of the given longs.
|
static long |
safeLongValueOfSum(long... longs)
Safely compute the sum of the given longs.
|
public static int safeIntValueOf(long aLong)
Integer.MAX_VALUE
then
Integer.MAX_VALUE
is returned.
If the long is lesser than Integer.MIN_VALUE
then Integer.MIN_VALUE
is returned.
Implementation use BigIntegers. See Math.toIntExact(long)
for a throwing equivalent.
aLong
- A long
public static long safeLongValueOfSum(long... longs)
Long.MAX_VALUE
then
Long.MAX_VALUE
is returned.
If the sum of all the longs is lesser than Long.MIN_VALUE
then Long.MIN_VALUE
is returned.
Implementation use BigIntegers. See Math.addExact(long, long)
for a throwing equivalent.
longs
- longs to sum
public static long safeLongValueOfMultiply(long... longs)
Long.MAX_VALUE
then
Long.MAX_VALUE
is returned.
If the product of all the longs is lesser than Long.MIN_VALUE
then Long.MIN_VALUE
is returned.
Implementation use BigIntegers. See Math.multiplyExact(long, long)
for a throwing equivalent.
longs
- longs to multiply