1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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));
568 assertNull(ArrayUtils.removeAll((byte[]) null, 0));
569 assertNull(ArrayUtils.removeAll((byte[]) null, NULL_INDICES));
570 final byte[] array0 = {};
571 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
572 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
573 final byte[] array1 = new byte[1];
574 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
575 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
576 }
577
578 @Test
579 void testRemoveAllNullCharArray() {
580 assertNull(ArrayUtils.removeAll((char[]) null));
581 assertNull(ArrayUtils.removeAll((char[]) null, 0));
582 assertNull(ArrayUtils.removeAll((char[]) null, NULL_INDICES));
583 final char[] array0 = {};
584 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
585 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
586 final char[] array1 = new char[1];
587 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
588 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
589 }
590
591 @Test
592 void testRemoveAllNullDoubleArray() {
593 assertNull(ArrayUtils.removeAll((double[]) null));
594 assertNull(ArrayUtils.removeAll((double[]) null, 0));
595 assertNull(ArrayUtils.removeAll((double[]) null, NULL_INDICES));
596 final double[] array0 = {};
597 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
598 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
599 final double[] array1 = new double[1];
600 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
601 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
602 }
603
604 @Test
605 void testRemoveAllNullFloatArray() {
606 assertNull(ArrayUtils.removeAll((float[]) null));
607 assertNull(ArrayUtils.removeAll((float[]) null, 0));
608 assertNull(ArrayUtils.removeAll((float[]) null, NULL_INDICES));
609 final float[] array0 = {};
610 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
611 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
612 final float[] array1 = new float[1];
613 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
614 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
615 }
616
617 @Test
618 void testRemoveAllNullIntArray() {
619 assertNull(ArrayUtils.removeAll((int[]) null));
620 assertNull(ArrayUtils.removeAll((int[]) null, 0));
621 assertNull(ArrayUtils.removeAll((int[]) null, NULL_INDICES));
622 final int[] array0 = {};
623 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
624 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
625 final int[] array1 = new int[1];
626 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
627 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
628 }
629
630 @Test
631 void testRemoveAllNullLongArray() {
632 assertNull(ArrayUtils.removeAll((long[]) null));
633 assertNull(ArrayUtils.removeAll((long[]) null, 0));
634 assertNull(ArrayUtils.removeAll((long[]) null, NULL_INDICES));
635 final long[] array0 = {};
636 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
637 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
638 final long[] array1 = new long[1];
639 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
640 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
641 }
642
643 @Test
644 void testRemoveAllNullObjectArray() {
645 assertNull(ArrayUtils.removeAll((Object[]) null));
646 assertNull(ArrayUtils.removeAll((Object[]) null, 0));
647 assertNull(ArrayUtils.removeAll((Object[]) null, NULL_INDICES));
648 final Object[] array0 = {};
649 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
650 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
651 final Object[] array1 = new Object[1];
652 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
653 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
654 }
655
656 @Test
657 void testRemoveAllNullShortArray() {
658 assertNull(ArrayUtils.removeAll((short[]) null));
659 assertNull(ArrayUtils.removeAll((short[]) null, 0));
660 assertNull(ArrayUtils.removeAll((short[]) null, NULL_INDICES));
661 final short[] array0 = {};
662 assertArrayEquals(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
663 assertNotSame(array0, ArrayUtils.removeAll(array0, NULL_INDICES));
664 final short[] array1 = new short[1];
665 assertArrayEquals(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
666 assertNotSame(array1, ArrayUtils.removeAll(array1, NULL_INDICES));
667 }
668
669 @Test
670 void testRemoveAllNumberArray() {
671 final Number[] inarray = { Integer.valueOf(1), Long.valueOf(2L), Byte.valueOf((byte) 3) };
672 assertEquals(3, inarray.length);
673 Number[] outarray;
674
675 outarray = ArrayUtils.removeAll(inarray, 1);
676 assertArrayEquals(new Number[] { Integer.valueOf(1), Byte.valueOf((byte) 3) }, outarray);
677 assertEquals(Number.class, outarray.getClass().getComponentType());
678
679 outarray = ArrayUtils.removeAll(outarray, 1);
680 assertArrayEquals(new Number[] { Integer.valueOf(1) }, outarray);
681 assertEquals(Number.class, outarray.getClass().getComponentType());
682
683 outarray = ArrayUtils.removeAll(outarray, 0);
684 assertEquals(0, outarray.length);
685 assertEquals(Number.class, outarray.getClass().getComponentType());
686
687 outarray = ArrayUtils.removeAll(inarray, 0, 1);
688 assertArrayEquals(new Number[] { Byte.valueOf((byte) 3) }, outarray);
689 assertEquals(Number.class, outarray.getClass().getComponentType());
690
691 outarray = ArrayUtils.removeAll(inarray, 0, 2);
692 assertArrayEquals(new Number[] { Long.valueOf(2L) }, outarray);
693 assertEquals(Number.class, outarray.getClass().getComponentType());
694
695 outarray = ArrayUtils.removeAll(inarray, 1, 2);
696 assertArrayEquals(new Number[] { Integer.valueOf(1) }, outarray);
697 assertEquals(Number.class, outarray.getClass().getComponentType());
698 }
699
700 @Test
701 void testRemoveAllObjectArray() {
702 Object[] array;
703
704 array = ArrayUtils.removeAll(new Object[] { "a" }, 0);
705 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
706 assertEquals(Object.class, array.getClass().getComponentType());
707
708 array = ArrayUtils.removeAll(new Object[] { "a", "b" }, 0, 1);
709 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
710 assertEquals(Object.class, array.getClass().getComponentType());
711
712 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c" }, 1, 2);
713 assertArrayEquals(new Object[] { "a" }, array);
714 assertEquals(Object.class, array.getClass().getComponentType());
715
716 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 1, 2);
717 assertArrayEquals(new Object[] { "a", "d" }, array);
718 assertEquals(Object.class, array.getClass().getComponentType());
719
720 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 3);
721 assertArrayEquals(new Object[] { "b", "c" }, array);
722 assertEquals(Object.class, array.getClass().getComponentType());
723
724 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 1, 3);
725 assertArrayEquals(new Object[] { "c" }, array);
726 assertEquals(Object.class, array.getClass().getComponentType());
727
728 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d", "e" }, 0, 1, 3);
729 assertArrayEquals(new Object[] { "c", "e" }, array);
730 assertEquals(Object.class, array.getClass().getComponentType());
731
732 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d", "e" }, 0, 2, 4);
733 assertArrayEquals(new Object[] { "b", "d" }, array);
734 assertEquals(Object.class, array.getClass().getComponentType());
735
736 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 0, 1, 3, 0, 1, 3);
737 assertArrayEquals(new Object[] { "c" }, array);
738 assertEquals(Object.class, array.getClass().getComponentType());
739
740 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 2, 1, 0, 3);
741 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
742 assertEquals(Object.class, array.getClass().getComponentType());
743
744 array = ArrayUtils.removeAll(new Object[] { "a", "b", "c", "d" }, 2, 0, 1, 3, 0, 2, 1, 3);
745 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
746 assertEquals(Object.class, array.getClass().getComponentType());
747 }
748
749 @Test
750 void testRemoveAllObjectArrayNegativeIndex() {
751 assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new Object[] { "a", "b" }, -1));
752 }
753
754 @Test
755 void testRemoveAllObjectArrayOutOfBoundsIndex() {
756 assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new Object[] { "a", "b" }, 2));
757 }
758
759 @Test
760 void testRemoveAllObjectArrayRemoveNone() {
761 final Object[] array1 = { "foo", "bar", "baz" };
762 final Object[] array2 = ArrayUtils.removeAll(array1);
763 assertNotSame(array1, array2);
764 assertArrayEquals(array1, array2);
765 assertEquals(Object.class, array2.getClass().getComponentType());
766 }
767
768 @Test
769 void testRemoveAllShortArray() {
770 short[] array;
771
772 array = ArrayUtils.removeAll(new short[] { 1 }, 0);
773 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
774 assertEquals(Short.TYPE, array.getClass().getComponentType());
775
776 array = ArrayUtils.removeAll(new short[] { 1, 2 }, 0);
777 assertArrayEquals(new short[]{2}, array);
778 assertEquals(Short.TYPE, array.getClass().getComponentType());
779
780 array = ArrayUtils.removeAll(new short[] { 1, 2 }, 1);
781 assertArrayEquals(new short[]{1}, array);
782 assertEquals(Short.TYPE, array.getClass().getComponentType());
783
784 array = ArrayUtils.removeAll(new short[] { 1, 2, 1 }, 1);
785 assertArrayEquals(new short[]{1, 1}, array);
786 assertEquals(Short.TYPE, array.getClass().getComponentType());
787
788 array = ArrayUtils.removeAll(new short[] { 1, 2 }, 0, 1);
789 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
790 assertEquals(Short.TYPE, array.getClass().getComponentType());
791
792 array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 0, 1);
793 assertArrayEquals(new short[]{3}, array);
794 assertEquals(Short.TYPE, array.getClass().getComponentType());
795
796 array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 1, 2);
797 assertArrayEquals(new short[]{1}, array);
798 assertEquals(Short.TYPE, array.getClass().getComponentType());
799
800 array = ArrayUtils.removeAll(new short[] { 1, 2, 3 }, 0, 2);
801 assertArrayEquals(new short[]{2}, array);
802 assertEquals(Short.TYPE, array.getClass().getComponentType());
803
804 array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5 }, 1, 3);
805 assertArrayEquals(new short[]{1, 3, 5}, array);
806 assertEquals(Short.TYPE, array.getClass().getComponentType());
807
808 array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5 }, 0, 2, 4);
809 assertArrayEquals(new short[]{2, 4}, array);
810 assertEquals(Short.TYPE, array.getClass().getComponentType());
811
812 array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5, 6, 7 }, 1, 3, 5);
813 assertArrayEquals(new short[]{1, 3, 5, 7}, array);
814 assertEquals(Short.TYPE, array.getClass().getComponentType());
815
816 array = ArrayUtils.removeAll(new short[] { 1, 2, 3, 4, 5, 6, 7 }, 0, 2, 4, 6);
817 assertArrayEquals(new short[]{2, 4, 6}, array);
818 assertEquals(Short.TYPE, array.getClass().getComponentType());
819 }
820
821 @Test
822 void testRemoveAllShortArrayNegativeIndex() {
823 assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new short[] { 1, 2 }, -1, 0));
824 }
825
826 @Test
827 void testRemoveAllShortArrayOutOfBoundsIndex() {
828 assertIndexOutOfBoundsException(() -> ArrayUtils.removeAll(new short[] { 1, 2 }, 2, 0));
829 }
830
831 @Test
832 void testRemoveAllShortArrayRemoveNone() {
833 final short[] array1 = { 1, 2 };
834 final short[] array2 = ArrayUtils.removeAll(array1);
835 assertNotSame(array1, array2);
836 assertArrayEquals(array1, array2);
837 assertEquals(short.class, array2.getClass().getComponentType());
838 }
839
840 @Test
841 void testRemoveElementBooleanArray() {
842 boolean[] array;
843
844 array = ArrayUtils.removeElements((boolean[]) null, true);
845 assertNull(array);
846
847 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BOOLEAN_ARRAY, true);
848 assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
849 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
850
851 array = ArrayUtils.removeElements(new boolean[] { true }, true);
852 assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
853 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
854
855 array = ArrayUtils.removeElements(new boolean[] { true, false }, true);
856 assertArrayEquals(new boolean[]{false}, array);
857 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
858
859 array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true);
860 assertArrayEquals(new boolean[]{false, true}, array);
861 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
862
863 array = ArrayUtils.removeElements((boolean[]) null, true, false);
864 assertNull(array);
865
866 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BOOLEAN_ARRAY, true, false);
867 assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
868 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
869
870 array = ArrayUtils.removeElements(new boolean[] { true }, true, false);
871 assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
872 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
873
874 array = ArrayUtils.removeElements(new boolean[] { true, false }, true, false);
875 assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
876 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
877
878 array = ArrayUtils.removeElements(new boolean[] { true, false }, 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, false);
883 assertArrayEquals(new boolean[]{true}, array);
884 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
885
886 array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true, true);
887 assertArrayEquals(new boolean[]{false}, array);
888 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
889
890 array = ArrayUtils.removeElements(new boolean[] { true, false, true }, true, true, true, true);
891 assertArrayEquals(new boolean[]{false}, array);
892 assertEquals(Boolean.TYPE, array.getClass().getComponentType());
893 }
894
895 @Test
896 void testRemoveElementByteArray() {
897 byte[] array;
898
899 array = ArrayUtils.removeElements((byte[]) null, (byte) 1);
900 assertNull(array);
901
902 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BYTE_ARRAY, (byte) 1);
903 assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
904 assertEquals(Byte.TYPE, array.getClass().getComponentType());
905
906 array = ArrayUtils.removeElements(new byte[] { 1 }, (byte) 1);
907 assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
908 assertEquals(Byte.TYPE, array.getClass().getComponentType());
909
910 array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (byte) 1);
911 assertArrayEquals(new byte[]{2}, array);
912 assertEquals(Byte.TYPE, array.getClass().getComponentType());
913
914 array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1);
915 assertArrayEquals(new byte[]{2, 1}, array);
916 assertEquals(Byte.TYPE, array.getClass().getComponentType());
917
918 array = ArrayUtils.removeElements((byte[]) null, (byte) 1, (byte) 2);
919 assertNull(array);
920
921 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_BYTE_ARRAY, (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 }, (byte) 1, (byte) 2);
926 assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
927 assertEquals(Byte.TYPE, array.getClass().getComponentType());
928
929 array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (byte) 1, (byte) 2);
930 assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
931 assertEquals(Byte.TYPE, array.getClass().getComponentType());
932
933 array = ArrayUtils.removeElements(new byte[] { 1, 2 }, (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) 2);
938 assertArrayEquals(new byte[]{1}, array);
939 assertEquals(Byte.TYPE, array.getClass().getComponentType());
940
941 array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1, (byte) 1);
942 assertArrayEquals(new byte[]{2}, array);
943 assertEquals(Byte.TYPE, array.getClass().getComponentType());
944
945 array = ArrayUtils.removeElements(new byte[] { 1, 2, 1 }, (byte) 1, (byte) 1, (byte) 1, (byte) 1);
946 assertArrayEquals(new byte[]{2}, array);
947 assertEquals(Byte.TYPE, array.getClass().getComponentType());
948 }
949
950 @Test
951 void testRemoveElementCharArray() {
952 char[] array;
953
954 array = ArrayUtils.removeElements((char[]) null, 'a');
955 assertNull(array);
956
957 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_CHAR_ARRAY, 'a');
958 assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
959 assertEquals(Character.TYPE, array.getClass().getComponentType());
960
961 array = ArrayUtils.removeElements(new char[] { 'a' }, 'a');
962 assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
963 assertEquals(Character.TYPE, array.getClass().getComponentType());
964
965 array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, 'a');
966 assertArrayEquals(new char[]{'b'}, array);
967 assertEquals(Character.TYPE, array.getClass().getComponentType());
968
969 array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a');
970 assertArrayEquals(new char[]{'b', 'a'}, array);
971 assertEquals(Character.TYPE, array.getClass().getComponentType());
972
973 array = ArrayUtils.removeElements((char[]) null, 'a', 'b');
974 assertNull(array);
975
976 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_CHAR_ARRAY, 'a', 'b');
977 assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
978 assertEquals(Character.TYPE, array.getClass().getComponentType());
979
980 array = ArrayUtils.removeElements(new char[] { 'a' }, 'a', 'b');
981 assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
982 assertEquals(Character.TYPE, array.getClass().getComponentType());
983
984 array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, 'a', 'b');
985 assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
986 assertEquals(Character.TYPE, array.getClass().getComponentType());
987
988 array = ArrayUtils.removeElements(new char[] { 'a', 'b' }, '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', 'b');
993 assertArrayEquals(new char[]{'a'}, array);
994 assertEquals(Character.TYPE, array.getClass().getComponentType());
995
996 array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a', 'a');
997 assertArrayEquals(new char[]{'b'}, array);
998 assertEquals(Character.TYPE, array.getClass().getComponentType());
999
1000 array = ArrayUtils.removeElements(new char[] { 'a', 'b', 'a' }, 'a', 'a', 'a', 'a');
1001 assertArrayEquals(new char[]{'b'}, array);
1002 assertEquals(Character.TYPE, array.getClass().getComponentType());
1003 }
1004
1005 @Test
1006 void testRemoveElementDoubleArray() {
1007 double[] array;
1008
1009 array = ArrayUtils.removeElements((double[]) null, (double) 1);
1010 assertNull(array);
1011
1012 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_DOUBLE_ARRAY, (double) 1);
1013 assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1014 assertEquals(Double.TYPE, array.getClass().getComponentType());
1015
1016 array = ArrayUtils.removeElements(new double[] { 1 }, (double) 1);
1017 assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1018 assertEquals(Double.TYPE, array.getClass().getComponentType());
1019
1020 array = ArrayUtils.removeElements(new double[] { 1, 2 }, (double) 1);
1021 assertArrayEquals(new double[]{2}, array);
1022 assertEquals(Double.TYPE, array.getClass().getComponentType());
1023
1024 array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, (double) 1);
1025 assertArrayEquals(new double[]{2, 1}, array);
1026 assertEquals(Double.TYPE, array.getClass().getComponentType());
1027
1028 array = ArrayUtils.removeElements((double[]) null, 1, 2);
1029 assertNull(array);
1030
1031 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2);
1032 assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1033 assertEquals(Double.TYPE, array.getClass().getComponentType());
1034
1035 array = ArrayUtils.removeElements(new double[] { 1 }, 1, 2);
1036 assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1037 assertEquals(Double.TYPE, array.getClass().getComponentType());
1038
1039 array = ArrayUtils.removeElements(new double[] { 1, 2 }, 1, 2);
1040 assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
1041 assertEquals(Double.TYPE, array.getClass().getComponentType());
1042
1043 array = ArrayUtils.removeElements(new double[] { 1, 2 }, 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, 2);
1048 assertArrayEquals(new double[]{1}, array);
1049 assertEquals(Double.TYPE, array.getClass().getComponentType());
1050
1051 array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, 1, 1);
1052 assertArrayEquals(new double[]{2}, array);
1053 assertEquals(Double.TYPE, array.getClass().getComponentType());
1054
1055 array = ArrayUtils.removeElements(new double[] { 1, 2, 1 }, 1, 1, 1, 1);
1056 assertArrayEquals(new double[]{2}, array);
1057 assertEquals(Double.TYPE, array.getClass().getComponentType());
1058 }
1059
1060 @Test
1061 void testRemoveElementFloatArray() {
1062 float[] array;
1063
1064 array = ArrayUtils.removeElements((float[]) null, (float) 1);
1065 assertNull(array);
1066
1067 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_FLOAT_ARRAY, (float) 1);
1068 assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1069 assertEquals(Float.TYPE, array.getClass().getComponentType());
1070
1071 array = ArrayUtils.removeElements(new float[] { 1 }, (float) 1);
1072 assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1073 assertEquals(Float.TYPE, array.getClass().getComponentType());
1074
1075 array = ArrayUtils.removeElements(new float[] { 1, 2 }, (float) 1);
1076 assertArrayEquals(new float[]{2}, array);
1077 assertEquals(Float.TYPE, array.getClass().getComponentType());
1078
1079 array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, (float) 1);
1080 assertArrayEquals(new float[]{2, 1}, array);
1081 assertEquals(Float.TYPE, array.getClass().getComponentType());
1082
1083 array = ArrayUtils.removeElements((float[]) null, 1, 1);
1084 assertNull(array);
1085
1086 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 1);
1087 assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1088 assertEquals(Float.TYPE, array.getClass().getComponentType());
1089
1090 array = ArrayUtils.removeElements(new float[] { 1 }, 1, 1);
1091 assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1092 assertEquals(Float.TYPE, array.getClass().getComponentType());
1093
1094 array = ArrayUtils.removeElements(new float[] { 1, 2 }, 1, 2);
1095 assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
1096 assertEquals(Float.TYPE, array.getClass().getComponentType());
1097
1098 array = ArrayUtils.removeElements(new float[] { 1, 2 }, 1, 1);
1099 assertArrayEquals(new float[]{2}, array);
1100 assertEquals(Float.TYPE, array.getClass().getComponentType());
1101
1102 array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 1);
1103 assertArrayEquals(new float[]{2}, array);
1104 assertEquals(Float.TYPE, array.getClass().getComponentType());
1105
1106 array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 2);
1107 assertArrayEquals(new float[]{1}, array);
1108 assertEquals(Float.TYPE, array.getClass().getComponentType());
1109
1110 array = ArrayUtils.removeElements(new float[] { 1, 2, 1 }, 1, 1, 1, 1);
1111 assertArrayEquals(new float[]{2}, array);
1112 assertEquals(Float.TYPE, array.getClass().getComponentType());
1113 }
1114
1115 @Test
1116 void testRemoveElementIntArray() {
1117 int[] array;
1118
1119 array = ArrayUtils.removeElements((int[]) null, 1);
1120 assertNull(array);
1121
1122 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_INT_ARRAY, 1);
1123 assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1124 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1125
1126 array = ArrayUtils.removeElements(new int[] { 1 }, 1);
1127 assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1128 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1129
1130 array = ArrayUtils.removeElements(new int[] { 1, 2 }, 1);
1131 assertArrayEquals(new int[]{2}, array);
1132 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1133
1134 array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1);
1135 assertArrayEquals(new int[]{2, 1}, array);
1136 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1137
1138 array = ArrayUtils.removeElements((int[]) null, 1);
1139 assertNull(array);
1140
1141 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_INT_ARRAY, 1, 1);
1142 assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1143 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1144
1145 array = ArrayUtils.removeElements(new int[] { 1 }, 1, 1);
1146 assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1147 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1148
1149 array = ArrayUtils.removeElements(new int[] { 1, 2 }, 1, 2);
1150 assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
1151 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1152
1153 array = ArrayUtils.removeElements(new int[] { 1, 2 }, 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, 2);
1158 assertArrayEquals(new int[]{1}, array);
1159 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1160
1161 array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1, 1);
1162 assertArrayEquals(new int[]{2}, array);
1163 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1164
1165 array = ArrayUtils.removeElements(new int[] { 1, 2, 1 }, 1, 1, 1, 1);
1166 assertArrayEquals(new int[]{2}, array);
1167 assertEquals(Integer.TYPE, array.getClass().getComponentType());
1168 }
1169
1170 @Test
1171 void testRemoveElementLongArray() {
1172 long[] array;
1173
1174 array = ArrayUtils.removeElements((long[]) null, 1L);
1175 assertNull(array);
1176
1177 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L);
1178 assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1179 assertEquals(Long.TYPE, array.getClass().getComponentType());
1180
1181 array = ArrayUtils.removeElements(new long[] { 1 }, 1L);
1182 assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1183 assertEquals(Long.TYPE, array.getClass().getComponentType());
1184
1185 array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L);
1186 assertArrayEquals(new long[]{2}, array);
1187 assertEquals(Long.TYPE, array.getClass().getComponentType());
1188
1189 array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L);
1190 assertArrayEquals(new long[]{2, 1}, array);
1191 assertEquals(Long.TYPE, array.getClass().getComponentType());
1192
1193 array = ArrayUtils.removeElements((long[]) null, 1L, 1L);
1194 assertNull(array);
1195
1196 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_LONG_ARRAY, 1L, 1L);
1197 assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1198 assertEquals(Long.TYPE, array.getClass().getComponentType());
1199
1200 array = ArrayUtils.removeElements(new long[] { 1 }, 1L, 1L);
1201 assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1202 assertEquals(Long.TYPE, array.getClass().getComponentType());
1203
1204 array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 2L);
1205 assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
1206 assertEquals(Long.TYPE, array.getClass().getComponentType());
1207
1208 array = ArrayUtils.removeElements(new long[] { 1, 2 }, 1L, 1L);
1209 assertArrayEquals(new long[]{2}, array);
1210 assertEquals(Long.TYPE, array.getClass().getComponentType());
1211
1212 array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L);
1213 assertArrayEquals(new long[]{2}, array);
1214 assertEquals(Long.TYPE, array.getClass().getComponentType());
1215
1216 array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 2L);
1217 assertArrayEquals(new long[]{1}, array);
1218 assertEquals(Long.TYPE, array.getClass().getComponentType());
1219
1220 array = ArrayUtils.removeElements(new long[] { 1, 2, 1 }, 1L, 1L, 1L, 1L);
1221 assertArrayEquals(new long[]{2}, array);
1222 assertEquals(Long.TYPE, array.getClass().getComponentType());
1223 }
1224
1225 @Test
1226 void testRemoveElementShortArray() {
1227 short[] array;
1228
1229 array = ArrayUtils.removeElements((short[]) null, (short) 1);
1230 assertNull(array);
1231
1232 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_SHORT_ARRAY, (short) 1);
1233 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1234 assertEquals(Short.TYPE, array.getClass().getComponentType());
1235
1236 array = ArrayUtils.removeElements(new short[] { 1 }, (short) 1);
1237 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1238 assertEquals(Short.TYPE, array.getClass().getComponentType());
1239
1240 array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1);
1241 assertArrayEquals(new short[]{2}, array);
1242 assertEquals(Short.TYPE, array.getClass().getComponentType());
1243
1244 array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1);
1245 assertArrayEquals(new short[]{2, 1}, array);
1246 assertEquals(Short.TYPE, array.getClass().getComponentType());
1247
1248 array = ArrayUtils.removeElements((short[]) null, (short) 1, (short) 1);
1249 assertNull(array);
1250
1251 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_SHORT_ARRAY, (short) 1, (short) 1);
1252 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1253 assertEquals(Short.TYPE, array.getClass().getComponentType());
1254
1255 array = ArrayUtils.removeElements(new short[] { 1 }, (short) 1, (short) 1);
1256 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1257 assertEquals(Short.TYPE, array.getClass().getComponentType());
1258
1259 array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1, (short) 2);
1260 assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
1261 assertEquals(Short.TYPE, array.getClass().getComponentType());
1262
1263 array = ArrayUtils.removeElements(new short[] { 1, 2 }, (short) 1, (short) 1);
1264 assertArrayEquals(new short[]{2}, array);
1265 assertEquals(Short.TYPE, array.getClass().getComponentType());
1266
1267 array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 1);
1268 assertArrayEquals(new short[]{2}, array);
1269 assertEquals(Short.TYPE, array.getClass().getComponentType());
1270
1271 array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 2);
1272 assertArrayEquals(new short[]{1}, array);
1273 assertEquals(Short.TYPE, array.getClass().getComponentType());
1274
1275 array = ArrayUtils.removeElements(new short[] { 1, 2, 1 }, (short) 1, (short) 1, (short) 1, (short) 1);
1276 assertArrayEquals(new short[]{2}, array);
1277 assertEquals(Short.TYPE, array.getClass().getComponentType());
1278 }
1279
1280 @Test
1281 void testRemoveElementsObjectArray() {
1282 Object[] array;
1283
1284 array = ArrayUtils.removeElements((Object[]) null, "a");
1285 assertNull(array);
1286
1287 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_OBJECT_ARRAY, "a");
1288 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1289 assertEquals(Object.class, array.getClass().getComponentType());
1290
1291 array = ArrayUtils.removeElements(new Object[] { "a" }, "a");
1292 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1293 assertEquals(Object.class, array.getClass().getComponentType());
1294
1295 array = ArrayUtils.removeElements(new Object[] { "a", "b" }, "a");
1296 assertArrayEquals(new Object[]{"b"}, array);
1297 assertEquals(Object.class, array.getClass().getComponentType());
1298
1299 array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a");
1300 assertArrayEquals(new Object[]{"b", "a"}, array);
1301 assertEquals(Object.class, array.getClass().getComponentType());
1302
1303 array = ArrayUtils.removeElements((Object[]) null, "a", "b");
1304 assertNull(array);
1305
1306 array = ArrayUtils.removeElements(ArrayUtils.EMPTY_OBJECT_ARRAY, "a", "b");
1307 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1308 assertEquals(Object.class, array.getClass().getComponentType());
1309
1310 array = ArrayUtils.removeElements(new Object[] { "a" }, "a", "b");
1311 assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
1312 assertEquals(Object.class, array.getClass().getComponentType());
1313
1314 array = ArrayUtils.removeElements(new Object[] { "a", "b" }, "a", "c");
1315 assertArrayEquals(new Object[]{"b"}, array);
1316 assertEquals(Object.class, array.getClass().getComponentType());
1317
1318 array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a");
1319 assertArrayEquals(new Object[]{"b", "a"}, array);
1320 assertEquals(Object.class, array.getClass().getComponentType());
1321
1322 array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "b");
1323 assertArrayEquals(new Object[]{"a"}, array);
1324 assertEquals(Object.class, array.getClass().getComponentType());
1325
1326 array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "a");
1327 assertArrayEquals(new Object[]{"b"}, array);
1328 assertEquals(Object.class, array.getClass().getComponentType());
1329
1330 array = ArrayUtils.removeElements(new Object[] { "a", "b", "a" }, "a", "a", "a", "a");
1331 assertArrayEquals(new Object[]{"b"}, array);
1332 assertEquals(Object.class, array.getClass().getComponentType());
1333 }
1334
1335 }