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