[LANG-1529] Deprecate
org.apache.commons.lang3.ArrayUtils.removeAllOccurences(*) for org.apache.commons.lang3.ArrayUtils.removeAllOccurrences(*). Closes #492.
This commit is contained in:
parent
93701c9ad7
commit
055c20ab98
|
@ -109,6 +109,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
<action issue="LANG-1525" type="update" dev="ggregory" due-to="Edgar Asatryan, Bruno P. Kinoshita, Gary Gregory">Internally use Validate.notNull(foo, ...) instead of Validate.isTrue(foo != null, ...).</action>
|
||||
<action issue="LANG-1526" type="update" dev="ggregory" due-to="Dominik Schramm">Add 1 and 0 in toBooleanObject(final String str) #502.</action>
|
||||
<action issue="LANG-1527" type="update" dev="ggregory" due-to="Pengyu Nie">Remove an redundant argument check in NumberUtils #504.</action>
|
||||
<action issue="LANG-1529" type="update" dev="ggregory" due-to="Gary Gregory, BillCindy, Bruno P. Kinoshita">Deprecate org.apache.commons.lang3.ArrayUtils.removeAllOccurences(*) for org.apache.commons.lang3.ArrayUtils.removeAllOccurrences(*).</action>
|
||||
</release>
|
||||
|
||||
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11.">
|
||||
|
|
|
@ -5302,6 +5302,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(boolean[], boolean)}
|
||||
*/
|
||||
public static boolean[] removeAllOccurences(final boolean[] array, final boolean element) {
|
||||
return (boolean[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5321,6 +5322,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(byte[], byte)}
|
||||
*/
|
||||
public static byte[] removeAllOccurences(final byte[] array, final byte element) {
|
||||
return (byte[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5340,6 +5342,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(char[], char)}
|
||||
*/
|
||||
public static char[] removeAllOccurences(final char[] array, final char element) {
|
||||
return (char[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5359,6 +5362,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(double[], double)}
|
||||
*/
|
||||
public static double[] removeAllOccurences(final double[] array, final double element) {
|
||||
return (double[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5378,6 +5382,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(float[], float)}
|
||||
*/
|
||||
public static float[] removeAllOccurences(final float[] array, final float element) {
|
||||
return (float[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5397,6 +5402,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(int[], int)}
|
||||
*/
|
||||
public static int[] removeAllOccurences(final int[] array, final int element) {
|
||||
return (int[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5416,6 +5422,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(long[], long)}
|
||||
*/
|
||||
public static long[] removeAllOccurences(final long[] array, final long element) {
|
||||
return (long[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5435,6 +5442,7 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(short[], short)}
|
||||
*/
|
||||
public static short[] removeAllOccurences(final short[] array, final short element) {
|
||||
return (short[]) removeAll((Object) array, indexesOf(array, element));
|
||||
|
@ -5455,11 +5463,184 @@ public static int indexOf(final int[] array, final int valueToFind) {
|
|||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.5
|
||||
* @deprecated Use {@link #removeAllOccurrences(Object[], Object)}
|
||||
*/
|
||||
public static <T> T[] removeAllOccurences(final T[] array, final T element) {
|
||||
return (T[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified boolean array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static boolean[] removeAllOccurrences(final boolean[] array, final boolean element) {
|
||||
return (boolean[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified byte array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static byte[] removeAllOccurrences(final byte[] array, final byte element) {
|
||||
return (byte[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified char array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static char[] removeAllOccurrences(final char[] array, final char element) {
|
||||
return (char[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified double array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static double[] removeAllOccurrences(final double[] array, final double element) {
|
||||
return (double[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified float array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static float[] removeAllOccurrences(final float[] array, final float element) {
|
||||
return (float[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified int array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static int[] removeAllOccurrences(final int[] array, final int element) {
|
||||
return (int[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified long array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static long[] removeAllOccurrences(final long[] array, final long element) {
|
||||
return (long[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified short array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static short[] removeAllOccurrences(final short[] array, final short element) {
|
||||
return (short[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the occurrences of the specified element from the specified array.
|
||||
*
|
||||
* <p>
|
||||
* All subsequent elements are shifted to the left (subtracts one from their indices).
|
||||
* If the array doesn't contains such an element, no elements are removed from the array.
|
||||
* {@code null} will be returned if the input array is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @param <T> the type of object in the array
|
||||
* @param element the element to remove
|
||||
* @param array the input array
|
||||
*
|
||||
* @return A new array containing the existing elements except the occurrences of the specified element.
|
||||
* @since 3.10
|
||||
*/
|
||||
public static <T> T[] removeAllOccurrences(final T[] array, final T element) {
|
||||
return (T[]) removeAll((Object) array, indexesOf(array, element));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Removes the first occurrence of the specified element from the
|
||||
* specified array. All subsequent elements are shifted to the left
|
||||
|
|
|
@ -30,39 +30,381 @@ import org.junit.jupiter.api.Test;
|
|||
public class ArrayUtilsRemoveTest {
|
||||
|
||||
@Test
|
||||
public void testRemoveObjectArray() {
|
||||
Object[] array;
|
||||
array = ArrayUtils.remove(new Object[] {"a"}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b"}, 0);
|
||||
assertArrayEquals(new Object[]{"b"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b"}, 1);
|
||||
assertArrayEquals(new Object[]{"a"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b", "c"}, 1);
|
||||
assertArrayEquals(new Object[]{"a", "c"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
|
||||
public void testRemoveAllBooleanOccurences() {
|
||||
boolean[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { true, true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{false, false}, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{true, true, true}, ArrayUtils.removeAllOccurences(a, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNumberArray() {
|
||||
final Number[] inarray = {Integer.valueOf(1), Long.valueOf(2), Byte.valueOf((byte) 3)};
|
||||
assertEquals(3, inarray.length);
|
||||
Number[] outarray;
|
||||
outarray = ArrayUtils.remove(inarray, 1);
|
||||
assertEquals(2, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
outarray = ArrayUtils.remove(outarray, 1);
|
||||
assertEquals(1, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
outarray = ArrayUtils.remove(outarray, 0);
|
||||
assertEquals(0, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
public void testRemoveAllBooleanOccurrences() {
|
||||
boolean[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, true));
|
||||
|
||||
a = new boolean[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
|
||||
|
||||
a = new boolean[] { true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
|
||||
|
||||
a = new boolean[] { true, true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{false, false}, ArrayUtils.removeAllOccurrences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{true, true, true}, ArrayUtils.removeAllOccurrences(a, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllByteOccurences() {
|
||||
byte[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 3}, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (byte) 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllByteOccurrences() {
|
||||
byte[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, (byte) 2));
|
||||
|
||||
a = new byte[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 3}, ArrayUtils.removeAllOccurrences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, (byte) 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllCharOccurences() {
|
||||
char[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '2', '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '3'}, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '2', '2', '3', '2'}, ArrayUtils.removeAllOccurences(a, '4'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllCharOccurrences() {
|
||||
char[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, '2'));
|
||||
|
||||
a = new char[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
|
||||
|
||||
a = new char[] { '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
|
||||
|
||||
a = new char[] { '2', '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '3'}, ArrayUtils.removeAllOccurrences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '2', '2', '3', '2'}, ArrayUtils.removeAllOccurrences(a, '4'));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllDoubleOccurences() {
|
||||
double[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllDoubleOccurrences() {
|
||||
double[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new double[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new double[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new double[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFloatOccurences() {
|
||||
float[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFloatOccurrences() {
|
||||
float[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new float[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new float[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new float[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllIntOccurences() {
|
||||
int[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllIntOccurrences() {
|
||||
int[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new int[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new int[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new int[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllLongOccurences() {
|
||||
long[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllLongOccurrences() {
|
||||
long[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new long[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new long[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new long[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllObjectOccurences() {
|
||||
String[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "2", "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "3"}, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "2", "2", "3", "2"}, ArrayUtils.removeAllOccurences(a, "4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllObjectOccurrences() {
|
||||
String[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, "2"));
|
||||
|
||||
a = new String[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
|
||||
|
||||
a = new String[] { "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
|
||||
|
||||
a = new String[] { "2", "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "3"}, ArrayUtils.removeAllOccurrences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "2", "2", "3", "2"}, ArrayUtils.removeAllOccurrences(a, "4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllShortOccurences() {
|
||||
short[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 3}, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (short) 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllShortOccurrences() {
|
||||
short[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurrences(a, (short) 2));
|
||||
|
||||
a = new short[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 3}, ArrayUtils.removeAllOccurrences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, (short) 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,105 +487,6 @@ public class ArrayUtilsRemoveTest {
|
|||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((double[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveFloatArray() {
|
||||
float[] array;
|
||||
array = ArrayUtils.remove(new float[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2}, 0);
|
||||
assertArrayEquals(new float[]{2}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2}, 1);
|
||||
assertArrayEquals(new float[]{1}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new float[]{1, 1}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((float[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIntArray() {
|
||||
int[] array;
|
||||
array = ArrayUtils.remove(new int[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2}, 0);
|
||||
assertArrayEquals(new int[]{2}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2}, 1);
|
||||
assertArrayEquals(new int[]{1}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new int[]{1, 1}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((int[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveLongArray() {
|
||||
long[] array;
|
||||
array = ArrayUtils.remove(new long[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2}, 0);
|
||||
assertArrayEquals(new long[]{2}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2}, 1);
|
||||
assertArrayEquals(new long[]{1}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new long[]{1, 1}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((long[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveShortArray() {
|
||||
short[] array;
|
||||
array = ArrayUtils.remove(new short[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2}, 0);
|
||||
assertArrayEquals(new short[]{2}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2}, 1);
|
||||
assertArrayEquals(new short[]{1}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new short[]{1, 1}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((short[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveElementObjectArray() {
|
||||
Object[] array;
|
||||
array = ArrayUtils.removeElement(null, "a");
|
||||
assertNull(array);
|
||||
array = ArrayUtils.removeElement(ArrayUtils.EMPTY_OBJECT_ARRAY, "a");
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a"}, "a");
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a", "b"}, "a");
|
||||
assertArrayEquals(new Object[]{"b"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a", "b", "a"}, "a");
|
||||
assertArrayEquals(new Object[]{"b", "a"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveElementBooleanArray() {
|
||||
boolean[] array;
|
||||
|
@ -360,6 +603,7 @@ public class ArrayUtilsRemoveTest {
|
|||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("cast")
|
||||
public void testRemoveElementLongArray() {
|
||||
|
@ -380,6 +624,25 @@ public class ArrayUtilsRemoveTest {
|
|||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveElementObjectArray() {
|
||||
Object[] array;
|
||||
array = ArrayUtils.removeElement(null, "a");
|
||||
assertNull(array);
|
||||
array = ArrayUtils.removeElement(ArrayUtils.EMPTY_OBJECT_ARRAY, "a");
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a"}, "a");
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a", "b"}, "a");
|
||||
assertArrayEquals(new Object[]{"b"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.removeElement(new Object[] {"a", "b", "a"}, "a");
|
||||
assertArrayEquals(new Object[]{"b", "a"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveElementShortArray() {
|
||||
short[] array;
|
||||
|
@ -399,193 +662,119 @@ public class ArrayUtilsRemoveTest {
|
|||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRemoveAllBooleanOccurences() {
|
||||
boolean[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { true, true };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{false, false}, ArrayUtils.removeAllOccurences(a, true));
|
||||
|
||||
a = new boolean[] { false, true, true, false, true };
|
||||
assertArrayEquals(new boolean[]{true, true, true}, ArrayUtils.removeAllOccurences(a, false));
|
||||
public void testRemoveFloatArray() {
|
||||
float[] array;
|
||||
array = ArrayUtils.remove(new float[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2}, 0);
|
||||
assertArrayEquals(new float[]{2}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2}, 1);
|
||||
assertArrayEquals(new float[]{1}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new float[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new float[]{1, 1}, array);
|
||||
assertEquals(Float.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((float[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllCharOccurences() {
|
||||
char[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '2', '2' };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '3'}, ArrayUtils.removeAllOccurences(a, '2'));
|
||||
|
||||
a = new char[] { '1', '2', '2', '3', '2' };
|
||||
assertArrayEquals(new char[]{'1', '2', '2', '3', '2'}, ArrayUtils.removeAllOccurences(a, '4'));
|
||||
public void testRemoveIntArray() {
|
||||
int[] array;
|
||||
array = ArrayUtils.remove(new int[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2}, 0);
|
||||
assertArrayEquals(new int[]{2}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2}, 1);
|
||||
assertArrayEquals(new int[]{1}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new int[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new int[]{1, 1}, array);
|
||||
assertEquals(Integer.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((int[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllByteOccurences() {
|
||||
byte[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 3}, ArrayUtils.removeAllOccurences(a, (byte) 2));
|
||||
|
||||
a = new byte[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new byte[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (byte) 4));
|
||||
public void testRemoveLongArray() {
|
||||
long[] array;
|
||||
array = ArrayUtils.remove(new long[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2}, 0);
|
||||
assertArrayEquals(new long[]{2}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2}, 1);
|
||||
assertArrayEquals(new long[]{1}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new long[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new long[]{1, 1}, array);
|
||||
assertEquals(Long.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((long[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllShortOccurences() {
|
||||
short[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 3}, ArrayUtils.removeAllOccurences(a, (short) 2));
|
||||
|
||||
a = new short[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new short[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (short) 4));
|
||||
public void testRemoveNumberArray() {
|
||||
final Number[] inarray = {Integer.valueOf(1), Long.valueOf(2), Byte.valueOf((byte) 3)};
|
||||
assertEquals(3, inarray.length);
|
||||
Number[] outarray;
|
||||
outarray = ArrayUtils.remove(inarray, 1);
|
||||
assertEquals(2, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
outarray = ArrayUtils.remove(outarray, 1);
|
||||
assertEquals(1, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
outarray = ArrayUtils.remove(outarray, 0);
|
||||
assertEquals(0, outarray.length);
|
||||
assertEquals(Number.class, outarray.getClass().getComponentType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllIntOccurences() {
|
||||
int[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new int[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new int[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
public void testRemoveObjectArray() {
|
||||
Object[] array;
|
||||
array = ArrayUtils.remove(new Object[] {"a"}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b"}, 0);
|
||||
assertArrayEquals(new Object[]{"b"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b"}, 1);
|
||||
assertArrayEquals(new Object[]{"a"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new Object[] {"a", "b", "c"}, 1);
|
||||
assertArrayEquals(new Object[]{"a", "c"}, array);
|
||||
assertEquals(Object.class, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllLongOccurences() {
|
||||
long[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new long[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new long[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllFloatOccurences() {
|
||||
float[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new float[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new float[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllDoubleOccurences() {
|
||||
double[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 2, 2 };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
|
||||
|
||||
a = new double[] { 1, 2, 2, 3, 2 };
|
||||
assertArrayEquals(new double[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveAllObjectOccurences() {
|
||||
String[] a = null;
|
||||
assertNull(ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[0];
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "2", "2" };
|
||||
assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "3"}, ArrayUtils.removeAllOccurences(a, "2"));
|
||||
|
||||
a = new String[] { "1", "2", "2", "3", "2" };
|
||||
assertArrayEquals(new String[]{"1", "2", "2", "3", "2"}, ArrayUtils.removeAllOccurences(a, "4"));
|
||||
public void testRemoveShortArray() {
|
||||
short[] array;
|
||||
array = ArrayUtils.remove(new short[] {1}, 0);
|
||||
assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2}, 0);
|
||||
assertArrayEquals(new short[]{2}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2}, 1);
|
||||
assertArrayEquals(new short[]{1}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
array = ArrayUtils.remove(new short[] {1, 2, 1}, 1);
|
||||
assertArrayEquals(new short[]{1, 1}, array);
|
||||
assertEquals(Short.TYPE, array.getClass().getComponentType());
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, -1));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, 2));
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((short[]) null, 0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5070,7 +5070,7 @@ public class ArrayUtilsTest {
|
|||
|
||||
ArrayUtils.shuffle(array1, new Random(SEED));
|
||||
assertFalse(Arrays.equals(array1, array2));
|
||||
assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
|
||||
assertEquals(5, ArrayUtils.removeAllOccurrences(array1, true).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue