commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1535078 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/ArrayUtils.java test/java/org/apache/commons/lang3/ArrayUtilsTest.java
Date Wed, 23 Oct 2013 17:23:08 GMT
Author: ggregory
Date: Wed Oct 23 17:23:07 2013
New Revision: 1535078

URL: http://svn.apache.org/r1535078
Log:
[LANG-926] Add ArrayUtils.reverse(array, from, to) methods.

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1535078&r1=1535077&r2=1535078&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml Wed Oct 23 17:23:07 2013
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.2" date="TBA" description="Next release">
+    <action issue="LANG-926" type="add" dev="ggregory">Add ArrayUtils.reverse(array,
from, to) methods.</action>
     <action issue="LANG-795" type="add" due-to="Aaron Digulla">StringUtils.toString(byte[],
String) deprecated in favour of a new StringUtils.toString(byte[], CharSet)</action>
     <action issue="LANG-902" type="fix" due-to="Andrzej Winnicki">RandomStringUtils.random
javadoc was incorrectly promising letters and numbers would, as opposed to may, appear</action>
     <action issue="LANG-921" type="fix" dev="britter">BooleanUtils.xor(boolean...)
produces wrong results</action>

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=1535078&r1=1535077&r2=1535078&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java Wed Oct
23 17:23:07 2013
@@ -1435,9 +1435,146 @@ public class ArrayUtils {
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        Object tmp;
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final long[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final int[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final short[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final char[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final byte[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final double[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final float[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>Reverses the order of the given array.</p>
+     *
+     * <p>This method does nothing for a {@code null} input array.</p>
+     *
+     * @param array  the array to reverse, may be {@code null}
+     */
+    public static void reverse(final boolean[] array) {
+        if (array == null) {
+            return;
+        }
+        reverse(array, 0, array.length);
+    }
+
+    /**
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
+     */
+    public static void reverse(final boolean[] array, int startIndexInclusive, int endIndexExclusive)
{
+        if (array == null) {
+            return;
+        }
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        boolean tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1448,19 +1585,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final long[] array) {
+    public static void reverse(final byte[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        long tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        byte tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1471,19 +1619,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final int[] array) {
+    public static void reverse(final char[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        int tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        char tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1494,19 +1653,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final short[] array) {
+    public static void reverse(final double[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        short tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        double tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1517,19 +1687,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final char[] array) {
+    public static void reverse(final float[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        char tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        float tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1540,19 +1721,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final byte[] array) {
+    public static void reverse(final int[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        byte tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        int tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1563,19 +1755,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final double[] array) {
+    public static void reverse(final long[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        double tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        long tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1586,19 +1789,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final float[] array) {
+    public static void reverse(final Object[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        float tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        Object tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];
@@ -1609,19 +1823,30 @@ public class ArrayUtils {
     }
 
     /**
-     * <p>Reverses the order of the given array.</p>
-     *
-     * <p>This method does nothing for a {@code null} input array.</p>
-     *
-     * @param array  the array to reverse, may be {@code null}
+     * <p>
+     * Reverses the order of the given array in the given range.
+     * </p>
+     * 
+     * <p>
+     * This method does nothing for a {@code null} input array.
+     * </p>
+     * 
+     * @param array
+     *            the array to reverse, may be {@code null}
+     * @param startIndexInclusive
+     *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue
(&gt;array.length) results in no
+     *            change.
+     * @param endIndexExclusive
+     *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt;
start index) results in no
+     *            change. Overvalue (&gt;array.length) is demoted to array length.
      */
-    public static void reverse(final boolean[] array) {
+    public static void reverse(final short[] array, int startIndexInclusive, int endIndexExclusive)
{
         if (array == null) {
             return;
         }
-        int i = 0;
-        int j = array.length - 1;
-        boolean tmp;
+        int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
+        int j = Math.min(array.length, endIndexExclusive) - 1;
+        short tmp;
         while (j > i) {
             tmp = array[j];
             array[j] = array[i];

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java?rev=1535078&r1=1535077&r2=1535078&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java Wed
Oct 23 17:23:07 2013
@@ -1806,6 +1806,295 @@ public class ArrayUtilsTest  {
         assertEquals(null, array);
     }
     
+    @Test
+    public void testReverseBooleanRange() {
+        boolean[] array = new boolean[] {false, false, true};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertTrue(array[0]);
+        assertFalse(array[1]);
+        assertFalse(array[2]);
+        // a range
+        array = new boolean[] {false, false, true};
+        ArrayUtils.reverse(array, 0, 2);
+        assertFalse(array[0]);
+        assertFalse(array[1]);
+        assertTrue(array[2]);
+        // a range with a negative start
+        array = new boolean[] {false, false, true};
+        ArrayUtils.reverse(array, -1, 3);
+        assertTrue(array[0]);
+        assertFalse(array[1]);
+        assertFalse(array[2]);
+        // a range with a large stop idnex
+        array = new boolean[] {false, false, true};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertTrue(array[0]);
+        assertFalse(array[1]);
+        assertFalse(array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseByteRange() {
+        byte[] array = new byte[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range
+        array = new byte[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0]);
+        assertEquals(1, array[1]);
+        assertEquals(3, array[2]);
+        // a range with a negative start
+        array = new byte[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range with a large stop idnex
+        array = new byte[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseCharRange() {
+        char[] array = new char[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range
+        array = new char[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0]);
+        assertEquals(1, array[1]);
+        assertEquals(3, array[2]);
+        // a range with a negative start
+        array = new char[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range with a large stop idnex
+        array = new char[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseDoubleRange() {
+        double[] array = new double[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // a range
+        array = new double[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0], 0);
+        assertEquals(1, array[1], 0);
+        assertEquals(3, array[2], 0);
+        // a range with a negative start
+        array = new double[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // a range with a large stop idnex
+        array = new double[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseFloatRange() {
+        float[] array = new float[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // a range
+        array = new float[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0], 0);
+        assertEquals(1, array[1], 0);
+        assertEquals(3, array[2], 0);
+        // a range with a negative start
+        array = new float[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // a range with a large stop idnex
+        array = new float[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0], 0);
+        assertEquals(2, array[1], 0);
+        assertEquals(1, array[2], 0);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseIntRange() {
+        int[] array = new int[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range
+        array = new int[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0]);
+        assertEquals(1, array[1]);
+        assertEquals(3, array[2]);
+        // a range with a negative start
+        array = new int[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range with a large stop idnex
+        array = new int[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseLongRange() {
+        long[] array = new long[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range
+        array = new long[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0]);
+        assertEquals(1, array[1]);
+        assertEquals(3, array[2]);
+        // a range with a negative start
+        array = new long[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range with a large stop idnex
+        array = new long[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseShortRange() {
+        short[] array = new short[] {1, 2, 3};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range
+        array = new short[] {1, 2, 3};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals(2, array[0]);
+        assertEquals(1, array[1]);
+        assertEquals(3, array[2]);
+        // a range with a negative start
+        array = new short[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // a range with a large stop idnex
+        array = new short[] {1, 2, 3};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals(3, array[0]);
+        assertEquals(2, array[1]);
+        assertEquals(1, array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+    @Test
+    public void testReverseObjectRange() {
+        String[] array = new String[] {"1", "2", "3"};
+        // The whole array
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals("3", array[0]);
+        assertEquals("2", array[1]);
+        assertEquals("1", array[2]);
+        // a range
+        array = new String[] {"1", "2", "3"};
+        ArrayUtils.reverse(array, 0, 2);
+        assertEquals("2", array[0]);
+        assertEquals("1", array[1]);
+        assertEquals("3", array[2]);
+        // a range with a negative start
+        array = new String[] {"1", "2", "3"};
+        ArrayUtils.reverse(array, -1, 3);
+        assertEquals("3", array[0]);
+        assertEquals("2", array[1]);
+        assertEquals("1", array[2]);
+        // a range with a large stop idnex
+        array = new String[] {"1", "2", "3"};
+        ArrayUtils.reverse(array, -1, array.length + 1000);
+        assertEquals("3", array[0]);
+        assertEquals("2", array[1]);
+        assertEquals("1", array[2]);
+        // null
+        array = null;
+        ArrayUtils.reverse(array, 0, 3);
+        assertEquals(null, array);
+    }
+    
+
     //-----------------------------------------------------------------------
     @Test
     public void testIndexOf() {



Mime
View raw message