LANG-856 Code refactoring in NumberUtils
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1408713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d844d1eb5e
commit
f5a83bb90c
|
@ -22,6 +22,7 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.2" date="TBA" description="Next release">
|
<release version="3.2" date="TBA" description="Next release">
|
||||||
|
<action issue="LANG-856" type="add">Code refactoring in NumberUtils</action>
|
||||||
<action issue="LANG-855" type="add">NumberUtils#createBigInteger does not allow for hex and octal numbers</action>
|
<action issue="LANG-855" type="add">NumberUtils#createBigInteger does not allow for hex and octal numbers</action>
|
||||||
<action issue="LANG-854" type="add">NumberUtils#createNumber - does not allow for hex numbers to be larger than Long</action>
|
<action issue="LANG-854" type="add">NumberUtils#createNumber - does not allow for hex numbers to be larger than Long</action>
|
||||||
<action issue="LANG-853" type="add">StringUtils join APIs for primitives</action>
|
<action issue="LANG-853" type="add">StringUtils join APIs for primitives</action>
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.commons.lang3.math;
|
package org.apache.commons.lang3.math;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
@ -766,11 +767,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static long min(long[] array) {
|
public static long min(long[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
long min = array[0];
|
long min = array[0];
|
||||||
|
@ -793,11 +790,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static int min(int[] array) {
|
public static int min(int[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
int min = array[0];
|
int min = array[0];
|
||||||
|
@ -820,11 +813,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static short min(short[] array) {
|
public static short min(short[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
short min = array[0];
|
short min = array[0];
|
||||||
|
@ -847,11 +836,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static byte min(byte[] array) {
|
public static byte min(byte[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
byte min = array[0];
|
byte min = array[0];
|
||||||
|
@ -875,11 +860,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static double min(double[] array) {
|
public static double min(double[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
double min = array[0];
|
double min = array[0];
|
||||||
|
@ -906,11 +887,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static float min(float[] array) {
|
public static float min(float[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns min
|
// Finds and returns min
|
||||||
float min = array[0];
|
float min = array[0];
|
||||||
|
@ -938,11 +915,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static long max(long[] array) {
|
public static long max(long[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
long max = array[0];
|
long max = array[0];
|
||||||
|
@ -965,11 +938,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static int max(int[] array) {
|
public static int max(int[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
int max = array[0];
|
int max = array[0];
|
||||||
|
@ -992,11 +961,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static short max(short[] array) {
|
public static short max(short[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
short max = array[0];
|
short max = array[0];
|
||||||
|
@ -1019,11 +984,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static byte max(byte[] array) {
|
public static byte max(byte[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
byte max = array[0];
|
byte max = array[0];
|
||||||
|
@ -1047,11 +1008,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static double max(double[] array) {
|
public static double max(double[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array== null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
double max = array[0];
|
double max = array[0];
|
||||||
|
@ -1078,11 +1035,7 @@ public class NumberUtils {
|
||||||
*/
|
*/
|
||||||
public static float max(float[] array) {
|
public static float max(float[] array) {
|
||||||
// Validates input
|
// Validates input
|
||||||
if (array == null) {
|
validateArray(array);
|
||||||
throw new IllegalArgumentException("The Array must not be null");
|
|
||||||
} else if (array.length == 0) {
|
|
||||||
throw new IllegalArgumentException("Array cannot be empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finds and returns max
|
// Finds and returns max
|
||||||
float max = array[0];
|
float max = array[0];
|
||||||
|
@ -1098,6 +1051,14 @@ public class NumberUtils {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void validateArray(Object array) {
|
||||||
|
if (array == null) {
|
||||||
|
throw new IllegalArgumentException("The Array must not be null");
|
||||||
|
} else if (Array.getLength(array) == 0) {
|
||||||
|
throw new IllegalArgumentException("Array cannot be empty.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3 param min
|
// 3 param min
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue