From 1311d6949a2b7487766ab3c5ba86c5b9ee84d42c Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Thu, 21 Jul 2022 09:15:02 -0400 Subject: [PATCH] Refactor some internals --- .../org/apache/commons/lang3/ArrayUtils.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 741372499..d3f3431ef 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -1628,6 +1628,20 @@ public class ArrayUtils { return indexOf(array, objectToFind) != INDEX_NOT_FOUND; } + /** + * Checks if the value is in the given array. + *

+ * The method returns {@code false} if a {@code null} array is passed in. + *

+ * + * @param array the array to search through + * @param valueToFind the value to find + * @return {@code true} if the array contains the object + */ + public static boolean contains(final short[] array, final short valueToFind) { + return indexOf(array, valueToFind) != INDEX_NOT_FOUND; + } + /** * Checks if any of the objects are in the given array. *

@@ -1643,20 +1657,6 @@ public class ArrayUtils { return Streams.of(objectsToFind).anyMatch(e -> contains(array, e)); } - /** - * Checks if the value is in the given array. - *

- * The method returns {@code false} if a {@code null} array is passed in. - *

- * - * @param array the array to search through - * @param valueToFind the value to find - * @return {@code true} if the array contains the object - */ - public static boolean contains(final short[] array, final short valueToFind) { - return indexOf(array, valueToFind) != INDEX_NOT_FOUND; - } - /** * Returns a copy of the given array of size 1 greater than the argument. * The last value of the array is left to the default value. @@ -3151,6 +3151,16 @@ public class ArrayUtils { return result; } + /** + * Checks if an array is empty or {@code null}. + * + * @param array the array to test + * @return {@code true} if the array is empty or {@code null} + */ + private static boolean isArrayEmpty(final Object array) { + return getLength(array) == 0; + } + /** * Returns whether a given array can safely be accessed at the given index. * @@ -3178,7 +3188,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final boolean[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3189,7 +3199,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final byte[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3200,7 +3210,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final char[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3211,7 +3221,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final double[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3222,7 +3232,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final float[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3233,7 +3243,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final int[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3244,7 +3254,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final long[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3255,7 +3265,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final Object[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /** @@ -3266,7 +3276,7 @@ public class ArrayUtils { * @since 2.1 */ public static boolean isEmpty(final short[] array) { - return getLength(array) == 0; + return isArrayEmpty(array); } /**