View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.lang3;
19  
20  import static org.apache.commons.lang3.LangAssertions.assertIndexOutOfBoundsException;
21  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
22  import static org.junit.jupiter.api.Assertions.assertEquals;
23  import static org.junit.jupiter.api.Assertions.assertNotSame;
24  import static org.junit.jupiter.api.Assertions.assertNull;
25  
26  import org.junit.jupiter.api.Test;
27  
28  /**
29   * Tests {@link ArrayUtils} remove and removeElement methods.
30   */
31  class ArrayUtilsRemoveMultipleTest extends AbstractLangTest {
32  
33      private static final int[] NULL_INDICES = null;
34  
35      @Test
36      void testRemoveAllBooleanArray() {
37          boolean[] array;
38  
39          array = ArrayUtils.removeAll(new boolean[] { true }, 0);
40          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
41          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
42  
43          array = ArrayUtils.removeAll(new boolean[] { true, false }, 0);
44          assertArrayEquals(new boolean[]{false}, array);
45          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
46  
47          array = ArrayUtils.removeAll(new boolean[] { true, false }, 1);
48          assertArrayEquals(new boolean[]{true}, array);
49          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
50  
51          array = ArrayUtils.removeAll(new boolean[] { true, false, true }, 1);
52          assertArrayEquals(new boolean[]{true, true}, array);
53          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
54  
55          array = ArrayUtils.removeAll(new boolean[] { true, false }, 0, 1);
56          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
57          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
58  
59          array = ArrayUtils.removeAll(new boolean[] { true, false, false }, 0, 1);
60          assertArrayEquals(new boolean[]{false}, array);
61          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
62  
63          array = ArrayUtils.removeAll(new boolean[] { true, false, false }, 0, 2);
64          assertArrayEquals(new boolean[]{false}, array);
65          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
66  
67          array = ArrayUtils.removeAll(new boolean[] { true, false, false }, 1, 2);
68          assertArrayEquals(new boolean[]{true}, array);
69          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
70  
71          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true }, 0, 2, 4);
72          assertArrayEquals(new boolean[]{false, false}, array);
73          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
74  
75          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true }, 1, 3);
76          assertArrayEquals(new boolean[]{true, true, true}, array);
77          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
78  
79          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true }, 1, 3, 4);
80          assertArrayEquals(new boolean[]{true, true}, array);
81          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
82  
83          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true, false, true }, 0, 2, 4, 6);
84          assertArrayEquals(new boolean[]{false, false, false}, array);
85          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
86  
87          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true, false, true }, 1, 3, 5);
88          assertArrayEquals(new boolean[]{true, true, true, true}, array);
89          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
90  
91          array = ArrayUtils.removeAll(new boolean[] { true, false, true, false, true, false, true }, 0, 1, 2);
92          assertArrayEquals(new boolean[]{false, true, false, true}, array);
93          assertEquals(Boolean.TYPE, array.getClass().getComponentType());
94      }
95  
96      @Test
97      void testRemoveAllBooleanArrayNegativeIndex() {
98          assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new boolean[] { true, false }, -1));
99      }
100 
101     @Test
102     void testRemoveAllBooleanArrayOutOfBoundsIndex() {
103         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new boolean[] { true, false }, 2));
104     }
105 
106     @Test
107     void testRemoveAllBooleanArrayRemoveNone() {
108         final boolean[] array1 = { true, false };
109         final boolean[] array2 = ArrayUtils.removeAll(array1);
110         assertNotSame(array1, array2);
111         assertArrayEquals(array1, array2);
112         assertEquals(boolean.class, array2.getClass().getComponentType());
113     }
114 
115     @Test
116     void testRemoveAllByteArray() {
117         byte[] array;
118 
119         array = ArrayUtils.removeAll(new byte[] { 1 }, 0);
120         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
121         assertEquals(Byte.TYPE, array.getClass().getComponentType());
122 
123         array = ArrayUtils.removeAll(new byte[] { 1, 2 }, 0);
124         assertArrayEquals(new byte[]{2}, array);
125         assertEquals(Byte.TYPE, array.getClass().getComponentType());
126 
127         array = ArrayUtils.removeAll(new byte[] { 1, 2 }, 1);
128         assertArrayEquals(new byte[]{1}, array);
129         assertEquals(Byte.TYPE, array.getClass().getComponentType());
130 
131         array = ArrayUtils.removeAll(new byte[] { 1, 2, 1 }, 1);
132         assertArrayEquals(new byte[]{1, 1}, array);
133         assertEquals(Byte.TYPE, array.getClass().getComponentType());
134 
135         array = ArrayUtils.removeAll(new byte[] { 1, 2 }, 0, 1);
136         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
137         assertEquals(Byte.TYPE, array.getClass().getComponentType());
138 
139         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3 }, 0, 1);
140         assertArrayEquals(new byte[]{3}, array);
141         assertEquals(Byte.TYPE, array.getClass().getComponentType());
142 
143         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3 }, 1, 2);
144         assertArrayEquals(new byte[]{1}, array);
145         assertEquals(Byte.TYPE, array.getClass().getComponentType());
146 
147         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3 }, 0, 2);
148         assertArrayEquals(new byte[]{2}, array);
149         assertEquals(Byte.TYPE, array.getClass().getComponentType());
150 
151         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3, 4, 5 }, 1, 3);
152         assertArrayEquals(new byte[]{1, 3, 5}, array);
153         assertEquals(Byte.TYPE, array.getClass().getComponentType());
154 
155         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
156         assertArrayEquals(new byte[]{2, 4}, array);
157         assertEquals(Byte.TYPE, array.getClass().getComponentType());
158 
159         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
160         assertArrayEquals(new byte[]{1, 3, 5, 7}, array);
161         assertEquals(Byte.TYPE, array.getClass().getComponentType());
162 
163         array = ArrayUtils.removeAll(new byte[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
164         assertArrayEquals(new byte[]{2, 4, 6}, array);
165         assertEquals(Byte.TYPE, array.getClass().getComponentType());
166     }
167 
168     @Test
169     void testRemoveAllByteArrayNegativeIndex() {
170         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new byte[] { 1, 2 }, -1));
171     }
172 
173     @Test
174     void testRemoveAllByteArrayOutOfBoundsIndex() {
175         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new byte[] { 1, 2 }, 2));
176     }
177 
178     @Test
179     void testRemoveAllByteArrayRemoveNone() {
180         final byte[] array1 = { 1, 2 };
181         final byte[] array2 = ArrayUtils.removeAll(array1);
182         assertNotSame(array1, array2);
183         assertArrayEquals(array1, array2);
184         assertEquals(byte.class, array2.getClass().getComponentType());
185     }
186 
187     @Test
188     void testRemoveAllCharArray() {
189         char[] array;
190 
191         array = ArrayUtils.removeAll(new char[] { 'a' }, 0);
192         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
193         assertEquals(Character.TYPE, array.getClass().getComponentType());
194 
195         array = ArrayUtils.removeAll(new char[] { 'a', 'b' }, 0);
196         assertArrayEquals(new char[]{'b'}, array);
197         assertEquals(Character.TYPE, array.getClass().getComponentType());
198 
199         array = ArrayUtils.removeAll(new char[] { 'a', 'b' }, 1);
200         assertArrayEquals(new char[]{'a'}, array);
201         assertEquals(Character.TYPE, array.getClass().getComponentType());
202 
203         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c' }, 1);
204         assertArrayEquals(new char[]{'a', 'c'}, array);
205         assertEquals(Character.TYPE, array.getClass().getComponentType());
206 
207         array = ArrayUtils.removeAll(new char[] { 'a', 'b' }, 0, 1);
208         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
209         assertEquals(Character.TYPE, array.getClass().getComponentType());
210 
211         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c' }, 0, 1);
212         assertArrayEquals(new char[]{'c'}, array);
213         assertEquals(Character.TYPE, array.getClass().getComponentType());
214 
215         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c' }, 1, 2);
216         assertArrayEquals(new char[]{'a'}, array);
217         assertEquals(Character.TYPE, array.getClass().getComponentType());
218 
219         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c' }, 0, 2);
220         assertArrayEquals(new char[]{'b'}, array);
221         assertEquals(Character.TYPE, array.getClass().getComponentType());
222 
223         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c', 'd', 'e' }, 1, 3);
224         assertArrayEquals(new char[]{'a', 'c', 'e'}, array);
225         assertEquals(Character.TYPE, array.getClass().getComponentType());
226 
227         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c', 'd', 'e' }, 0, 2, 4);
228         assertArrayEquals(new char[]{'b', 'd'}, array);
229         assertEquals(Character.TYPE, array.getClass().getComponentType());
230 
231         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, 1, 3, 5);
232         assertArrayEquals(new char[]{'a', 'c', 'e', 'g'}, array);
233         assertEquals(Character.TYPE, array.getClass().getComponentType());
234 
235         array = ArrayUtils.removeAll(new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g' }, 0, 2, 4, 6);
236         assertArrayEquals(new char[]{'b', 'd', 'f'}, array);
237         assertEquals(Character.TYPE, array.getClass().getComponentType());
238     }
239 
240     @Test
241     void testRemoveAllCharArrayNegativeIndex() {
242         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new char[] { 'a', 'b' }, -1));
243     }
244 
245     @Test
246     void testRemoveAllCharArrayOutOfBoundsIndex() {
247         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new char[] { 'a', 'b' }, 2));
248     }
249 
250     @Test
251     void testRemoveAllCharArrayRemoveNone() {
252         final char[] array1 = { 'a', 'b' };
253         final char[] array2 = ArrayUtils.removeAll(array1);
254         assertNotSame(array1, array2);
255         assertArrayEquals(array1, array2);
256         assertEquals(char.class, array2.getClass().getComponentType());
257     }
258 
259     @Test
260     void testRemoveAllDoubleArray() {
261         double[] array;
262 
263         array = ArrayUtils.removeAll(new double[] { 1 }, 0);
264         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
265         assertEquals(Double.TYPE, array.getClass().getComponentType());
266 
267         array = ArrayUtils.removeAll(new double[] { 1, 2 }, 0);
268         assertArrayEquals(new double[]{2}, array);
269         assertEquals(Double.TYPE, array.getClass().getComponentType());
270 
271         array = ArrayUtils.removeAll(new double[] { 1, 2 }, 1);
272         assertArrayEquals(new double[]{1}, array);
273         assertEquals(Double.TYPE, array.getClass().getComponentType());
274 
275         array = ArrayUtils.removeAll(new double[] { 1, 2, 1 }, 1);
276         assertArrayEquals(new double[]{1, 1}, array);
277         assertEquals(Double.TYPE, array.getClass().getComponentType());
278 
279         array = ArrayUtils.removeAll(new double[] { 1, 2 }, 0, 1);
280         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
281         assertEquals(Double.TYPE, array.getClass().getComponentType());
282 
283         array = ArrayUtils.removeAll(new double[] { 1, 2, 3 }, 0, 1);
284         assertArrayEquals(new double[]{3}, array);
285         assertEquals(Double.TYPE, array.getClass().getComponentType());
286 
287         array = ArrayUtils.removeAll(new double[] { 1, 2, 3 }, 1, 2);
288         assertArrayEquals(new double[]{1}, array);
289         assertEquals(Double.TYPE, array.getClass().getComponentType());
290 
291         array = ArrayUtils.removeAll(new double[] { 1, 2, 3 }, 0, 2);
292         assertArrayEquals(new double[]{2}, array);
293         assertEquals(Double.TYPE, array.getClass().getComponentType());
294 
295         array = ArrayUtils.removeAll(new double[] { 1, 2, 3, 4, 5 }, 1, 3);
296         assertArrayEquals(new double[]{1, 3, 5}, array);
297         assertEquals(Double.TYPE, array.getClass().getComponentType());
298 
299         array = ArrayUtils.removeAll(new double[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
300         assertArrayEquals(new double[]{2, 4}, array);
301         assertEquals(Double.TYPE, array.getClass().getComponentType());
302 
303         array = ArrayUtils.removeAll(new double[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
304         assertArrayEquals(new double[]{1, 3, 5, 7}, array);
305         assertEquals(Double.TYPE, array.getClass().getComponentType());
306 
307         array = ArrayUtils.removeAll(new double[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
308         assertArrayEquals(new double[]{2, 4, 6}, array);
309         assertEquals(Double.TYPE, array.getClass().getComponentType());
310     }
311 
312     @Test
313     void testRemoveAllDoubleArrayNegativeIndex() {
314         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new double[] { 1, 2 }, -1));
315     }
316 
317     @Test
318     void testRemoveAllDoubleArrayOutOfBoundsIndex() {
319         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new double[] { 1, 2 }, 2));
320     }
321 
322     @Test
323     void testRemoveAllDoubleArrayRemoveNone() {
324         final double[] array1 = { 1, 2 };
325         final double[] array2 = ArrayUtils.removeAll(array1);
326         assertNotSame(array1, array2);
327         assertArrayEquals(array1, array2);
328         assertEquals(double.class, array2.getClass().getComponentType());
329     }
330 
331     @Test
332     void testRemoveAllFloatArray() {
333         float[] array;
334 
335         array = ArrayUtils.removeAll(new float[] { 1 }, 0);
336         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
337         assertEquals(Float.TYPE, array.getClass().getComponentType());
338 
339         array = ArrayUtils.removeAll(new float[] { 1, 2 }, 0);
340         assertArrayEquals(new float[]{2}, array);
341         assertEquals(Float.TYPE, array.getClass().getComponentType());
342 
343         array = ArrayUtils.removeAll(new float[] { 1, 2 }, 1);
344         assertArrayEquals(new float[]{1}, array);
345         assertEquals(Float.TYPE, array.getClass().getComponentType());
346 
347         array = ArrayUtils.removeAll(new float[] { 1, 2, 1 }, 1);
348         assertArrayEquals(new float[]{1, 1}, array);
349         assertEquals(Float.TYPE, array.getClass().getComponentType());
350 
351         array = ArrayUtils.removeAll(new float[] { 1, 2 }, 0, 1);
352         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
353         assertEquals(Float.TYPE, array.getClass().getComponentType());
354 
355         array = ArrayUtils.removeAll(new float[] { 1, 2, 3 }, 0, 1);
356         assertArrayEquals(new float[]{3}, array);
357         assertEquals(Float.TYPE, array.getClass().getComponentType());
358 
359         array = ArrayUtils.removeAll(new float[] { 1, 2, 3 }, 1, 2);
360         assertArrayEquals(new float[]{1}, array);
361         assertEquals(Float.TYPE, array.getClass().getComponentType());
362 
363         array = ArrayUtils.removeAll(new float[] { 1, 2, 3 }, 0, 2);
364         assertArrayEquals(new float[]{2}, array);
365         assertEquals(Float.TYPE, array.getClass().getComponentType());
366 
367         array = ArrayUtils.removeAll(new float[] { 1, 2, 3, 4, 5 }, 1, 3);
368         assertArrayEquals(new float[]{1, 3, 5}, array);
369         assertEquals(Float.TYPE, array.getClass().getComponentType());
370 
371         array = ArrayUtils.removeAll(new float[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
372         assertArrayEquals(new float[]{2, 4}, array);
373         assertEquals(Float.TYPE, array.getClass().getComponentType());
374 
375         array = ArrayUtils.removeAll(new float[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
376         assertArrayEquals(new float[]{1, 3, 5, 7}, array);
377         assertEquals(Float.TYPE, array.getClass().getComponentType());
378 
379         array = ArrayUtils.removeAll(new float[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
380         assertArrayEquals(new float[]{2, 4, 6}, array);
381         assertEquals(Float.TYPE, array.getClass().getComponentType());
382     }
383 
384     @Test
385     void testRemoveAllFloatArrayNegativeIndex() {
386         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new float[] { 1, 2 }, -1));
387     }
388 
389     @Test
390     void testRemoveAllFloatArrayOutOfBoundsIndex() {
391         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new float[] { 1, 2 }, 2));
392     }
393 
394     @Test
395     void testRemoveAllFloatArrayRemoveNone() {
396         final float[] array1 = { 1, 2 };
397         final float[] array2 = ArrayUtils.removeAll(array1);
398         assertNotSame(array1, array2);
399         assertArrayEquals(array1, array2);
400         assertEquals(float.class, array2.getClass().getComponentType());
401     }
402 
403     @Test
404     void testRemoveAllIntArray() {
405         int[] array;
406 
407         array = ArrayUtils.removeAll(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.EMPTY_INT_ARRAY);
408         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
409 
410         array = ArrayUtils.removeAll(new int[] { 1 }, ArrayUtils.EMPTY_INT_ARRAY);
411         assertArrayEquals(new int[]{1}, array);
412 
413         array = ArrayUtils.removeAll(new int[] { 1 }, 0);
414         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
415         assertEquals(Integer.TYPE, array.getClass().getComponentType());
416 
417         array = ArrayUtils.removeAll(new int[] { 1, 2 }, 0);
418         assertArrayEquals(new int[]{2}, array);
419         assertEquals(Integer.TYPE, array.getClass().getComponentType());
420 
421         array = ArrayUtils.removeAll(new int[] { 1, 2 }, 1);
422         assertArrayEquals(new int[]{1}, array);
423         assertEquals(Integer.TYPE, array.getClass().getComponentType());
424 
425         array = ArrayUtils.removeAll(new int[] { 1, 2, 1 }, 1);
426         assertArrayEquals(new int[]{1, 1}, array);
427         assertEquals(Integer.TYPE, array.getClass().getComponentType());
428 
429         array = ArrayUtils.removeAll(new int[] { 1, 2 }, 0, 1);
430         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
431         assertEquals(Integer.TYPE, array.getClass().getComponentType());
432 
433         array = ArrayUtils.removeAll(new int[] { 1, 2, 3 }, 0, 1);
434         assertArrayEquals(new int[]{3}, array);
435         assertEquals(Integer.TYPE, array.getClass().getComponentType());
436 
437         array = ArrayUtils.removeAll(new int[] { 1, 2, 3 }, 1, 2);
438         assertArrayEquals(new int[]{1}, array);
439         assertEquals(Integer.TYPE, array.getClass().getComponentType());
440 
441         array = ArrayUtils.removeAll(new int[] { 1, 2, 3 }, 0, 2);
442         assertArrayEquals(new int[]{2}, array);
443         assertEquals(Integer.TYPE, array.getClass().getComponentType());
444 
445         array = ArrayUtils.removeAll(new int[] { 1, 2, 3, 4, 5 }, 1, 3);
446         assertArrayEquals(new int[]{1, 3, 5}, array);
447         assertEquals(Integer.TYPE, array.getClass().getComponentType());
448 
449         array = ArrayUtils.removeAll(new int[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
450         assertArrayEquals(new int[]{2, 4}, array);
451         assertEquals(Integer.TYPE, array.getClass().getComponentType());
452 
453         array = ArrayUtils.removeAll(new int[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
454         assertArrayEquals(new int[]{1, 3, 5, 7}, array);
455         assertEquals(Integer.TYPE, array.getClass().getComponentType());
456 
457         array = ArrayUtils.removeAll(new int[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
458         assertArrayEquals(new int[]{2, 4, 6}, array);
459         assertEquals(Integer.TYPE, array.getClass().getComponentType());
460     }
461 
462     @Test
463     void testRemoveAllIntArrayNegativeIndex() {
464         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new int[] { 1, 2 }, -1));
465     }
466 
467     @Test
468     void testRemoveAllIntArrayOutOfBoundsIndex() {
469         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new int[] { 1, 2 }, 2));
470     }
471 
472     @Test
473     void testRemoveAllIntArrayRemoveNone() {
474         final int[] array1 = { 1, 2 };
475         final int[] array2 = ArrayUtils.removeAll(array1);
476         assertNotSame(array1, array2);
477         assertArrayEquals(array1, array2);
478         assertEquals(int.class, array2.getClass().getComponentType());
479     }
480 
481     @Test
482     void testRemoveAllLongArray() {
483         long[] array;
484 
485         array = ArrayUtils.removeAll(new long[] { 1 }, 0);
486         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
487         assertEquals(Long.TYPE, array.getClass().getComponentType());
488 
489         array = ArrayUtils.removeAll(new long[] { 1, 2 }, 0);
490         assertArrayEquals(new long[]{2}, array);
491         assertEquals(Long.TYPE, array.getClass().getComponentType());
492 
493         array = ArrayUtils.removeAll(new long[] { 1, 2 }, 1);
494         assertArrayEquals(new long[]{1}, array);
495         assertEquals(Long.TYPE, array.getClass().getComponentType());
496 
497         array = ArrayUtils.removeAll(new long[] { 1, 2, 1 }, 1);
498         assertArrayEquals(new long[]{1, 1}, array);
499         assertEquals(Long.TYPE, array.getClass().getComponentType());
500 
501         array = ArrayUtils.removeAll(new long[] { 1, 2 }, 0, 1);
502         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
503         assertEquals(Long.TYPE, array.getClass().getComponentType());
504 
505         array = ArrayUtils.removeAll(new long[] { 1, 2, 3 }, 0, 1);
506         assertArrayEquals(new long[]{3}, array);
507         assertEquals(Long.TYPE, array.getClass().getComponentType());
508 
509         array = ArrayUtils.removeAll(new long[] { 1, 2, 3 }, 1, 2);
510         assertArrayEquals(new long[]{1}, array);
511         assertEquals(Long.TYPE, array.getClass().getComponentType());
512 
513         array = ArrayUtils.removeAll(new long[] { 1, 2, 3 }, 0, 2);
514         assertArrayEquals(new long[]{2}, array);
515         assertEquals(Long.TYPE, array.getClass().getComponentType());
516 
517         array = ArrayUtils.removeAll(new long[] { 1, 2, 3, 4, 5 }, 1, 3);
518         assertArrayEquals(new long[]{1, 3, 5}, array);
519         assertEquals(Long.TYPE, array.getClass().getComponentType());
520 
521         array = ArrayUtils.removeAll(new long[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
522         assertArrayEquals(new long[]{2, 4}, array);
523         assertEquals(Long.TYPE, array.getClass().getComponentType());
524 
525         array = ArrayUtils.removeAll(new long[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
526         assertArrayEquals(new long[]{1, 3, 5, 7}, array);
527         assertEquals(Long.TYPE, array.getClass().getComponentType());
528 
529         array = ArrayUtils.removeAll(new long[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
530         assertArrayEquals(new long[]{2, 4, 6}, array);
531         assertEquals(Long.TYPE, array.getClass().getComponentType());
532     }
533 
534     @Test
535     void testRemoveAllLongArrayNegativeIndex() {
536         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new long[] { 1, 2 }, -1));
537     }
538 
539     @Test
540     void testRemoveAllLongArrayOutOfBoundsIndex() {
541         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new long[] { 1, 2 }, 2));
542     }
543 
544     @Test
545     void testRemoveAllLongArrayRemoveNone() {
546         final long[] array1 = { 1, 2 };
547         final long[] array2 = ArrayUtils.removeAll(array1);
548         assertNotSame(array1, array2);
549         assertArrayEquals(array1, array2);
550         assertEquals(long.class, array2.getClass().getComponentType());
551     }
552 
553     @Test
554     void testRemoveAllNullBooleanArray() {
555         assertNull(ArrayUtils.removeAll((boolean[]) null, 0));
556         assertNull(ArrayUtils.removeAll((boolean[]) null, NULL_INDICES));
557         final boolean[] array0 = {};
558         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
559         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
560         final boolean[] array1 = new boolean[1];
561         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
562         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
563     }
564 
565     @Test
566     void testRemoveAllNullByteArray() {
567         assertNull(ArrayUtils.removeAll((byte[]) null, 0));
568         assertNull(ArrayUtils.removeAll((byte[]) null, NULL_INDICES));
569         final byte[] array0 = {};
570         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
571         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
572         final byte[] array1 = new byte[1];
573         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
574         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
575     }
576 
577     @Test
578     void testRemoveAllNullCharArray() {
579         assertNull(ArrayUtils.removeAll((char[]) null, 0));
580         assertNull(ArrayUtils.removeAll((char[]) null, NULL_INDICES));
581         final char[] array0 = {};
582         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
583         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
584         final char[] array1 = new char[1];
585         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
586         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
587     }
588 
589     @Test
590     void testRemoveAllNullDoubleArray() {
591         assertNull(ArrayUtils.removeAll((double[]) null, 0));
592         assertNull(ArrayUtils.removeAll((double[]) null, NULL_INDICES));
593         final double[] array0 = {};
594         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
595         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
596         final double[] array1 = new double[1];
597         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
598         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
599     }
600 
601     @Test
602     void testRemoveAllNullFloatArray() {
603         assertNull(ArrayUtils.removeAll((float[]) null, 0));
604         assertNull(ArrayUtils.removeAll((float[]) null, NULL_INDICES));
605         final float[] array0 = {};
606         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
607         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
608         final float[] array1 = new float[1];
609         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
610         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
611     }
612 
613     @Test
614     void testRemoveAllNullIntArray() {
615         assertNull(ArrayUtils.removeAll((int[]) null, 0));
616         assertNull(ArrayUtils.removeAll((int[]) null, NULL_INDICES));
617         final int[] array0 = {};
618         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
619         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
620         final int[] array1 = new int[1];
621         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
622         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
623     }
624 
625     @Test
626     void testRemoveAllNullLongArray() {
627         assertNull(ArrayUtils.removeAll((long[]) null, 0));
628         assertNull(ArrayUtils.removeAll((long[]) null, NULL_INDICES));
629         final long[] array0 = {};
630         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
631         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
632         final long[] array1 = new long[1];
633         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
634         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
635     }
636 
637     @Test
638     void testRemoveAllNullObjectArray() {
639         assertNull(ArrayUtils.removeAll((Object[]) null, 0));
640         assertNull(ArrayUtils.removeAll((Object[]) null, NULL_INDICES));
641         final Object[] array0 = {};
642         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
643         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
644         final Object[] array1 = new Object[1];
645         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
646         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
647     }
648 
649     @Test
650     void testRemoveAllNullShortArray() {
651         assertNull(ArrayUtils.removeAll((short[]) null, 0));
652         assertNull(ArrayUtils.removeAll((short[]) null, NULL_INDICES));
653         final short[] array0 = {};
654         assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
655         assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
656         final short[] array1 = new short[1];
657         assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
658         assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
659     }
660 
661     @Test
662     void testRemoveAllNumberArray() {
663         final Number[] inarray = { Integer.valueOf(1), Long.valueOf(2L), Byte.valueOf((byte) 3) };
664         assertEquals(3, inarray.length);
665         Number[] outarray;
666 
667         outarray = ArrayUtils.removeAll(inarray, 1);
668         assertArrayEquals(new Number[] { Integer.valueOf(1), Byte.valueOf((byte) 3) }, outarray);
669         assertEquals(Number.class, outarray.getClass().getComponentType());
670 
671         outarray = ArrayUtils.removeAll(outarray, 1);
672         assertArrayEquals(new Number[] { Integer.valueOf(1) }, outarray);
673         assertEquals(Number.class, outarray.getClass().getComponentType());
674 
675         outarray = ArrayUtils.removeAll(outarray, 0);
676         assertEquals(0, outarray.length);
677         assertEquals(Number.class, outarray.getClass().getComponentType());
678 
679         outarray = ArrayUtils.removeAll(inarray, 0, 1);
680         assertArrayEquals(new Number[] { Byte.valueOf((byte) 3) }, outarray);
681         assertEquals(Number.class, outarray.getClass().getComponentType());
682 
683         outarray = ArrayUtils.removeAll(inarray, 0, 2);
684         assertArrayEquals(new Number[] { Long.valueOf(2L) }, outarray);
685         assertEquals(Number.class, outarray.getClass().getComponentType());
686 
687         outarray = ArrayUtils.removeAll(inarray, 1, 2);
688         assertArrayEquals(new Number[] { Integer.valueOf(1) }, outarray);
689         assertEquals(Number.class, outarray.getClass().getComponentType());
690     }
691 
692     @Test
693     void testRemoveAllObjectArray() {
694         Object[] array;
695 
696         array = ArrayUtils.removeAll(new Object[] { "a" }, 0);
697         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
698         assertEquals(Object.class, array.getClass().getComponentType());
699 
700         array = ArrayUtils.removeAll(new Object[] { "a", "b" }, 0, 1);
701         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
702         assertEquals(Object.class, array.getClass().getComponentType());
703 
704         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c" }, 1, 2);
705         assertArrayEquals(new Object[] { "a" }, array);
706         assertEquals(Object.class, array.getClass().getComponentType());
707 
708         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 1, 2);
709         assertArrayEquals(new Object[] { "a", "d" }, array);
710         assertEquals(Object.class, array.getClass().getComponentType());
711 
712         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 3);
713         assertArrayEquals(new Object[] { "b", "c" }, array);
714         assertEquals(Object.class, array.getClass().getComponentType());
715 
716         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 1, 3);
717         assertArrayEquals(new Object[] { "c" }, array);
718         assertEquals(Object.class, array.getClass().getComponentType());
719 
720         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d", "e" }, 0, 1, 3);
721         assertArrayEquals(new Object[] { "c", "e" }, array);
722         assertEquals(Object.class, array.getClass().getComponentType());
723 
724         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d", "e" }, 0, 2, 4);
725         assertArrayEquals(new Object[] { "b", "d" }, array);
726         assertEquals(Object.class, array.getClass().getComponentType());
727 
728         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 1, 3, 0, 1, 3);
729         assertArrayEquals(new Object[] { "c" }, array);
730         assertEquals(Object.class, array.getClass().getComponentType());
731 
732         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 2, 1, 0, 3);
733         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
734         assertEquals(Object.class, array.getClass().getComponentType());
735 
736         array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 2, 0, 1, 3, 0, 2, 1, 3);
737         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
738         assertEquals(Object.class, array.getClass().getComponentType());
739     }
740 
741     @Test
742     void testRemoveAllObjectArrayNegativeIndex() {
743         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new Object[] { "a", "b" }, -1));
744     }
745 
746     @Test
747     void testRemoveAllObjectArrayOutOfBoundsIndex() {
748         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new Object[] { "a", "b" }, 2));
749     }
750 
751     @Test
752     void testRemoveAllObjectArrayRemoveNone() {
753         final Object[] array1 = { "foo", "bar", "baz" };
754         final Object[] array2 = ArrayUtils.removeAll(array1);
755         assertNotSame(array1, array2);
756         assertArrayEquals(array1, array2);
757         assertEquals(Object.class, array2.getClass().getComponentType());
758     }
759 
760     @Test
761     void testRemoveAllShortArray() {
762         short[] array;
763 
764         array = ArrayUtils.removeAll(new short[] { 1 }, 0);
765         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
766         assertEquals(Short.TYPE, array.getClass().getComponentType());
767 
768         array = ArrayUtils.removeAll(new short[] { 1, 2 }, 0);
769         assertArrayEquals(new short[]{2}, array);
770         assertEquals(Short.TYPE, array.getClass().getComponentType());
771 
772         array = ArrayUtils.removeAll(new short[] { 1, 2 }, 1);
773         assertArrayEquals(new short[]{1}, array);
774         assertEquals(Short.TYPE, array.getClass().getComponentType());
775 
776         array = ArrayUtils.removeAll(new short[] { 1, 2, 1 }, 1);
777         assertArrayEquals(new short[]{1, 1}, array);
778         assertEquals(Short.TYPE, array.getClass().getComponentType());
779 
780         array = ArrayUtils.removeAll(new short[] { 1, 2 }, 0, 1);
781         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
782         assertEquals(Short.TYPE, array.getClass().getComponentType());
783 
784         array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 0, 1);
785         assertArrayEquals(new short[]{3}, array);
786         assertEquals(Short.TYPE, array.getClass().getComponentType());
787 
788         array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 1, 2);
789         assertArrayEquals(new short[]{1}, array);
790         assertEquals(Short.TYPE, array.getClass().getComponentType());
791 
792         array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 0, 2);
793         assertArrayEquals(new short[]{2}, array);
794         assertEquals(Short.TYPE, array.getClass().getComponentType());
795 
796         array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5 }, 1, 3);
797         assertArrayEquals(new short[]{1, 3, 5}, array);
798         assertEquals(Short.TYPE, array.getClass().getComponentType());
799 
800         array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
801         assertArrayEquals(new short[]{2, 4}, array);
802         assertEquals(Short.TYPE, array.getClass().getComponentType());
803 
804         array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
805         assertArrayEquals(new short[]{1, 3, 5, 7}, array);
806         assertEquals(Short.TYPE, array.getClass().getComponentType());
807 
808         array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
809         assertArrayEquals(new short[]{2, 4, 6}, array);
810         assertEquals(Short.TYPE, array.getClass().getComponentType());
811     }
812 
813     @Test
814     void testRemoveAllShortArrayNegativeIndex() {
815         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new short[] { 1, 2 }, -1, 0));
816     }
817 
818     @Test
819     void testRemoveAllShortArrayOutOfBoundsIndex() {
820         assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new short[] { 1, 2 }, 2, 0));
821     }
822 
823     @Test
824     void testRemoveAllShortArrayRemoveNone() {
825         final short[] array1 = { 1, 2 };
826         final short[] array2 = ArrayUtils.removeAll(array1);
827         assertNotSame(array1, array2);
828         assertArrayEquals(array1, array2);
829         assertEquals(short.class, array2.getClass().getComponentType());
830     }
831 
832     @Test
833     void testRemoveElementBooleanArray() {
834         boolean[] array;
835 
836         array = ArrayUtils.removeElements((boolean[]) null, true);
837         assertNull(array);
838 
839         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BOOLEAN_ARRAY, true);
840         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
841         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
842 
843         array = ArrayUtils.removeElements(new boolean[] { true }, true);
844         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
845         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
846 
847         array = ArrayUtils.removeElements(new boolean[] { true, false }, true);
848         assertArrayEquals(new boolean[]{false}, array);
849         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
850 
851         array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true);
852         assertArrayEquals(new boolean[]{false, true}, array);
853         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
854 
855         array = ArrayUtils.removeElements((boolean[]) null, true, false);
856         assertNull(array);
857 
858         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BOOLEAN_ARRAY, true, false);
859         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
860         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
861 
862         array = ArrayUtils.removeElements(new boolean[] { true }, true, false);
863         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
864         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
865 
866         array = ArrayUtils.removeElements(new boolean[] { true, false }, true, false);
867         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
868         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
869 
870         array = ArrayUtils.removeElements(new boolean[] { true, false }, true, true);
871         assertArrayEquals(new boolean[]{false}, array);
872         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
873 
874         array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true, false);
875         assertArrayEquals(new boolean[]{true}, array);
876         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
877 
878         array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true, true);
879         assertArrayEquals(new boolean[]{false}, array);
880         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
881 
882         array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true, true, true, true);
883         assertArrayEquals(new boolean[]{false}, array);
884         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
885     }
886 
887     @Test
888     void testRemoveElementByteArray() {
889         byte[] array;
890 
891         array = ArrayUtils.removeElements((byte[]) null, (byte) 1);
892         assertNull(array);
893 
894         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BYTE_ARRAY, (byte) 1);
895         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
896         assertEquals(Byte.TYPE, array.getClass().getComponentType());
897 
898         array = ArrayUtils.removeElements(new byte[] { 1 }, (byte) 1);
899         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
900         assertEquals(Byte.TYPE, array.getClass().getComponentType());
901 
902         array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (byte) 1);
903         assertArrayEquals(new byte[]{2}, array);
904         assertEquals(Byte.TYPE, array.getClass().getComponentType());
905 
906         array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1);
907         assertArrayEquals(new byte[]{2, 1}, array);
908         assertEquals(Byte.TYPE, array.getClass().getComponentType());
909 
910         array = ArrayUtils.removeElements((byte[]) null, (byte) 1, (byte) 2);
911         assertNull(array);
912 
913         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BYTE_ARRAY, (byte) 1, (byte) 2);
914         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
915         assertEquals(Byte.TYPE, array.getClass().getComponentType());
916 
917         array = ArrayUtils.removeElements(new byte[] { 1 }, (byte) 1, (byte) 2);
918         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
919         assertEquals(Byte.TYPE, array.getClass().getComponentType());
920 
921         array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (byte) 1, (byte) 2);
922         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
923         assertEquals(Byte.TYPE, array.getClass().getComponentType());
924 
925         array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (byte) 1, (byte) 1);
926         assertArrayEquals(new byte[]{2}, array);
927         assertEquals(Byte.TYPE, array.getClass().getComponentType());
928 
929         array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1, (byte) 2);
930         assertArrayEquals(new byte[]{1}, array);
931         assertEquals(Byte.TYPE, array.getClass().getComponentType());
932 
933         array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1, (byte) 1);
934         assertArrayEquals(new byte[]{2}, array);
935         assertEquals(Byte.TYPE, array.getClass().getComponentType());
936 
937         array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1, (byte) 1, (byte) 1, (byte) 1);
938         assertArrayEquals(new byte[]{2}, array);
939         assertEquals(Byte.TYPE, array.getClass().getComponentType());
940     }
941 
942     @Test
943     void testRemoveElementCharArray() {
944         char[] array;
945 
946         array = ArrayUtils.removeElements((char[]) null, 'a');
947         assertNull(array);
948 
949         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_CHAR_ARRAY, 'a');
950         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
951         assertEquals(Character.TYPE, array.getClass().getComponentType());
952 
953         array = ArrayUtils.removeElements(new char[] { 'a' }, 'a');
954         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
955         assertEquals(Character.TYPE, array.getClass().getComponentType());
956 
957         array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, 'a');
958         assertArrayEquals(new char[]{'b'}, array);
959         assertEquals(Character.TYPE, array.getClass().getComponentType());
960 
961         array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a');
962         assertArrayEquals(new char[]{'b', 'a'}, array);
963         assertEquals(Character.TYPE, array.getClass().getComponentType());
964 
965         array = ArrayUtils.removeElements((char[]) null, 'a', 'b');
966         assertNull(array);
967 
968         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_CHAR_ARRAY, 'a', 'b');
969         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
970         assertEquals(Character.TYPE, array.getClass().getComponentType());
971 
972         array = ArrayUtils.removeElements(new char[] { 'a' }, 'a', 'b');
973         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
974         assertEquals(Character.TYPE, array.getClass().getComponentType());
975 
976         array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, 'a', 'b');
977         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
978         assertEquals(Character.TYPE, array.getClass().getComponentType());
979 
980         array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, 'a', 'a');
981         assertArrayEquals(new char[]{'b'}, array);
982         assertEquals(Character.TYPE, array.getClass().getComponentType());
983 
984         array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a', 'b');
985         assertArrayEquals(new char[]{'a'}, array);
986         assertEquals(Character.TYPE, array.getClass().getComponentType());
987 
988         array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a', 'a');
989         assertArrayEquals(new char[]{'b'}, array);
990         assertEquals(Character.TYPE, array.getClass().getComponentType());
991 
992         array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a', 'a', 'a', 'a');
993         assertArrayEquals(new char[]{'b'}, array);
994         assertEquals(Character.TYPE, array.getClass().getComponentType());
995     }
996 
997     @Test
998     void testRemoveElementDoubleArray() {
999         double[] array;
1000 
1001         array = ArrayUtils.removeElements((double[]) null, (double) 1);
1002         assertNull(array);
1003 
1004         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_DOUBLE_ARRAY, (double) 1);
1005         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1006         assertEquals(Double.TYPE, array.getClass().getComponentType());
1007 
1008         array = ArrayUtils.removeElements(new double[] { 1 }, (double) 1);
1009         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1010         assertEquals(Double.TYPE, array.getClass().getComponentType());
1011 
1012         array = ArrayUtils.removeElements(new double[] { 1, 2 }, (double) 1);
1013         assertArrayEquals(new double[]{2}, array);
1014         assertEquals(Double.TYPE, array.getClass().getComponentType());
1015 
1016         array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, (double) 1);
1017         assertArrayEquals(new double[]{2, 1}, array);
1018         assertEquals(Double.TYPE, array.getClass().getComponentType());
1019 
1020         array = ArrayUtils.removeElements((double[]) null, 1, 2);
1021         assertNull(array);
1022 
1023         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2);
1024         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1025         assertEquals(Double.TYPE, array.getClass().getComponentType());
1026 
1027         array = ArrayUtils.removeElements(new double[] { 1 }, 1, 2);
1028         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1029         assertEquals(Double.TYPE, array.getClass().getComponentType());
1030 
1031         array = ArrayUtils.removeElements(new double[] { 1, 2 }, 1, 2);
1032         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1033         assertEquals(Double.TYPE, array.getClass().getComponentType());
1034 
1035         array = ArrayUtils.removeElements(new double[] { 1, 2 }, 1, 1);
1036         assertArrayEquals(new double[]{2}, array);
1037         assertEquals(Double.TYPE, array.getClass().getComponentType());
1038 
1039         array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, 1, 2);
1040         assertArrayEquals(new double[]{1}, array);
1041         assertEquals(Double.TYPE, array.getClass().getComponentType());
1042 
1043         array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, 1, 1);
1044         assertArrayEquals(new double[]{2}, array);
1045         assertEquals(Double.TYPE, array.getClass().getComponentType());
1046 
1047         array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, 1, 1, 1, 1);
1048         assertArrayEquals(new double[]{2}, array);
1049         assertEquals(Double.TYPE, array.getClass().getComponentType());
1050     }
1051 
1052     @Test
1053     void testRemoveElementFloatArray() {
1054         float[] array;
1055 
1056         array = ArrayUtils.removeElements((float[]) null, (float) 1);
1057         assertNull(array);
1058 
1059         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_FLOAT_ARRAY, (float) 1);
1060         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1061         assertEquals(Float.TYPE, array.getClass().getComponentType());
1062 
1063         array = ArrayUtils.removeElements(new float[] { 1 }, (float) 1);
1064         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1065         assertEquals(Float.TYPE, array.getClass().getComponentType());
1066 
1067         array = ArrayUtils.removeElements(new float[] { 1, 2 }, (float) 1);
1068         assertArrayEquals(new float[]{2}, array);
1069         assertEquals(Float.TYPE, array.getClass().getComponentType());
1070 
1071         array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, (float) 1);
1072         assertArrayEquals(new float[]{2, 1}, array);
1073         assertEquals(Float.TYPE, array.getClass().getComponentType());
1074 
1075         array = ArrayUtils.removeElements((float[]) null, 1, 1);
1076         assertNull(array);
1077 
1078         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 1);
1079         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1080         assertEquals(Float.TYPE, array.getClass().getComponentType());
1081 
1082         array = ArrayUtils.removeElements(new float[] { 1 }, 1, 1);
1083         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1084         assertEquals(Float.TYPE, array.getClass().getComponentType());
1085 
1086         array = ArrayUtils.removeElements(new float[] { 1, 2 }, 1, 2);
1087         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1088         assertEquals(Float.TYPE, array.getClass().getComponentType());
1089 
1090         array = ArrayUtils.removeElements(new float[] { 1, 2 }, 1, 1);
1091         assertArrayEquals(new float[]{2}, array);
1092         assertEquals(Float.TYPE, array.getClass().getComponentType());
1093 
1094         array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 1);
1095         assertArrayEquals(new float[]{2}, array);
1096         assertEquals(Float.TYPE, array.getClass().getComponentType());
1097 
1098         array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 2);
1099         assertArrayEquals(new float[]{1}, array);
1100         assertEquals(Float.TYPE, array.getClass().getComponentType());
1101 
1102         array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 1, 1, 1);
1103         assertArrayEquals(new float[]{2}, array);
1104         assertEquals(Float.TYPE, array.getClass().getComponentType());
1105     }
1106 
1107     @Test
1108     void testRemoveElementIntArray() {
1109         int[] array;
1110 
1111         array = ArrayUtils.removeElements((int[]) null, 1);
1112         assertNull(array);
1113 
1114         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_INT_ARRAY, 1);
1115         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1116         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1117 
1118         array = ArrayUtils.removeElements(new int[] { 1 }, 1);
1119         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1120         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1121 
1122         array = ArrayUtils.removeElements(new int[] { 1, 2 }, 1);
1123         assertArrayEquals(new int[]{2}, array);
1124         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1125 
1126         array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1);
1127         assertArrayEquals(new int[]{2, 1}, array);
1128         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1129 
1130         array = ArrayUtils.removeElements((int[]) null, 1);
1131         assertNull(array);
1132 
1133         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_INT_ARRAY, 1, 1);
1134         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1135         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1136 
1137         array = ArrayUtils.removeElements(new int[] { 1 }, 1, 1);
1138         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1139         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1140 
1141         array = ArrayUtils.removeElements(new int[] { 1, 2 }, 1, 2);
1142         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1143         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1144 
1145         array = ArrayUtils.removeElements(new int[] { 1, 2 }, 1, 1);
1146         assertArrayEquals(new int[]{2}, array);
1147         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1148 
1149         array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1, 2);
1150         assertArrayEquals(new int[]{1}, array);
1151         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1152 
1153         array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1, 1);
1154         assertArrayEquals(new int[]{2}, array);
1155         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1156 
1157         array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1, 1, 1, 1);
1158         assertArrayEquals(new int[]{2}, array);
1159         assertEquals(Integer.TYPE, array.getClass().getComponentType());
1160     }
1161 
1162     @Test
1163     void testRemoveElementLongArray() {
1164         long[] array;
1165 
1166         array = ArrayUtils.removeElements((long[]) null, 1L);
1167         assertNull(array);
1168 
1169         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L);
1170         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1171         assertEquals(Long.TYPE, array.getClass().getComponentType());
1172 
1173         array = ArrayUtils.removeElements(new long[] { 1 }, 1L);
1174         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1175         assertEquals(Long.TYPE, array.getClass().getComponentType());
1176 
1177         array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L);
1178         assertArrayEquals(new long[]{2}, array);
1179         assertEquals(Long.TYPE, array.getClass().getComponentType());
1180 
1181         array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L);
1182         assertArrayEquals(new long[]{2, 1}, array);
1183         assertEquals(Long.TYPE, array.getClass().getComponentType());
1184 
1185         array = ArrayUtils.removeElements((long[]) null, 1L, 1L);
1186         assertNull(array);
1187 
1188         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L, 1L);
1189         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1190         assertEquals(Long.TYPE, array.getClass().getComponentType());
1191 
1192         array = ArrayUtils.removeElements(new long[] { 1 }, 1L, 1L);
1193         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1194         assertEquals(Long.TYPE, array.getClass().getComponentType());
1195 
1196         array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 2L);
1197         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1198         assertEquals(Long.TYPE, array.getClass().getComponentType());
1199 
1200         array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 1L);
1201         assertArrayEquals(new long[]{2}, array);
1202         assertEquals(Long.TYPE, array.getClass().getComponentType());
1203 
1204         array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L);
1205         assertArrayEquals(new long[]{2}, array);
1206         assertEquals(Long.TYPE, array.getClass().getComponentType());
1207 
1208         array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 2L);
1209         assertArrayEquals(new long[]{1}, array);
1210         assertEquals(Long.TYPE, array.getClass().getComponentType());
1211 
1212         array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L, 1L, 1L);
1213         assertArrayEquals(new long[]{2}, array);
1214         assertEquals(Long.TYPE, array.getClass().getComponentType());
1215     }
1216 
1217     @Test
1218     void testRemoveElementShortArray() {
1219         short[] array;
1220 
1221         array = ArrayUtils.removeElements((short[]) null, (short) 1);
1222         assertNull(array);
1223 
1224         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_SHORT_ARRAY, (short) 1);
1225         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1226         assertEquals(Short.TYPE, array.getClass().getComponentType());
1227 
1228         array = ArrayUtils.removeElements(new short[] { 1 }, (short) 1);
1229         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1230         assertEquals(Short.TYPE, array.getClass().getComponentType());
1231 
1232         array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1);
1233         assertArrayEquals(new short[]{2}, array);
1234         assertEquals(Short.TYPE, array.getClass().getComponentType());
1235 
1236         array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1);
1237         assertArrayEquals(new short[]{2, 1}, array);
1238         assertEquals(Short.TYPE, array.getClass().getComponentType());
1239 
1240         array = ArrayUtils.removeElements((short[]) null, (short) 1, (short) 1);
1241         assertNull(array);
1242 
1243         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_SHORT_ARRAY, (short) 1, (short) 1);
1244         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1245         assertEquals(Short.TYPE, array.getClass().getComponentType());
1246 
1247         array = ArrayUtils.removeElements(new short[] { 1 }, (short) 1, (short) 1);
1248         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1249         assertEquals(Short.TYPE, array.getClass().getComponentType());
1250 
1251         array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1, (short) 2);
1252         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1253         assertEquals(Short.TYPE, array.getClass().getComponentType());
1254 
1255         array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1, (short) 1);
1256         assertArrayEquals(new short[]{2}, array);
1257         assertEquals(Short.TYPE, array.getClass().getComponentType());
1258 
1259         array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 1);
1260         assertArrayEquals(new short[]{2}, array);
1261         assertEquals(Short.TYPE, array.getClass().getComponentType());
1262 
1263         array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 2);
1264         assertArrayEquals(new short[]{1}, array);
1265         assertEquals(Short.TYPE, array.getClass().getComponentType());
1266 
1267         array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 1, (short) 1, (short) 1);
1268         assertArrayEquals(new short[]{2}, array);
1269         assertEquals(Short.TYPE, array.getClass().getComponentType());
1270     }
1271 
1272     @Test
1273     void testRemoveElementsObjectArray() {
1274         Object[] array;
1275 
1276         array = ArrayUtils.removeElements((Object[]) null, "a");
1277         assertNull(array);
1278 
1279         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_OBJECT_ARRAY, "a");
1280         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1281         assertEquals(Object.class, array.getClass().getComponentType());
1282 
1283         array = ArrayUtils.removeElements(new Object[] { "a" }, "a");
1284         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1285         assertEquals(Object.class, array.getClass().getComponentType());
1286 
1287         array = ArrayUtils.removeElements(new Object[] { "a", "b" }, "a");
1288         assertArrayEquals(new Object[]{"b"}, array);
1289         assertEquals(Object.class, array.getClass().getComponentType());
1290 
1291         array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a");
1292         assertArrayEquals(new Object[]{"b", "a"}, array);
1293         assertEquals(Object.class, array.getClass().getComponentType());
1294 
1295         array = ArrayUtils.removeElements((Object[]) null, "a", "b");
1296         assertNull(array);
1297 
1298         array = ArrayUtils.removeElements(ArrayUtils.EMPTY_OBJECT_ARRAY, "a", "b");
1299         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1300         assertEquals(Object.class, array.getClass().getComponentType());
1301 
1302         array = ArrayUtils.removeElements(new Object[] { "a" }, "a", "b");
1303         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1304         assertEquals(Object.class, array.getClass().getComponentType());
1305 
1306         array = ArrayUtils.removeElements(new Object[] { "a", "b" }, "a", "c");
1307         assertArrayEquals(new Object[]{"b"}, array);
1308         assertEquals(Object.class, array.getClass().getComponentType());
1309 
1310         array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a");
1311         assertArrayEquals(new Object[]{"b", "a"}, array);
1312         assertEquals(Object.class, array.getClass().getComponentType());
1313 
1314         array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "b");
1315         assertArrayEquals(new Object[]{"a"}, array);
1316         assertEquals(Object.class, array.getClass().getComponentType());
1317 
1318         array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "a");
1319         assertArrayEquals(new Object[]{"b"}, array);
1320         assertEquals(Object.class, array.getClass().getComponentType());
1321 
1322         array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "a", "a", "a");
1323         assertArrayEquals(new Object[]{"b"}, array);
1324         assertEquals(Object.class, array.getClass().getComponentType());
1325     }
1326 
1327 }