commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang ArrayUtilsTest.java
Date Sat, 16 Nov 2002 12:56:44 GMT
scolebourne    2002/11/16 04:56:44

  Modified:    lang/src/java/org/apache/commons/lang ArrayUtils.java
               lang/src/test/org/apache/commons/lang ArrayUtilsTest.java
  Log:
  Add to ArrayUtils and test it
  
  Revision  Changes    Path
  1.5       +96 -11    jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java
  
  Index: ArrayUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ArrayUtils.java	16 Nov 2002 10:41:03 -0000	1.4
  +++ ArrayUtils.java	16 Nov 2002 12:56:43 -0000	1.5
  @@ -56,6 +56,8 @@
   import java.util.HashMap;
   import java.util.Map;
   
  +import org.apache.commons.lang.builder.EqualsBuilder;
  +import org.apache.commons.lang.builder.HashCodeBuilder;
   import org.apache.commons.lang.builder.ToStringBuilder;
   import org.apache.commons.lang.builder.ToStringStyle;
   /**
  @@ -100,6 +102,7 @@
       public ArrayUtils() {
       }
   
  +    // Basic methods handling multi-dimensional arrays
       //--------------------------------------------------------------------------
       
       /**
  @@ -110,7 +113,7 @@
        *
        * <p>The format is that of Java source code, for example {a,b}.</p>
        * 
  -     * @param array  the array to get a toString for, may not be <code>null</code>
  +     * @param array  the array to get a toString for, may be <code>null</code>
        * @return a String representation of the array, '{}' if <code>null</code>
passed in
        */
       public static String toString(Object array) {
  @@ -137,6 +140,34 @@
       }
       
       /**
  +     * <p>Get a hashCode for an array handling multi-dimensional arrays correctly.</p>
  +     * 
  +     * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
  +     * 
  +     * @param array  the array to get a hashCode for, may be <code>null</code>
  +     * @return a hashCode for the array
  +     */
  +    public static int hashCode(Object array) {
  +        return new HashCodeBuilder().append(array).toHashCode();
  +    }
  +    
  +    /**
  +     * <p>Compares two arrays, using equals(), handling multi-dimensional arrays
  +     * correctly.</p>
  +     * 
  +     * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
  +     * 
  +     * @param array1  the array to get a hashCode for, may be <code>null</code>
  +     * @param array2  the array to get a hashCode for, may be <code>null</code>
  +     * @return <code>true</code> if the arrays are equal
  +     */
  +    public static boolean isEquals(Object array1, Object array2) {
  +        return new EqualsBuilder().append(array1, array2).isEquals();
  +    }
  +    
  +    //--------------------------------------------------------------------------
  +    
  +    /**
        * <p>Converts the given array into a {@link Map}. Each element of the array
        * must be either a {@link Map.Entry} or an Array, containing at least two
        * elements, where the first element is used as key and the second as
  @@ -298,9 +329,10 @@
        * <p>Shallow clones an array returning a typecast result and handling
        * <code>null</code>.</p>
        *
  -     * <p>The objecs in the array are not cloned.</p>
  +     * <p>The objecs in the array are not cloned, thus there is no special
  +     * handling for multi-dimensional arrays.</p>
        * 
  -     * @param array  the array to shallow clone, may not be <code>null</code>
  +     * @param array  the array to shallow clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -314,8 +346,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -329,8 +363,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -344,8 +380,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -359,8 +397,27 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
  +     * @return the cloned array, or <code>null</code> if <code>null</code>
  +     *  passed in
  +     */
  +    public static char[] clone(char[] array) {
  +        if (array == null) {
  +            return null;
  +        }
  +        return (char[]) array.clone();
  +    }
  +    
  +    /**
  +     * <p>Clones an array returning a typecast result and handling
  +     * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
  +     * 
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -374,8 +431,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -389,8 +448,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -404,8 +465,10 @@
       /**
        * <p>Clones an array returning a typecast result and handling
        * <code>null</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
        * 
  -     * @param array  the array to clone, may not be <code>null</code>
  +     * @param array  the array to clone, may be <code>null</code>
        * @return the cloned array, or <code>null</code> if <code>null</code>
        *  passed in
        */
  @@ -509,6 +572,26 @@
        * @return <code>true</code> if length of arrays matches, treating
        *  <code>null</code> as an empty array
        */
  +    public static boolean isSameLength(char[] array1, char[] array2) {
  +        if ((array1 == null && array2 != null && array2.length > 0)
||
  +            (array2 == null && array1 != null && array1.length > 0)
||
  +            (array1 != null && array2 != null && array1.length != array2.length))
{
  +                return false;
  +        }
  +        return true;
  +    }
  +    
  +    /**
  +     * <p>Checks whether two arrays are the same length, treating
  +     * <code>null</code> arrays as length <code>0</code>.</p>
  +     *
  +     * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
  +     * 
  +     * @param array1 the first array, may be <code>null</code>
  +     * @param array2 the second array, may be <code>null</code>
  +     * @return <code>true</code> if length of arrays matches, treating
  +     *  <code>null</code> as an empty array
  +     */
       public static boolean isSameLength(byte[] array1, byte[] array2) {
           if ((array1 == null && array2 != null && array2.length > 0)
||
               (array2 == null && array1 != null && array1.length > 0)
||
  @@ -581,6 +664,8 @@
       /**
        * <p>Checks whether two arrays are the same type taking into account
        * multi-dimensional arrays.</p>
  +     * 
  +     * <p>Primitive arrays may be compared using this method too.</p>
        * 
        * @param array1 the first array, must not be <code>null</code>
        * @param array2 the second array, must not be <code>null</code>
  
  
  
  1.2       +384 -16   jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsTest.java
  
  Index: ArrayUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArrayUtilsTest.java	13 Oct 2002 22:42:59 -0000	1.1
  +++ ArrayUtilsTest.java	16 Nov 2002 12:56:44 -0000	1.2
  @@ -54,6 +54,7 @@
    * <http://www.apache.org/>.
    */
   
  +import java.util.Arrays;
   import java.util.Map;
   
   import junit.framework.Test;
  @@ -92,7 +93,47 @@
       }
   
       //-----------------------------------------------------------------------
  +    public void testToString() {
  +        assertEquals("{}", ArrayUtils.toString(null));
  +        assertEquals("{}", ArrayUtils.toString(new Object[0]));
  +        assertEquals("{}", ArrayUtils.toString(new String[0]));
  +        assertEquals("{<null>}", ArrayUtils.toString(new String[] {null}));
  +        assertEquals("{pink,blue}", ArrayUtils.toString(new String[] {"pink","blue"}));
  +        
  +        assertEquals("<empty>", ArrayUtils.toString(null, "<empty>"));
  +        assertEquals("{}", ArrayUtils.toString(new Object[0], "<empty>"));
  +        assertEquals("{}", ArrayUtils.toString(new String[0], "<empty>"));
  +        assertEquals("{<null>}", ArrayUtils.toString(new String[] {null}, "<empty>"));
  +        assertEquals("{pink,blue}", ArrayUtils.toString(new String[] {"pink","blue"}, "<empty>"));
  +    }
   
  +    //-----------------------------------------------------------------------
  +    public void testHashCode() {
  +        long[][] array1 = new long[][] {{2,5}, {4,5}};
  +        long[][] array2 = new long[][] {{2,5}, {4,6}};
  +        assertEquals(true, ArrayUtils.hashCode(array1) == ArrayUtils.hashCode(array1));
  +        assertEquals(false, ArrayUtils.hashCode(array1) == ArrayUtils.hashCode(array2));
  +        
  +        Object[] array3 = new Object[] {new String(new char[] {'A', 'B'})};
  +        Object[] array4 = new Object[] {"AB"};
  +        assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array3));
  +        assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array4));
  +    }
  +    
  +    //-----------------------------------------------------------------------
  +    public void testIsEquals() {
  +        long[][] array1 = new long[][] {{2,5}, {4,5}};
  +        long[][] array2 = new long[][] {{2,5}, {4,6}};
  +        assertEquals(true, ArrayUtils.isEquals(array1, array1));
  +        assertEquals(false, ArrayUtils.isEquals(array1, array2));
  +        
  +        Object[] array3 = new Object[] {new String(new char[] {'A', 'B'})};
  +        Object[] array4 = new Object[] {"AB"};
  +        assertEquals(true, ArrayUtils.isEquals(array3, array3));
  +        assertEquals(true, ArrayUtils.isEquals(array3, array4));
  +    }
  +    
  +    //-----------------------------------------------------------------------
       public void testToMap() {
           Map map = ArrayUtils.toMap(new String[][] {{"foo", "bar"}, {"hello", "world"}});
           
  @@ -102,30 +143,19 @@
           try {
               ArrayUtils.toMap(null);
               fail("exception expected");
  -        } catch (IllegalArgumentException e) {
  -            // expected.
  -        }
  -        
  +        } catch (IllegalArgumentException ex) {}
           try {
               ArrayUtils.toMap(new String[][] {{"foo", "bar"}, {"short"}});
               fail("exception expected");
  -        } catch (IllegalArgumentException e) {
  -            // expected.
  -        }
  -        
  +        } catch (IllegalArgumentException ex) {}
           try {
               ArrayUtils.toMap(new Object[] {new Object[] {"foo", "bar"}, "illegal type"});
               fail("exception expected");
  -        } catch (IllegalArgumentException e) {
  -            // expected.
  -        }
  -        
  +        } catch (IllegalArgumentException ex) {}
           try {
               ArrayUtils.toMap(new Object[] {new Object[] {"foo", "bar"}, null});
               fail("exception expected");
  -        } catch (IllegalArgumentException e) {
  -            // expected.
  -        }
  +        } catch (IllegalArgumentException ex) {}
           
           map = ArrayUtils.toMap(new Object[] {new Map.Entry() {
               public Object getKey() {
  @@ -147,6 +177,344 @@
           assertEquals("bar", map.get("foo"));
       }
   
  +    //-----------------------------------------------------------------------
  +    public void testClone() {
  +        assertEquals(null, ArrayUtils.clone((Object[]) null));
  +        Object[] original1 = new Object[0];
  +        Object[] cloned1 = ArrayUtils.clone(original1);
  +        assertTrue(Arrays.equals(original1, cloned1));
  +        assertTrue(original1 != cloned1);
  +        
  +        StringBuffer buf = new StringBuffer("pick");
  +        original1 = new Object[] {buf, "a", new String[] {"stick"}};
  +        cloned1 = ArrayUtils.clone(original1);
  +        assertTrue(Arrays.equals(original1, cloned1));
  +        assertTrue(original1 != cloned1);
  +        assertSame(original1[0], cloned1[0]);
  +        assertSame(original1[1], cloned1[1]);
  +        assertSame(original1[2], cloned1[2]);
  +    }
  +
  +    public void testCloneBoolean() {
  +        boolean[] original = new boolean[] {true, false};
  +        boolean[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneLong() {
  +        long[] original = new long[] {0L, 1L};
  +        long[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneInt() {
  +        int[] original = new int[] {5, 8};
  +        int[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneShort() {
  +        short[] original = new short[] {1, 4};
  +        short[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneChar() {
  +        char[] original = new char[] {'a', '4'};
  +        char[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneByte() {
  +        byte[] original = new byte[] {1, 6};
  +        byte[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneDouble() {
  +        double[] original = new double[] {2.4d, 5.7d};
  +        double[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
  +    
  +    public void testCloneFloat() {
  +        float[] original = new float[] {2.6f, 6.4f};
  +        float[] cloned = ArrayUtils.clone(original);
  +        assertTrue(Arrays.equals(original, cloned));
  +        assertTrue(original != cloned);
  +    }
   
  +    //-----------------------------------------------------------------------
  +    public void testSameLength() {
  +        Object[] nullArray = null;
  +        Object[] emptyArray = new Object[0];
  +        Object[] oneArray = new Object[] {"pick"};
  +        Object[] twoArray = new Object[] {"pick", "stick"};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
   
  +    public void testSameLengthBoolean() {
  +        boolean[] nullArray = null;
  +        boolean[] emptyArray = new boolean[0];
  +        boolean[] oneArray = new boolean[] {true};
  +        boolean[] twoArray = new boolean[] {true, false};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthLong() {
  +        long[] nullArray = null;
  +        long[] emptyArray = new long[0];
  +        long[] oneArray = new long[] {0L};
  +        long[] twoArray = new long[] {0L, 76L};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthInt() {
  +        int[] nullArray = null;
  +        int[] emptyArray = new int[0];
  +        int[] oneArray = new int[] {4};
  +        int[] twoArray = new int[] {5, 7};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthShort() {
  +        short[] nullArray = null;
  +        short[] emptyArray = new short[0];
  +        short[] oneArray = new short[] {4};
  +        short[] twoArray = new short[] {6, 8};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthChar() {
  +        char[] nullArray = null;
  +        char[] emptyArray = new char[0];
  +        char[] oneArray = new char[] {'f'};
  +        char[] twoArray = new char[] {'d', 't'};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthByte() {
  +        byte[] nullArray = null;
  +        byte[] emptyArray = new byte[0];
  +        byte[] oneArray = new byte[] {3};
  +        byte[] twoArray = new byte[] {4, 6};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthDouble() {
  +        double[] nullArray = null;
  +        double[] emptyArray = new double[0];
  +        double[] oneArray = new double[] {1.3d};
  +        double[] twoArray = new double[] {4.5d, 6.3d};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    public void testSameLengthFloat() {
  +        float[] nullArray = null;
  +        float[] emptyArray = new float[0];
  +        float[] oneArray = new float[] {2.5f};
  +        float[] twoArray = new float[] {6.4f, 5.8f};
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
  +        
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
  +        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
  +        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
  +        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
  +        
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
  +        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
  +        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
  +    }
  +    
  +    //-----------------------------------------------------------------------
  +    public void testSameType() {
  +        try {
  +            ArrayUtils.isSameType(null, null);
  +            fail();
  +        } catch (IllegalArgumentException ex) {}
  +        try {
  +            ArrayUtils.isSameType(null, new Object[0]);
  +            fail();
  +        } catch (IllegalArgumentException ex) {}
  +        try {
  +            ArrayUtils.isSameType(new Object[0], null);
  +            fail();
  +        } catch (IllegalArgumentException ex) {}
  +        
  +        assertEquals(true, ArrayUtils.isSameType(new Object[0], new Object[0]));
  +        assertEquals(false, ArrayUtils.isSameType(new String[0], new Object[0]));
  +        assertEquals(true, ArrayUtils.isSameType(new String[0][0], new String[0][0]));
  +        assertEquals(false, ArrayUtils.isSameType(new String[0], new String[0][0]));
  +        assertEquals(false, ArrayUtils.isSameType(new String[0][0], new String[0]));
  +    }
  +    
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message