From 1fdcb829bb8aa3abbf8d930f4b684b525cd68471 Mon Sep 17 00:00:00 2001 From: Niall Pemberton Date: Mon, 22 Feb 2010 23:22:18 +0000 Subject: [PATCH] Minor code simplification git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@915110 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/ArrayUtils.java | 73 +++++-------------- 1 file changed, 18 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 7f9cae540..648249881 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -457,9 +457,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Object[] nullToEmpty(Object[] array) { - if (array == null) { - return EMPTY_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_OBJECT_ARRAY; } return array; @@ -478,9 +476,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static String[] nullToEmpty(String[] array) { - if (array == null) { - return EMPTY_STRING_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_STRING_ARRAY; } return array; @@ -499,10 +495,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static long[] nullToEmpty(long[] array) { - if (array == null) { - return EMPTY_LONG_ARRAY; - } - if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_LONG_ARRAY; } return array; @@ -521,9 +514,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static int[] nullToEmpty(int[] array) { - if (array == null) { - return EMPTY_INT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_INT_ARRAY; } return array; @@ -542,9 +533,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static short[] nullToEmpty(short[] array) { - if (array == null) { - return EMPTY_SHORT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_SHORT_ARRAY; } return array; @@ -563,9 +552,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static char[] nullToEmpty(char[] array) { - if (array == null) { - return EMPTY_CHAR_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_CHAR_ARRAY; } return array; @@ -584,9 +571,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static byte[] nullToEmpty(byte[] array) { - if (array == null) { - return EMPTY_BYTE_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_BYTE_ARRAY; } return array; @@ -605,9 +590,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static double[] nullToEmpty(double[] array) { - if (array == null) { - return EMPTY_DOUBLE_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_DOUBLE_ARRAY; } return array; @@ -626,9 +609,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static float[] nullToEmpty(float[] array) { - if (array == null) { - return EMPTY_FLOAT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_FLOAT_ARRAY; } return array; @@ -647,9 +628,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static boolean[] nullToEmpty(boolean[] array) { - if (array == null) { - return EMPTY_BOOLEAN_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_BOOLEAN_ARRAY; } return array; @@ -668,9 +647,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Long[] nullToEmpty(Long[] array) { - if (array == null) { - return EMPTY_LONG_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_LONG_OBJECT_ARRAY; } return array; @@ -689,9 +666,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Integer[] nullToEmpty(Integer[] array) { - if (array == null) { - return EMPTY_INTEGER_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_INTEGER_OBJECT_ARRAY; } return array; @@ -710,9 +685,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Short[] nullToEmpty(Short[] array) { - if (array == null) { - return EMPTY_SHORT_OBJECT_ARRAY; - }else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_SHORT_OBJECT_ARRAY; } return array; @@ -731,9 +704,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Character[] nullToEmpty(Character[] array) { - if (array == null) { - return EMPTY_CHARACTER_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_CHARACTER_OBJECT_ARRAY; } return array; @@ -752,9 +723,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Byte[] nullToEmpty(Byte[] array) { - if (array == null) { - return EMPTY_BYTE_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_BYTE_OBJECT_ARRAY; } return array; @@ -773,9 +742,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Double[] nullToEmpty(Double[] array) { - if (array == null) { - return EMPTY_DOUBLE_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_DOUBLE_OBJECT_ARRAY; } return array; @@ -794,9 +761,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Float[] nullToEmpty(Float[] array) { - if (array == null) { - return EMPTY_FLOAT_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_FLOAT_OBJECT_ARRAY; } return array; @@ -815,9 +780,7 @@ public class ArrayUtils { * @return the same array, public static empty array if null or empty input */ public static Boolean[] nullToEmpty(Boolean[] array) { - if (array == null) { - return EMPTY_BOOLEAN_OBJECT_ARRAY; - } else if (array.length == 0) { + if (array == null || array.length == 0) { return EMPTY_BOOLEAN_OBJECT_ARRAY; } return array;