You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/29 14:35:57 UTC
[commons-lang] branch master updated: [LANG-1177] Added indexesOf
methods and simplified removeAllOccurences (#471)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new 55a2a03 [LANG-1177] Added indexesOf methods and simplified removeAllOccurences (#471)
55a2a03 is described below
commit 55a2a03aa30836c814b9c2d50d5081a52f01d83c
Author: Liel Fridman <li...@gmail.com>
AuthorDate: Tue Oct 29 16:35:36 2019 +0200
[LANG-1177] Added indexesOf methods and simplified removeAllOccurences (#471)
* [LANG-1177] Added indexesOf methods and simplified removeAllOccurences in ArrayUtils
* [LANG-1177] Fixed style error
* [LANG-1177] Added @since tags for newly provided methods
* changing BitSet vars name to bitSet and inlining the 'foundBits'
* Fixed Javadoc in indexesOf
* Fixed trailing spaces
* Fixing a trailing space
---
.../java/org/apache/commons/lang3/ArrayUtils.java | 665 +++++++++++++++++----
.../org/apache/commons/lang3/ArrayUtilsTest.java | 472 +++++++++++++++
2 files changed, 1011 insertions(+), 126 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 45bfc4f..7569bf7 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -3255,6 +3255,59 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given object in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param objectToFind the object to find, may be {@code null}
+ * @return a BitSet of all the indices of the object within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final Object[] array, final Object objectToFind) {
+ return indexesOf(array, objectToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given object in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param objectToFind the object to find, may be {@code null}
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the object within the array starting at the index,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final Object[] array, final Object objectToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, objectToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+
+
+ /**
* <p>Finds the last index of the given object within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3366,6 +3419,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final long[] array, final long valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final long[] array, final long valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3469,6 +3573,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final int[] array, final int valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final int[] array, final int valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3572,6 +3727,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final short[] array, final short valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final short[] array, final short valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3677,6 +3883,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final char[] array, final char valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final char[] array, final char valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3783,6 +4040,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final byte[] array, final byte valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final byte[] array, final byte valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -3937,6 +4245,121 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final double[] array, final double valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value within a given tolerance in the array.
+ *
+ * <p>
+ * This method will return all the indices of the value which fall between the region
+ * defined by valueToFind - tolerance and valueToFind + tolerance, each time between the nearest integers.
+ * </p>
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param tolerance tolerance of the search
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final double[] array, final double valueToFind, final double tolerance) {
+ return indexesOf(array, valueToFind, 0, tolerance);
+ }
+
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>
+ * This method will return the indices of the values which fall between the region
+ * defined by valueToFind - tolerance and valueToFind + tolerance, between the nearest integers.
+ * </p>
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @param tolerance tolerance of the search
+ * @return a BitSet of the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex, tolerance);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -4110,6 +4533,57 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final float[] array, final float valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return empty BitSet.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final float[] array, final float valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.
@@ -4214,6 +4688,58 @@ public class ArrayUtils {
}
/**
+ * Finds the indices of the given value in the array.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @return a BitSet of all the the indices of the value within the array,
+ * an empty BitSet if not found or {@code null} array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final boolean[] array, final boolean valueToFind) {
+ return indexesOf(array, valueToFind, 0);
+ }
+
+ /**
+ * Finds the indices of the given value in the array starting at the given index.
+ *
+ * <p>This method returns an empty BitSet for a {@code null} input array.</p>
+ *
+ * <p>A negative startIndex is treated as zero. A startIndex larger than the array
+ * length will return an empty BitSet ({@code -1}).</p>
+ *
+ * @param array the array to search through for the object, may be {@code null}
+ * @param valueToFind the value to find
+ * @param startIndex the index to start searching at
+ * @return a BitSet of all the indices of the value within the array,
+ * an empty BitSet if not found or {@code null}
+ * array input
+ * @since 3.10
+ */
+ public static BitSet indexesOf(final boolean[] array, final boolean valueToFind, int startIndex) {
+ BitSet bitSet = new BitSet();
+
+ if (array == null) {
+ return bitSet;
+ }
+
+ while (startIndex < array.length) {
+ startIndex = indexOf(array, valueToFind, startIndex);
+
+ if (startIndex == INDEX_NOT_FOUND) {
+ break;
+ }
+
+ bitSet.set(startIndex);
+ ++startIndex;
+ }
+
+ return bitSet;
+ }
+
+ /**
* <p>Finds the last index of the given value within the array.
*
* <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) if
@@ -7720,6 +8246,10 @@ public class ArrayUtils {
*/
// package protected for access by unit tests
static Object removeAll(final Object array, final BitSet indices) {
+ if (array == null) {
+ return null;
+ }
+
final int srcLength = getLength(array);
// No need to check maxIndex here, because method only currently called from removeElements()
// which guarantee to generate on;y valid bit entries.
@@ -8010,20 +8540,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static boolean[] removeAllOccurences(final boolean[] array, final boolean element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (boolean[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8042,20 +8559,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static char[] removeAllOccurences(final char[] array, final char element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (char[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8074,20 +8578,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static byte[] removeAllOccurences(final byte[] array, final byte element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (byte[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8106,20 +8597,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static short[] removeAllOccurences(final short[] array, final short element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (short[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8138,20 +8616,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static int[] removeAllOccurences(final int[] array, final int element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (int[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8170,20 +8635,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static long[] removeAllOccurences(final long[] array, final long element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (long[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8202,20 +8654,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static float[] removeAllOccurences(final float[] array, final float element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (float[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8234,20 +8673,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static double[] removeAllOccurences(final double[] array, final double element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (double[]) removeAll((Object) array, indexesOf(array, element));
}
/**
@@ -8267,20 +8693,7 @@ public class ArrayUtils {
* @since 3.5
*/
public static <T> T[] removeAllOccurences(final T[] array, final T element) {
- int index = indexOf(array, element);
- if (index == INDEX_NOT_FOUND) {
- return clone(array);
- }
-
- final int[] indices = new int[array.length - index];
- indices[0] = index;
- int count = 1;
-
- while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) {
- indices[count++] = index;
- }
-
- return removeAll(array, Arrays.copyOf(indices, count));
+ return (T[]) removeAll((Object) array, indexesOf(array, element));
}
/**
diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
index 069466e..3eb76c5 100644
--- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
@@ -31,6 +31,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collections;
+import java.util.BitSet;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
@@ -3143,6 +3144,61 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOf() {
+ final Object[] array = new Object[]{"0", "1", "2", "3", null, "0"};
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf((Object[]) null, null));
+ assertEquals(emptySet, ArrayUtils.indexesOf(new Object[0], "0"));
+ testSet.set(5);
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "0"));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "2"));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "3"));
+ testSet.clear();
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, null));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, "notInArray"));
+ }
+
+ @Test
+ public void testIndexesOfWithStartIndex() {
+ final Object[] array = new Object[]{"0", "1", "2", "3", "2", "3", "1", null, "0"};
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(null, null, 2));
+ assertEquals(emptySet, ArrayUtils.indexesOf(new Object[0], "0", 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(null, "0", 2));
+ testSet.set(8);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "0", 8));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "0", 0));
+ testSet.clear();
+ testSet.set(6);
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "1", 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, "1", 9));
+ testSet.clear();
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "2", 3));
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "2", 0));
+ testSet.clear();
+ testSet.set(3);
+ testSet.set(5);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, "3", 0));
+ testSet.clear();
+ testSet.set(7);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, null, 0));
+
+ }
+
+
+ @Test
public void testLastIndexOf() {
final Object[] array = new Object[]{"0", "1", "2", "3", null, "0"};
assertEquals(-1, ArrayUtils.lastIndexOf(null, null));
@@ -3230,6 +3286,52 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOfLong() {
+ final long[] array = new long[]{0, 1, 2, 3};
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf((long[]) null, 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 4));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3));
+ }
+
+ @Test
+ public void testIndexesOfLongWithStartIndex() {
+ final long[] array = new long[]{0, 1, 2, 3, 2, 1, 0, 1};
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf((long[]) null, 0, 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 4, 0));
+ testSet.set(6);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 1));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ testSet.set(5);
+ testSet.set(7);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1, 0));
+ testSet.clear();
+ testSet.set(2);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 3, 8));
+ }
+
+ @Test
public void testLastIndexOfLong() {
long[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
@@ -3295,6 +3397,52 @@ public class ArrayUtilsTest {
}
@Test
+ public void textIndexesOfInt() {
+ int[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
+ array = new int[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99));
+ }
+
+ @Test
+ public void testIndexesOfIntWithStartIndex() {
+ int[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
+ array = new int[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, -1));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99, 0));
+ }
+
+ @Test
public void testLastIndexOfInt() {
int[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
@@ -3360,6 +3508,52 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOfShort() {
+ short[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 0));
+ array = new short[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 3));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 99));
+ }
+
+ @Test
+ public void testIndexesOfShortWithStartIndex() {
+ short[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 0, 2));
+ array = new short[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 0, 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 1, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 3, 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (short) 3, -1));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (short) 99, 0));
+ }
+
+ @Test
public void testLastIndexOfShort() {
short[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0));
@@ -3425,6 +3619,53 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOfChar() {
+ char[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 'a'));
+ array = new char[]{'a', 'b', 'c', 'd', 'a'};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'a'));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'b'));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'c'));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'd'));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 'e'));
+ }
+
+ @Test
+ public void testIndexesOfCharWithStartIndex() {
+ char[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 'a', 0));
+ array = new char[]{'a', 'b', 'c', 'd', 'a'};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'a', 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'a', 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'a', -1));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'b', 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'c', 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 'd', 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 'd', 5));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 'e', 0));
+ }
+
+ @Test
public void testLastIndexOfChar() {
char[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a'));
@@ -3490,6 +3731,52 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOfByte() {
+ byte[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 0));
+ array = new byte[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 3));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 99));
+ }
+
+ @Test
+ public void testIndexesOfByteWithStartIndex() {
+ byte[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 0, 2));
+ array = new byte[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 0, 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 1, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 3, 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (byte) 3, -1));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (byte) 99, 0));
+ }
+
+ @Test
public void testLastIndexOfByte() {
byte[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0));
@@ -3594,6 +3881,103 @@ public class ArrayUtilsTest {
@SuppressWarnings("cast")
@Test
+ public void testIndexesOfDouble() {
+ double[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
+ array = new double[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void testIndexesOfDoubleWithStartIndex() {
+ double[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
+ array = new double[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, -1));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99, 0));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void testIndexesOfDoubleTolerance() {
+ double[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, (double) 0));
+ array = new double[0];
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, (double) 0));
+ array = new double[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 0.3));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 4.15, 2.0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1.00001324, 0.0001));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void testIndexesOfDoubleWithStartIndexTolerance() {
+ double[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0));
+ array = new double[0];
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, (double) 0, 0, (double) 0));
+ array = new double[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 1, 0.3));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, (double) 0, 0, 0.3));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0, 0.35));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 2, 0.35));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, -1, 0.35));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 2, 3, 0.35));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 4.15, 0, 2.0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1.00001324, 0, 0.0001));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
public void testLastIndexOfDouble() {
double[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
@@ -3716,6 +4100,54 @@ public class ArrayUtilsTest {
@SuppressWarnings("cast")
@Test
+ public void testIndexesOfFloat() {
+ float[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0));
+ array = new float[]{0, 1, 2, 3, 0};
+ testSet.set(0);
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void testIndexesOfFloatWithStartIndex() {
+ float[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 0, 2));
+ array = new float[]{0, 1, 2, 3, 0};
+ testSet.set(4);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 2));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 0, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 1, 1));
+ testSet.clear();
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 2, 0));
+ testSet.clear();
+ testSet.set(3);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, 0));
+ assertEquals(testSet, ArrayUtils.indexesOf(array, 3, -1));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, 99, 0));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
public void testLastIndexOfFloat() {
float[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
@@ -3790,6 +4222,46 @@ public class ArrayUtilsTest {
}
@Test
+ public void testIndexesOfBoolean() {
+ boolean[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, true));
+ array = new boolean[0];
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, true));
+ array = new boolean[]{true, false, true};
+ testSet.set(0);
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, true));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, false));
+ array = new boolean[]{true, true};
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, false));
+ }
+
+ @Test
+ public void testIndexesOfBooleanWithStartIndex() {
+ boolean[] array = null;
+ BitSet emptySet = new BitSet();
+ BitSet testSet = new BitSet();
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, true, 0));
+ array = new boolean[0];
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, true, 0));
+ array = new boolean[]{true, false, true};
+ testSet.set(2);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, true, 1));
+ testSet.set(0);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, true, 0));
+ testSet.clear();
+ testSet.set(1);
+ assertEquals(testSet, ArrayUtils.indexesOf(array, false, 1));
+ array = new boolean[]{true, true};
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, false, 0));
+ assertEquals(emptySet, ArrayUtils.indexesOf(array, false, -1));
+ }
+
+ @Test
public void testLastIndexOfBoolean() {
boolean[] array = null;
assertEquals(-1, ArrayUtils.lastIndexOf(array, true));