Modifier and Type | Method | Description |
---|---|---|
static Byte |
getNullSafe(Byte value) |
Returns a non-null byte, even if the object being passed is a null byte.
|
static Double |
getNullSafe(Double value) |
Returns a non-null double, even if the object being passed is a null double.
|
static Float |
getNullSafe(Float value) |
Returns a non-null float, even if the object being passed is a null float.
|
static Integer |
getNullSafe(Integer value) |
Returns a non-null integer, even if the object being passed is a null integer.
|
static Long |
getNullSafe(Long value) |
Returns a non-null long, even if the object being passed is a null long.
|
static Short |
getNullSafe(Short value) |
Returns a non-null short, even if the object being passed is a null short.
|
static int |
getNumOfDigits(int number) |
Returns the number of digits in the passed in number.
|
static int[] |
getUniqueRandomNumbers(int bound,
int arraySize) |
Returns an array of pseudorandom int values between zero (inclusive) and the specified upper bound (exclusive).
|
static int[] |
getUniqueRandomNumbers(int lowerBound,
int upperBound,
int arraySize) |
Returns an array of pseudorandom int values between the specified lower bound (inclusive) and the specified upper
bound (exclusive).
|
static boolean |
isPerfectSquare(Byte value) |
Returns
true if number is a Perfect Square. |
static boolean |
isPerfectSquare(Integer value) |
Returns
true if number is a Perfect Square. |
static boolean |
isPerfectSquare(Long value) |
Returns
true if number is a Perfect Square. |
static boolean |
isPerfectSquare(Short value) |
Returns
true if number is a Perfect Square. |
public static Byte getNullSafe(Byte value)
Byte num1 = 10; Byte num2 = null; Byte num3 = NumberHelper.getNullSafe(num1); Byte num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: -128.
value
- The number to safeguard against null
.null
then Byte.MIN_VALUE
.public static Short getNullSafe(Short value)
Short num1 = 10; Short num2 = null; Short num3 = NumberHelper.getNullSafe(num1); Short num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: -2^15.
value
- The number to safeguard against null
.null
then Short.MIN_VALUE
.public static Long getNullSafe(Long value)
Long num1 = 10; Long num2 = null; Long num3 = NumberHelper.getNullSafe(num1); Long num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: -2^63
value
- The number to safeguard against null
.null
then Long.MIN_VALUE
.public static Float getNullSafe(Float value)
Float num1 = 10.0f; Float num2 = null; Float num3 = NumberHelper.getNullSafe(num1); Float num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: 2^-149
value
- The number to safeguard against null
.null
then Float.MIN_VALUE
.public static Double getNullSafe(Double value)
Double num1 = 10.0d; Double num2 = null; Double num3 = NumberHelper.getNullSafe(num1); Double num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: 2^-149
value
- The number to safeguard against null
.null
then Double.MIN_VALUE
.public static Integer getNullSafe(Integer value)
Integer num1 = 10; Integer num2 = null; Integer num3 = NumberHelper.getNullSafe(num1); Integer num4 = NumberHelper.getNullSafe(num2); // num3 now contains the number: 10 // num4 now contains the number: -2^31
value
- The number to safeguard against null
.null
then Integer.MIN_VALUE
.public static boolean isPerfectSquare(Byte value)
true
if number is a Perfect Square.
NumberHelper.isPerfectSquare(0); // true NumberHelper.isPerfectSquare(1); // true NumberHelper.isPerfectSquare(81); // true NumberHelper.isPerfectSquare(100); // true NumberHelper.isPerfectSquare(5); // false NumberHelper.isPerfectSquare(101); // false NumberHelper.isPerfectSquare(250); // false
value
- The number to testpublic static boolean isPerfectSquare(Short value)
true
if number is a Perfect Square.
NumberHelper.isPerfectSquare(0); // true NumberHelper.isPerfectSquare(1); // true NumberHelper.isPerfectSquare(81); // true NumberHelper.isPerfectSquare(100); // true NumberHelper.isPerfectSquare(5); // false NumberHelper.isPerfectSquare(101); // false NumberHelper.isPerfectSquare(250); // false
value
- The number to testpublic static boolean isPerfectSquare(Integer value)
true
if number is a Perfect Square.
NumberHelper.isPerfectSquare(0); // true NumberHelper.isPerfectSquare(1); // true NumberHelper.isPerfectSquare(81); // true NumberHelper.isPerfectSquare(100); // true NumberHelper.isPerfectSquare(5); // false NumberHelper.isPerfectSquare(101); // false NumberHelper.isPerfectSquare(250); // false
value
- The number to testpublic static boolean isPerfectSquare(Long value)
true
if number is a Perfect Square.
NumberHelper.isPerfectSquare(0); // true NumberHelper.isPerfectSquare(1); // true NumberHelper.isPerfectSquare(81); // true NumberHelper.isPerfectSquare(100); // true NumberHelper.isPerfectSquare(5); // false NumberHelper.isPerfectSquare(101); // false NumberHelper.isPerfectSquare(250); // false
value
- The number to testpublic static int[] getUniqueRandomNumbers(int bound, int arraySize)
NumberHelper.getUniqueRandomNumbers(0, upperBound, arraySize)
bound
- the upper bound (exclusive)arraySize
- the number of unique random numbers expectedInteger
array of pseudorandom int values between zero (inclusive) and the upper bound
(exclusive).IllegalArgumentException
- if any of the arguments are negative integersIllegalArgumentException
- if lower bound is greater than or equal to upper boundgetUniqueRandomNumbers(int, int, int)
public static int[] getUniqueRandomNumbers(int lowerBound, int upperBound, int arraySize)
lowerBound
- the least value returnedupperBound
- the upper bound (exclusive)arraySize
- the number of unique random numbers expectedInteger
array of pseudorandom int values between the lower bound (inclusive) and the
upper bound (exclusive).IllegalArgumentException
- if any of the arguments are negative integersIllegalArgumentException
- if lower bound is greater than or equal to upper boundThreadLocalRandom.nextInt(int, int)
,
Collection.stream()
,
Stream.mapToInt(java.util.function.ToIntFunction)
public static int getNumOfDigits(int number)
number
- for which to count the number of digits inCopyright © 2008, 2018, Shaiksphere Inc.. All rights reserved.