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    *      http://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.junit.jupiter.api.Assertions.assertArrayEquals;
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  import static org.junit.jupiter.api.Assertions.assertThrows;
24  
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Tests ArrayUtils remove and removeElement methods.
29   */
30  public class ArrayUtilsRemoveTest extends AbstractLangTest {
31  
32      @Test
33      public void testRemoveAllBooleanOccurences() {
34          boolean[] a = null;
35          assertNull(ArrayUtils.removeAllOccurences(a, true));
36  
37          a = new boolean[0];
38          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
39  
40          a = new boolean[] { true };
41          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
42  
43          a = new boolean[] { true, true };
44          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurences(a, true));
45  
46          a = new boolean[] { false, true, true, false, true };
47          assertArrayEquals(new boolean[]{false, false}, ArrayUtils.removeAllOccurences(a, true));
48  
49          a = new boolean[] { false, true, true, false, true };
50          assertArrayEquals(new boolean[]{true, true, true}, ArrayUtils.removeAllOccurences(a, false));
51      }
52  
53      @Test
54      public void testRemoveAllBooleanOccurrences() {
55          boolean[] a = null;
56          assertNull(ArrayUtils.removeAllOccurrences(a, true));
57  
58          a = new boolean[0];
59          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
60  
61          a = new boolean[] { true };
62          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
63  
64          a = new boolean[] { true, true };
65          assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.removeAllOccurrences(a, true));
66  
67          a = new boolean[] { false, true, true, false, true };
68          assertArrayEquals(new boolean[]{false, false}, ArrayUtils.removeAllOccurrences(a, true));
69  
70          a = new boolean[] { false, true, true, false, true };
71          assertArrayEquals(new boolean[]{true, true, true}, ArrayUtils.removeAllOccurrences(a, false));
72      }
73  
74      @Test
75      public void testRemoveAllByteOccurences() {
76          byte[] a = null;
77          assertNull(ArrayUtils.removeAllOccurences(a, (byte) 2));
78  
79          a = new byte[0];
80          assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
81  
82          a = new byte[] { 2 };
83          assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
84  
85          a = new byte[] { 2, 2 };
86          assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurences(a, (byte) 2));
87  
88          a = new byte[] { 1, 2, 2, 3, 2 };
89          assertArrayEquals(new byte[]{1, 3}, ArrayUtils.removeAllOccurences(a, (byte) 2));
90  
91          a = new byte[] { 1, 2, 2, 3, 2 };
92          assertArrayEquals(new byte[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (byte) 4));
93      }
94  
95      @Test
96      public void testRemoveAllByteOccurrences() {
97          byte[] a = null;
98          assertNull(ArrayUtils.removeAllOccurrences(a, (byte) 2));
99  
100         a = new byte[0];
101         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
102 
103         a = new byte[] { 2 };
104         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
105 
106         a = new byte[] { 2, 2 };
107         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.removeAllOccurrences(a, (byte) 2));
108 
109         a = new byte[] { 1, 2, 2, 3, 2 };
110         assertArrayEquals(new byte[]{1, 3}, ArrayUtils.removeAllOccurrences(a, (byte) 2));
111 
112         a = new byte[] { 1, 2, 2, 3, 2 };
113         assertArrayEquals(new byte[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, (byte) 4));
114     }
115 
116     @Test
117     public void testRemoveAllCharOccurences() {
118         char[] a = null;
119         assertNull(ArrayUtils.removeAllOccurences(a, '2'));
120 
121         a = new char[0];
122         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
123 
124         a = new char[] { '2' };
125         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
126 
127         a = new char[] { '2', '2' };
128         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurences(a, '2'));
129 
130         a = new char[] { '1', '2', '2', '3', '2' };
131         assertArrayEquals(new char[]{'1', '3'}, ArrayUtils.removeAllOccurences(a, '2'));
132 
133         a = new char[] { '1', '2', '2', '3', '2' };
134         assertArrayEquals(new char[]{'1', '2', '2', '3', '2'}, ArrayUtils.removeAllOccurences(a, '4'));
135     }
136 
137     @Test
138     public void testRemoveAllCharOccurrences() {
139         char[] a = null;
140         assertNull(ArrayUtils.removeAllOccurrences(a, '2'));
141 
142         a = new char[0];
143         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
144 
145         a = new char[] { '2' };
146         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
147 
148         a = new char[] { '2', '2' };
149         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.removeAllOccurrences(a, '2'));
150 
151         a = new char[] { '1', '2', '2', '3', '2' };
152         assertArrayEquals(new char[]{'1', '3'}, ArrayUtils.removeAllOccurrences(a, '2'));
153 
154         a = new char[] { '1', '2', '2', '3', '2' };
155         assertArrayEquals(new char[]{'1', '2', '2', '3', '2'}, ArrayUtils.removeAllOccurrences(a, '4'));
156     }
157 
158     @Test
159     public void testRemoveAllDoubleOccurences() {
160         double[] a = null;
161         assertNull(ArrayUtils.removeAllOccurences(a, 2));
162 
163         a = new double[0];
164         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
165 
166         a = new double[] { 2 };
167         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
168 
169         a = new double[] { 2, 2 };
170         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
171 
172         a = new double[] { 1, 2, 2, 3, 2 };
173         assertArrayEquals(new double[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
174 
175         a = new double[] { 1, 2, 2, 3, 2 };
176         assertArrayEquals(new double[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
177     }
178 
179     @Test
180     public void testRemoveAllDoubleOccurrences() {
181         double[] a = null;
182         assertNull(ArrayUtils.removeAllOccurrences(a, 2));
183 
184         a = new double[0];
185         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
186 
187         a = new double[] { 2 };
188         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
189 
190         a = new double[] { 2, 2 };
191         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
192 
193         a = new double[] { 1, 2, 2, 3, 2 };
194         assertArrayEquals(new double[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
195 
196         a = new double[] { 1, 2, 2, 3, 2 };
197         assertArrayEquals(new double[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
198     }
199 
200     @Test
201     public void testRemoveAllFloatOccurences() {
202         float[] a = null;
203         assertNull(ArrayUtils.removeAllOccurences(a, 2));
204 
205         a = new float[0];
206         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
207 
208         a = new float[] { 2 };
209         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
210 
211         a = new float[] { 2, 2 };
212         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
213 
214         a = new float[] { 1, 2, 2, 3, 2 };
215         assertArrayEquals(new float[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
216 
217         a = new float[] { 1, 2, 2, 3, 2 };
218         assertArrayEquals(new float[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
219     }
220 
221     @Test
222     public void testRemoveAllFloatOccurrences() {
223         float[] a = null;
224         assertNull(ArrayUtils.removeAllOccurrences(a, 2));
225 
226         a = new float[0];
227         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
228 
229         a = new float[] { 2 };
230         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
231 
232         a = new float[] { 2, 2 };
233         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
234 
235         a = new float[] { 1, 2, 2, 3, 2 };
236         assertArrayEquals(new float[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
237 
238         a = new float[] { 1, 2, 2, 3, 2 };
239         assertArrayEquals(new float[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
240     }
241 
242     @Test
243     public void testRemoveAllIntOccurences() {
244         int[] a = null;
245         assertNull(ArrayUtils.removeAllOccurences(a, 2));
246 
247         a = new int[0];
248         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
249 
250         a = new int[] { 2 };
251         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
252 
253         a = new int[] { 2, 2 };
254         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
255 
256         a = new int[] { 1, 2, 2, 3, 2 };
257         assertArrayEquals(new int[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
258 
259         a = new int[] { 1, 2, 2, 3, 2 };
260         assertArrayEquals(new int[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
261     }
262 
263     @Test
264     public void testRemoveAllIntOccurrences() {
265         int[] a = null;
266         assertNull(ArrayUtils.removeAllOccurrences(a, 2));
267 
268         a = new int[0];
269         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
270 
271         a = new int[] { 2 };
272         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
273 
274         a = new int[] { 2, 2 };
275         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
276 
277         a = new int[] { 1, 2, 2, 3, 2 };
278         assertArrayEquals(new int[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
279 
280         a = new int[] { 1, 2, 2, 3, 2 };
281         assertArrayEquals(new int[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
282     }
283 
284     @Test
285     public void testRemoveAllLongOccurences() {
286         long[] a = null;
287         assertNull(ArrayUtils.removeAllOccurences(a, 2));
288 
289         a = new long[0];
290         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
291 
292         a = new long[] { 2 };
293         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
294 
295         a = new long[] { 2, 2 };
296         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurences(a, 2));
297 
298         a = new long[] { 1, 2, 2, 3, 2 };
299         assertArrayEquals(new long[]{1, 3}, ArrayUtils.removeAllOccurences(a, 2));
300 
301         a = new long[] { 1, 2, 2, 3, 2 };
302         assertArrayEquals(new long[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, 4));
303     }
304 
305     @Test
306     public void testRemoveAllLongOccurrences() {
307         long[] a = null;
308         assertNull(ArrayUtils.removeAllOccurrences(a, 2));
309 
310         a = new long[0];
311         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
312 
313         a = new long[] { 2 };
314         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
315 
316         a = new long[] { 2, 2 };
317         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.removeAllOccurrences(a, 2));
318 
319         a = new long[] { 1, 2, 2, 3, 2 };
320         assertArrayEquals(new long[]{1, 3}, ArrayUtils.removeAllOccurrences(a, 2));
321 
322         a = new long[] { 1, 2, 2, 3, 2 };
323         assertArrayEquals(new long[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, 4));
324     }
325 
326     @Test
327     public void testRemoveAllObjectOccurences() {
328         String[] a = null;
329         assertNull(ArrayUtils.removeAllOccurences(a, "2"));
330 
331         a = new String[0];
332         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
333 
334         a = new String[] { "2" };
335         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
336 
337         a = new String[] { "2", "2" };
338         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurences(a, "2"));
339 
340         a = new String[] { "1", "2", "2", "3", "2" };
341         assertArrayEquals(new String[]{"1", "3"}, ArrayUtils.removeAllOccurences(a, "2"));
342 
343         a = new String[] { "1", "2", "2", "3", "2" };
344         assertArrayEquals(new String[]{"1", "2", "2", "3", "2"}, ArrayUtils.removeAllOccurences(a, "4"));
345     }
346 
347     @Test
348     public void testRemoveAllObjectOccurrences() {
349         String[] a = null;
350         assertNull(ArrayUtils.removeAllOccurrences(a, "2"));
351 
352         a = new String[0];
353         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
354 
355         a = new String[] { "2" };
356         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
357 
358         a = new String[] { "2", "2" };
359         assertArrayEquals(ArrayUtils.EMPTY_STRING_ARRAY, ArrayUtils.removeAllOccurrences(a, "2"));
360 
361         a = new String[] { "1", "2", "2", "3", "2" };
362         assertArrayEquals(new String[]{"1", "3"}, ArrayUtils.removeAllOccurrences(a, "2"));
363 
364         a = new String[] { "1", "2", "2", "3", "2" };
365         assertArrayEquals(new String[]{"1", "2", "2", "3", "2"}, ArrayUtils.removeAllOccurrences(a, "4"));
366     }
367 
368     @Test
369     public void testRemoveAllShortOccurences() {
370         short[] a = null;
371         assertNull(ArrayUtils.removeAllOccurences(a, (short) 2));
372 
373         a = new short[0];
374         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
375 
376         a = new short[] { 2 };
377         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
378 
379         a = new short[] { 2, 2 };
380         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurences(a, (short) 2));
381 
382         a = new short[] { 1, 2, 2, 3, 2 };
383         assertArrayEquals(new short[]{1, 3}, ArrayUtils.removeAllOccurences(a, (short) 2));
384 
385         a = new short[] { 1, 2, 2, 3, 2 };
386         assertArrayEquals(new short[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurences(a, (short) 4));
387     }
388 
389     @Test
390     public void testRemoveAllShortOccurrences() {
391         short[] a = null;
392         assertNull(ArrayUtils.removeAllOccurrences(a, (short) 2));
393 
394         a = new short[0];
395         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
396 
397         a = new short[] { 2 };
398         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
399 
400         a = new short[] { 2, 2 };
401         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.removeAllOccurrences(a, (short) 2));
402 
403         a = new short[] { 1, 2, 2, 3, 2 };
404         assertArrayEquals(new short[]{1, 3}, ArrayUtils.removeAllOccurrences(a, (short) 2));
405 
406         a = new short[] { 1, 2, 2, 3, 2 };
407         assertArrayEquals(new short[]{1, 2, 2, 3, 2}, ArrayUtils.removeAllOccurrences(a, (short) 4));
408     }
409 
410     @Test
411     public void testRemoveBooleanArray() {
412         boolean[] array;
413         array = ArrayUtils.remove(new boolean[] {true}, 0);
414         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
415         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
416         array = ArrayUtils.remove(new boolean[] {true, false}, 0);
417         assertArrayEquals(new boolean[]{false}, array);
418         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
419         array = ArrayUtils.remove(new boolean[] {true, false}, 1);
420         assertArrayEquals(new boolean[]{true}, array);
421         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
422         array = ArrayUtils.remove(new boolean[] {true, false, true}, 1);
423         assertArrayEquals(new boolean[]{true, true}, array);
424         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
425         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new boolean[] {true, false}, -1));
426         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new boolean[] {true, false}, 2));
427         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((boolean[]) null, 0));
428     }
429 
430     @Test
431     public void testRemoveByteArray() {
432         byte[] array;
433         array = ArrayUtils.remove(new byte[] {1}, 0);
434         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
435         assertEquals(Byte.TYPE, array.getClass().getComponentType());
436         array = ArrayUtils.remove(new byte[] {1, 2}, 0);
437         assertArrayEquals(new byte[]{2}, array);
438         assertEquals(Byte.TYPE, array.getClass().getComponentType());
439         array = ArrayUtils.remove(new byte[] {1, 2}, 1);
440         assertArrayEquals(new byte[]{1}, array);
441         assertEquals(Byte.TYPE, array.getClass().getComponentType());
442         array = ArrayUtils.remove(new byte[] {1, 2, 1}, 1);
443         assertArrayEquals(new byte[]{1, 1}, array);
444         assertEquals(Byte.TYPE, array.getClass().getComponentType());
445         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new byte[] {1, 2}, -1));
446         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new byte[] {1, 2}, 2));
447         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((byte[]) null, 0));
448     }
449 
450     @Test
451     public void testRemoveCharArray() {
452         char[] array;
453         array = ArrayUtils.remove(new char[] {'a'}, 0);
454         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
455         assertEquals(Character.TYPE, array.getClass().getComponentType());
456         array = ArrayUtils.remove(new char[] {'a', 'b'}, 0);
457         assertArrayEquals(new char[]{'b'}, array);
458         assertEquals(Character.TYPE, array.getClass().getComponentType());
459         array = ArrayUtils.remove(new char[] {'a', 'b'}, 1);
460         assertArrayEquals(new char[]{'a'}, array);
461         assertEquals(Character.TYPE, array.getClass().getComponentType());
462         array = ArrayUtils.remove(new char[] {'a', 'b', 'c'}, 1);
463         assertArrayEquals(new char[]{'a', 'c'}, array);
464         assertEquals(Character.TYPE, array.getClass().getComponentType());
465         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new char[] {'a', 'b'}, -1));
466         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new char[] {'a', 'b'}, 2));
467         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((char[]) null, 0));
468     }
469 
470     @Test
471     public void testRemoveDoubleArray() {
472         double[] array;
473         array = ArrayUtils.remove(new double[] {1}, 0);
474         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
475         assertEquals(Double.TYPE, array.getClass().getComponentType());
476         array = ArrayUtils.remove(new double[] {1, 2}, 0);
477         assertArrayEquals(new double[]{2}, array);
478         assertEquals(Double.TYPE, array.getClass().getComponentType());
479         array = ArrayUtils.remove(new double[] {1, 2}, 1);
480         assertArrayEquals(new double[]{1}, array);
481         assertEquals(Double.TYPE, array.getClass().getComponentType());
482         array = ArrayUtils.remove(new double[] {1, 2, 1}, 1);
483         assertArrayEquals(new double[]{1, 1}, array);
484         assertEquals(Double.TYPE, array.getClass().getComponentType());
485         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new double[] {1, 2}, -1));
486         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new double[] {1, 2}, 2));
487         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((double[]) null, 0));
488     }
489 
490     @Test
491     public void testRemoveElementBooleanArray() {
492         boolean[] array;
493         array = ArrayUtils.removeElement(null, true);
494         assertNull(array);
495         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_BOOLEAN_ARRAY, true);
496         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
497         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
498         array = ArrayUtils.removeElement(new boolean[] {true}, true);
499         assertArrayEquals(ArrayUtils.EMPTY_BOOLEAN_ARRAY, array);
500         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
501         array = ArrayUtils.removeElement(new boolean[] {true, false}, true);
502         assertArrayEquals(new boolean[]{false}, array);
503         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
504         array = ArrayUtils.removeElement(new boolean[] {true, false, true}, true);
505         assertArrayEquals(new boolean[]{false, true}, array);
506         assertEquals(Boolean.TYPE, array.getClass().getComponentType());
507     }
508 
509     @Test
510     public void testRemoveElementByteArray() {
511         byte[] array;
512         array = ArrayUtils.removeElement((byte[]) null, (byte) 1);
513         assertNull(array);
514         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_BYTE_ARRAY, (byte) 1);
515         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
516         assertEquals(Byte.TYPE, array.getClass().getComponentType());
517         array = ArrayUtils.removeElement(new byte[] {1}, (byte) 1);
518         assertArrayEquals(ArrayUtils.EMPTY_BYTE_ARRAY, array);
519         assertEquals(Byte.TYPE, array.getClass().getComponentType());
520         array = ArrayUtils.removeElement(new byte[] {1, 2}, (byte) 1);
521         assertArrayEquals(new byte[]{2}, array);
522         assertEquals(Byte.TYPE, array.getClass().getComponentType());
523         array = ArrayUtils.removeElement(new byte[] {1, 2, 1}, (byte) 1);
524         assertArrayEquals(new byte[]{2, 1}, array);
525         assertEquals(Byte.TYPE, array.getClass().getComponentType());
526     }
527 
528     @Test
529     public void testRemoveElementCharArray() {
530         char[] array;
531         array = ArrayUtils.removeElement((char[]) null, 'a');
532         assertNull(array);
533         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_CHAR_ARRAY, 'a');
534         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
535         assertEquals(Character.TYPE, array.getClass().getComponentType());
536         array = ArrayUtils.removeElement(new char[] {'a'}, 'a');
537         assertArrayEquals(ArrayUtils.EMPTY_CHAR_ARRAY, array);
538         assertEquals(Character.TYPE, array.getClass().getComponentType());
539         array = ArrayUtils.removeElement(new char[] {'a', 'b'}, 'a');
540         assertArrayEquals(new char[]{'b'}, array);
541         assertEquals(Character.TYPE, array.getClass().getComponentType());
542         array = ArrayUtils.removeElement(new char[] {'a', 'b', 'a'}, 'a');
543         assertArrayEquals(new char[]{'b', 'a'}, array);
544         assertEquals(Character.TYPE, array.getClass().getComponentType());
545     }
546 
547     @Test
548     @SuppressWarnings("cast")
549     public void testRemoveElementDoubleArray() {
550         double[] array;
551         array = ArrayUtils.removeElement(null, (double) 1);
552         assertNull(array);
553         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_DOUBLE_ARRAY, (double) 1);
554         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
555         assertEquals(Double.TYPE, array.getClass().getComponentType());
556         array = ArrayUtils.removeElement(new double[] {1}, (double) 1);
557         assertArrayEquals(ArrayUtils.EMPTY_DOUBLE_ARRAY, array);
558         assertEquals(Double.TYPE, array.getClass().getComponentType());
559         array = ArrayUtils.removeElement(new double[] {1, 2}, (double) 1);
560         assertArrayEquals(new double[]{2}, array);
561         assertEquals(Double.TYPE, array.getClass().getComponentType());
562         array = ArrayUtils.removeElement(new double[] {1, 2, 1}, (double) 1);
563         assertArrayEquals(new double[]{2, 1}, array);
564         assertEquals(Double.TYPE, array.getClass().getComponentType());
565     }
566 
567     @Test
568     @SuppressWarnings("cast")
569     public void testRemoveElementFloatArray() {
570         float[] array;
571         array = ArrayUtils.removeElement((float[]) null, (float) 1);
572         assertNull(array);
573         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_FLOAT_ARRAY, (float) 1);
574         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
575         assertEquals(Float.TYPE, array.getClass().getComponentType());
576         array = ArrayUtils.removeElement(new float[] {1}, (float) 1);
577         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
578         assertEquals(Float.TYPE, array.getClass().getComponentType());
579         array = ArrayUtils.removeElement(new float[] {1, 2}, (float) 1);
580         assertArrayEquals(new float[]{2}, array);
581         assertEquals(Float.TYPE, array.getClass().getComponentType());
582         array = ArrayUtils.removeElement(new float[] {1, 2, 1}, (float) 1);
583         assertArrayEquals(new float[]{2, 1}, array);
584         assertEquals(Float.TYPE, array.getClass().getComponentType());
585     }
586 
587     @Test
588     public void testRemoveElementIntArray() {
589         int[] array;
590         array = ArrayUtils.removeElement((int[]) null, 1);
591         assertNull(array);
592         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_INT_ARRAY, 1);
593         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
594         assertEquals(Integer.TYPE, array.getClass().getComponentType());
595         array = ArrayUtils.removeElement(new int[] {1}, 1);
596         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
597         assertEquals(Integer.TYPE, array.getClass().getComponentType());
598         array = ArrayUtils.removeElement(new int[] {1, 2}, 1);
599         assertArrayEquals(new int[]{2}, array);
600         assertEquals(Integer.TYPE, array.getClass().getComponentType());
601         array = ArrayUtils.removeElement(new int[] {1, 2, 1}, 1);
602         assertArrayEquals(new int[]{2, 1}, array);
603         assertEquals(Integer.TYPE, array.getClass().getComponentType());
604     }
605 
606 
607     @Test
608     public void testRemoveElementLongArray() {
609         long[] array;
610         array = ArrayUtils.removeElement((long[]) null, 1L);
611         assertNull(array);
612         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_LONG_ARRAY, 1L);
613         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
614         assertEquals(Long.TYPE, array.getClass().getComponentType());
615         array = ArrayUtils.removeElement(new long[] {1}, 1L);
616         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
617         assertEquals(Long.TYPE, array.getClass().getComponentType());
618         array = ArrayUtils.removeElement(new long[] {1, 2}, 1L);
619         assertArrayEquals(new long[]{2}, array);
620         assertEquals(Long.TYPE, array.getClass().getComponentType());
621         array = ArrayUtils.removeElement(new long[] {1, 2, 1}, 1L);
622         assertArrayEquals(new long[]{2, 1}, array);
623         assertEquals(Long.TYPE, array.getClass().getComponentType());
624     }
625 
626     @Test
627     public void testRemoveElementObjectArray() {
628         Object[] array;
629         array = ArrayUtils.removeElement(null, "a");
630         assertNull(array);
631         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_OBJECT_ARRAY, "a");
632         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
633         assertEquals(Object.class, array.getClass().getComponentType());
634         array = ArrayUtils.removeElement(new Object[] {"a"}, "a");
635         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
636         assertEquals(Object.class, array.getClass().getComponentType());
637         array = ArrayUtils.removeElement(new Object[] {"a", "b"}, "a");
638         assertArrayEquals(new Object[]{"b"}, array);
639         assertEquals(Object.class, array.getClass().getComponentType());
640         array = ArrayUtils.removeElement(new Object[] {"a", "b", "a"}, "a");
641         assertArrayEquals(new Object[]{"b", "a"}, array);
642         assertEquals(Object.class, array.getClass().getComponentType());
643     }
644 
645     @Test
646     public void testRemoveElementShortArray() {
647         short[] array;
648         array = ArrayUtils.removeElement((short[]) null, (short) 1);
649         assertNull(array);
650         array = ArrayUtils.removeElement(ArrayUtils.EMPTY_SHORT_ARRAY, (short) 1);
651         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
652         assertEquals(Short.TYPE, array.getClass().getComponentType());
653         array = ArrayUtils.removeElement(new short[] {1}, (short) 1);
654         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
655         assertEquals(Short.TYPE, array.getClass().getComponentType());
656         array = ArrayUtils.removeElement(new short[] {1, 2}, (short) 1);
657         assertArrayEquals(new short[]{2}, array);
658         assertEquals(Short.TYPE, array.getClass().getComponentType());
659         array = ArrayUtils.removeElement(new short[] {1, 2, 1}, (short) 1);
660         assertArrayEquals(new short[]{2, 1}, array);
661         assertEquals(Short.TYPE, array.getClass().getComponentType());
662     }
663 
664     @Test
665     public void testRemoveFloatArray() {
666         float[] array;
667         array = ArrayUtils.remove(new float[] {1}, 0);
668         assertArrayEquals(ArrayUtils.EMPTY_FLOAT_ARRAY, array);
669         assertEquals(Float.TYPE, array.getClass().getComponentType());
670         array = ArrayUtils.remove(new float[] {1, 2}, 0);
671         assertArrayEquals(new float[]{2}, array);
672         assertEquals(Float.TYPE, array.getClass().getComponentType());
673         array = ArrayUtils.remove(new float[] {1, 2}, 1);
674         assertArrayEquals(new float[]{1}, array);
675         assertEquals(Float.TYPE, array.getClass().getComponentType());
676         array = ArrayUtils.remove(new float[] {1, 2, 1}, 1);
677         assertArrayEquals(new float[]{1, 1}, array);
678         assertEquals(Float.TYPE, array.getClass().getComponentType());
679         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, -1));
680         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new float[] {1, 2}, 2));
681         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((float[]) null, 0));
682     }
683 
684     @Test
685     public void testRemoveIntArray() {
686         int[] array;
687         array = ArrayUtils.remove(new int[] {1}, 0);
688         assertArrayEquals(ArrayUtils.EMPTY_INT_ARRAY, array);
689         assertEquals(Integer.TYPE, array.getClass().getComponentType());
690         array = ArrayUtils.remove(new int[] {1, 2}, 0);
691         assertArrayEquals(new int[]{2}, array);
692         assertEquals(Integer.TYPE, array.getClass().getComponentType());
693         array = ArrayUtils.remove(new int[] {1, 2}, 1);
694         assertArrayEquals(new int[]{1}, array);
695         assertEquals(Integer.TYPE, array.getClass().getComponentType());
696         array = ArrayUtils.remove(new int[] {1, 2, 1}, 1);
697         assertArrayEquals(new int[]{1, 1}, array);
698         assertEquals(Integer.TYPE, array.getClass().getComponentType());
699         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, -1));
700         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new int[] {1, 2}, 2));
701         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((int[]) null, 0));
702     }
703 
704     @Test
705     public void testRemoveLongArray() {
706         long[] array;
707         array = ArrayUtils.remove(new long[] {1}, 0);
708         assertArrayEquals(ArrayUtils.EMPTY_LONG_ARRAY, array);
709         assertEquals(Long.TYPE, array.getClass().getComponentType());
710         array = ArrayUtils.remove(new long[] {1, 2}, 0);
711         assertArrayEquals(new long[]{2}, array);
712         assertEquals(Long.TYPE, array.getClass().getComponentType());
713         array = ArrayUtils.remove(new long[] {1, 2}, 1);
714         assertArrayEquals(new long[]{1}, array);
715         assertEquals(Long.TYPE, array.getClass().getComponentType());
716         array = ArrayUtils.remove(new long[] {1, 2, 1}, 1);
717         assertArrayEquals(new long[]{1, 1}, array);
718         assertEquals(Long.TYPE, array.getClass().getComponentType());
719         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, -1));
720         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new long[] {1, 2}, 2));
721         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((long[]) null, 0));
722     }
723 
724     @Test
725     public void testRemoveNumberArray() {
726         final Number[] inarray = {Integer.valueOf(1), Long.valueOf(2), Byte.valueOf((byte) 3)};
727         assertEquals(3, inarray.length);
728         Number[] outarray;
729         outarray = ArrayUtils.remove(inarray, 1);
730         assertEquals(2, outarray.length);
731         assertEquals(Number.class, outarray.getClass().getComponentType());
732         outarray = ArrayUtils.remove(outarray, 1);
733         assertEquals(1, outarray.length);
734         assertEquals(Number.class, outarray.getClass().getComponentType());
735         outarray = ArrayUtils.remove(outarray, 0);
736         assertEquals(0, outarray.length);
737         assertEquals(Number.class, outarray.getClass().getComponentType());
738     }
739 
740     @Test
741     public void testRemoveObjectArray() {
742         Object[] array;
743         array = ArrayUtils.remove(new Object[] {"a"}, 0);
744         assertArrayEquals(ArrayUtils.EMPTY_OBJECT_ARRAY, array);
745         assertEquals(Object.class, array.getClass().getComponentType());
746         array = ArrayUtils.remove(new Object[] {"a", "b"}, 0);
747         assertArrayEquals(new Object[]{"b"}, array);
748         assertEquals(Object.class, array.getClass().getComponentType());
749         array = ArrayUtils.remove(new Object[] {"a", "b"}, 1);
750         assertArrayEquals(new Object[]{"a"}, array);
751         assertEquals(Object.class, array.getClass().getComponentType());
752         array = ArrayUtils.remove(new Object[] {"a", "b", "c"}, 1);
753         assertArrayEquals(new Object[]{"a", "c"}, array);
754         assertEquals(Object.class, array.getClass().getComponentType());
755         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, -1));
756         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new Object[] {"a", "b"}, 2));
757         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((Object[]) null, 0));
758     }
759 
760     @Test
761     public void testRemoveShortArray() {
762         short[] array;
763         array = ArrayUtils.remove(new short[] {1}, 0);
764         assertArrayEquals(ArrayUtils.EMPTY_SHORT_ARRAY, array);
765         assertEquals(Short.TYPE, array.getClass().getComponentType());
766         array = ArrayUtils.remove(new short[] {1, 2}, 0);
767         assertArrayEquals(new short[]{2}, array);
768         assertEquals(Short.TYPE, array.getClass().getComponentType());
769         array = ArrayUtils.remove(new short[] {1, 2}, 1);
770         assertArrayEquals(new short[]{1}, array);
771         assertEquals(Short.TYPE, array.getClass().getComponentType());
772         array = ArrayUtils.remove(new short[] {1, 2, 1}, 1);
773         assertArrayEquals(new short[]{1, 1}, array);
774         assertEquals(Short.TYPE, array.getClass().getComponentType());
775         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, -1));
776         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove(new short[] {1, 2}, 2));
777         assertThrows(IndexOutOfBoundsException.class, () -> ArrayUtils.remove((short[]) null, 0));
778     }
779 }