You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2016/05/12 17:49:50 UTC

[1/2] [lang] LANG-1178: ArrayUtils.removeAll(Object array, int... indices) should do the clone, not its callers (closes #116)

Repository: commons-lang
Updated Branches:
  refs/heads/master 28f7862ab -> f02261849


LANG-1178: ArrayUtils.removeAll(Object array, int... indices) should do the clone, not its callers (closes #116)


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/5eae0a64
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/5eae0a64
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/5eae0a64

Branch: refs/heads/master
Commit: 5eae0a646469672d1cc5385bd7bd6aedc4aed19b
Parents: 28f7862
Author: Henri Yandell <hy...@amazon.com>
Authored: Thu Nov 19 21:58:47 2015 +0000
Committer: pascalschumacher <pa...@gmx.net>
Committed: Thu May 12 19:43:31 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/lang3/ArrayUtils.java    | 37 +++++++++++---------
 1 file changed, 20 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/5eae0a64/src/main/java/org/apache/commons/lang3/ArrayUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index efd9c4a..6fe185d 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -6536,7 +6536,7 @@ public class ArrayUtils {
      */
     @SuppressWarnings("unchecked") // removeAll() always creates an array of the same type as its input
     public static <T> T[] removeAll(final T[] array, final int... indices) {
-        return (T[]) removeAll((Object) array, clone(indices));
+        return (T[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -6628,7 +6628,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static byte[] removeAll(final byte[] array, final int... indices) {
-        return (byte[]) removeAll((Object) array, clone(indices));
+        return (byte[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -6717,7 +6717,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static short[] removeAll(final short[] array, final int... indices) {
-        return (short[]) removeAll((Object) array, clone(indices));
+        return (short[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -6806,7 +6806,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static int[] removeAll(final int[] array, final int... indices) {
-        return (int[]) removeAll((Object) array, clone(indices));
+        return (int[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -6895,7 +6895,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static char[] removeAll(final char[] array, final int... indices) {
-        return (char[]) removeAll((Object) array, clone(indices));
+        return (char[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -6984,7 +6984,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static long[] removeAll(final long[] array, final int... indices) {
-        return (long[]) removeAll((Object) array, clone(indices));
+        return (long[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -7073,7 +7073,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static float[] removeAll(final float[] array, final int... indices) {
-        return (float[]) removeAll((Object) array, clone(indices));
+        return (float[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -7162,7 +7162,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static double[] removeAll(final double[] array, final int... indices) {
-        return (double[]) removeAll((Object) array, clone(indices));
+        return (double[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -7247,7 +7247,7 @@ public class ArrayUtils {
      * @since 3.0.1
      */
     public static boolean[] removeAll(final boolean[] array, final int... indices) {
-        return (boolean[]) removeAll((Object) array, clone(indices));
+        return (boolean[]) removeAll((Object) array, indices);
     }
 
     /**
@@ -7309,7 +7309,7 @@ public class ArrayUtils {
     /**
      * Removes multiple array elements specified by index.
      * @param array source
-     * @param indices to remove, WILL BE SORTED--so only clones of user-owned arrays!
+     * @param indices to remove
      * @return new array of same type minus elements specified by unique values of {@code indices}
      * @since 3.0.1
      */
@@ -7317,14 +7317,15 @@ public class ArrayUtils {
     static Object removeAll(final Object array, final int... indices) {
         final int length = getLength(array);
         int diff = 0; // number of distinct indexes, i.e. number of entries that will be removed
+        int[] clonedIndices = clone(indices);
+        Arrays.sort(clonedIndices);
 
-        if (isNotEmpty(indices)) {
-            Arrays.sort(indices);
-
-            int i = indices.length;
+        // identify length of result array
+        if (isNotEmpty(clonedIndices)) {
+            int i = clonedIndices.length;
             int prevIndex = length;
             while (--i >= 0) {
-                final int index = indices[i];
+                final int index = clonedIndices[i];
                 if (index < 0 || index >= length) {
                     throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
                 }
@@ -7335,12 +7336,14 @@ public class ArrayUtils {
                 prevIndex = index;
             }
         }
+
+        // create result array
         final Object result = Array.newInstance(array.getClass().getComponentType(), length - diff);
         if (diff < length) {
             int end = length; // index just after last copy
             int dest = length - diff; // number of entries so far not copied
-            for (int i = indices.length - 1; i >= 0; i--) {
-                final int index = indices[i];
+            for (int i = clonedIndices.length - 1; i >= 0; i--) {
+                final int index = clonedIndices[i];
                 if (end - index > 1) { // same as (cp > 0)
                     final int cp = end - index - 1;
                     dest -= cp;


[2/2] [lang] LANG-1178: add changes.xml entry

Posted by pa...@apache.org.
LANG-1178: add changes.xml entry


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/f0226184
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/f0226184
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/f0226184

Branch: refs/heads/master
Commit: f02261849ec44fccb94b15b1b0e8afc8fff6edd9
Parents: 5eae0a6
Author: pascalschumacher <pa...@gmx.net>
Authored: Thu May 12 19:48:38 2016 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Thu May 12 19:48:38 2016 +0200

----------------------------------------------------------------------
 src/changes/changes.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f0226184/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 779375c..fc8162a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
+    <action issue="LANG-1178" type="fix" dev="pschumacher" due-to="Henri Yandell">ArrayUtils.removeAll(Object array, int... indices) should do the clone, not its callers</action>
     <action issue="LANG-1151" type="update" dev="pschumacher" due-to="Juan Pablo Santos Rodr�guez">Performance improvements for NumberUtils.isParsable</action>
     <action issue="LANG-1227" type="fix" dev="pschumacher" due-to="kaching88">StringUtils.stripAccents should remove accents from "\u0141" and "\u0142".</action>
     <action issue="LANG-1227" type="new" dev="ggregory" due-to="Gary Gregory">Add XMLCharacter class.</action>