Author: niallp
Date: Wed Feb  3 10:52:37 2010
New Revision: 905988

URL: http://svn.apache.org/viewvc?rev=905988&view=rev
Log:
Port LANG-534 to 2.x branch - add nullToEmpty() methods to ArrayUtils

Modified:
    
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
    
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ArrayUtilsTest.java

Modified: 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java?rev=905988&r1=905987&r2=905988&view=diff
==============================================================================
--- 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
 (original)
+++ 
commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/ArrayUtils.java
 Wed Feb  3 10:52:37 2010
@@ -409,6 +409,368 @@
         return (boolean[]) array.clone();
     }
 
+    // nullToEmpty
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Object[] nullToEmpty(Object[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static String[] nullToEmpty(String[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_STRING_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static long[] nullToEmpty(long[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_LONG_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static int[] nullToEmpty(int[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_INT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static short[] nullToEmpty(short[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_SHORT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static char[] nullToEmpty(char[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_CHAR_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static byte[] nullToEmpty(byte[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_BYTE_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static double[] nullToEmpty(double[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_DOUBLE_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static float[] nullToEmpty(float[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_FLOAT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static boolean[] nullToEmpty(boolean[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_BOOLEAN_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Long[] nullToEmpty(Long[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_LONG_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Integer[] nullToEmpty(Integer[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_INTEGER_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Short[] nullToEmpty(Short[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_SHORT_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Character[] nullToEmpty(Character[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_CHARACTER_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Byte[] nullToEmpty(Byte[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_BYTE_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Double[] nullToEmpty(Double[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_DOUBLE_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Float[] nullToEmpty(Float[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_FLOAT_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
+    /**
+     * <p>Defensive programming technique to change a <code>null</code>
+     * reference to an empty one.</p>
+     *
+     * <p>This method returns an empty array for a <code>null</code> input 
array.</p>
+     * 
+     * <p>As a memory optimizing technique an empty array passed in will be 
overridden with 
+     * the empty <code>public static</code> references in this class.</p>
+     *
+     * @param array  the array to check for <code>null</code> or empty
+     * @return the same array, <code>public static</code> empty array if 
<code>null</code> or empty input
+     * @since 2.5
+     */
+    public static Boolean[] nullToEmpty(Boolean[] array) {
+        if (array == null || array.length == 0) {
+            return EMPTY_BOOLEAN_OBJECT_ARRAY;
+        }
+        return array;
+    }
+
     // Subarrays
     //-----------------------------------------------------------------------
     /**

Modified: 
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ArrayUtilsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ArrayUtilsTest.java?rev=905988&r1=905987&r2=905988&view=diff
==============================================================================
--- 
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ArrayUtilsTest.java
 (original)
+++ 
commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/ArrayUtilsTest.java
 Wed Feb  3 10:52:37 2010
@@ -270,6 +270,242 @@
 
     //-----------------------------------------------------------------------
 
+    public void testNullToEmptyBoolean() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, 
ArrayUtils.nullToEmpty((boolean[]) null));
+        // Test valid array handling
+        boolean[] original = new boolean[] {true, false};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        boolean[] empty = new boolean[]{};
+        boolean[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyLong() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_LONG_ARRAY, 
ArrayUtils.nullToEmpty((long[]) null));
+        // Test valid array handling
+        long[] original = new long[] {1L, 2L};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        long[] empty = new long[]{};
+        long[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_LONG_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyInt() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_INT_ARRAY, 
ArrayUtils.nullToEmpty((int[]) null));
+        // Test valid array handling
+        int[] original = new int[] {1, 2};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        int[] empty = new int[]{};
+        int[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_INT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyShort() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_SHORT_ARRAY, 
ArrayUtils.nullToEmpty((short[]) null));
+        // Test valid array handling
+        short[] original = new short[] {1, 2};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        short[] empty = new short[]{};
+        short[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_SHORT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyChar() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, 
ArrayUtils.nullToEmpty((char[]) null));
+        // Test valid array handling
+        char[] original = new char[] {'a', 'b'};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        char[] empty = new char[]{};
+        char[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_CHAR_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyByte() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_BYTE_ARRAY, 
ArrayUtils.nullToEmpty((byte[]) null));
+        // Test valid array handling
+        byte[] original = new byte[] {0x0F, 0x0E};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        byte[] empty = new byte[]{};
+        byte[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_BYTE_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyDouble() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, 
ArrayUtils.nullToEmpty((double[]) null));
+        // Test valid array handling
+        double[] original = new double[] {1L, 2L};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        double[] empty = new double[]{};
+        double[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyFloat() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, 
ArrayUtils.nullToEmpty((float[]) null));
+        // Test valid array handling
+        float[] original = new float[] {2.6f, 3.8f};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        float[] empty = new float[]{};
+        float[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+
+    public void testNullToEmptyObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Object[]) null));
+        // Test valid array handling
+        Object[] original = new Object[] {Boolean.TRUE, Boolean.TRUE};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Object[] empty = new Object[]{};
+        Object[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+
+    public void testNullToEmptyString() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_STRING_ARRAY, 
ArrayUtils.nullToEmpty((String[]) null));
+        // Test valid array handling
+        String[] original = new String[] {"abc", "def"};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        String[] empty = new String[]{};
+        String[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_STRING_ARRAY, result);
+        assertTrue(empty != result);
+    }
+
+    public void testNullToEmptyBooleanObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Boolean[]) null));
+        // Test valid array handling
+        Boolean[] original = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Boolean[] empty = new Boolean[]{};
+        Boolean[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyLongObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Long[]) null));
+        // Test valid array handling
+        Long[] original = new Long[] {new Long(1L), new Long(2L)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Long[] empty = new Long[]{};
+        Long[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyIntObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Integer[]) null));
+        // Test valid array handling
+        Integer[] original = new Integer[] {new Integer(1), new Integer(2)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Integer[] empty = new Integer[]{};
+        Integer[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyShortObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Short[]) null));
+        // Test valid array handling
+        Short[] original = new Short[] {new Short((short)1), new 
Short((short)2)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Short[] empty = new Short[]{};
+        Short[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyCharObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Character[]) null));
+        // Test valid array handling
+        Character[] original = new Character[] {new Character('a'), new 
Character('b')};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Character[] empty = new Character[]{};
+        Character[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyByteObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Byte[]) null));
+        // Test valid array handling
+        Byte[] original = new Byte[] {new Byte((byte)0x0F), new 
Byte((byte)0x0E)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Byte[] empty = new Byte[]{};
+        Byte[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyDoubleObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Double[]) null));
+        // Test valid array handling
+        Double[] original = new Double[] {new Double(1D), new Double(2D)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Double[] empty = new Double[]{};
+        Double[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+    
+    public void testNullToEmptyFloatObject() {
+        // Test null handling
+        assertEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, 
ArrayUtils.nullToEmpty((Float[]) null));
+        // Test valid array handling
+        Float[] original = new Float[] {new Float(2.6f), new Float(3.8f)};
+        assertEquals(original, ArrayUtils.nullToEmpty(original));
+        // Test empty array handling
+        Float[] empty = new Float[]{};
+        Float[] result = ArrayUtils.nullToEmpty(empty);
+        assertEquals(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, result);
+        assertTrue(empty != result);
+    }
+
+    //-----------------------------------------------------------------------
+
     public void testSubarrayObject() {
         Object[] nullArray = null;
         Object[] objectArray = { "a", "b", "c", "d", "e", "f"};


Reply via email to