Coverage Report - org.apache.commons.lang3.ArrayUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
ArrayUtils
99%
1374/1375
98%
1128/1140
4,225
ArrayUtils$1
100%
2/2
N/A
4,225
 
 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  
 package org.apache.commons.lang3;
 18  
 
 19  
 import java.lang.reflect.Array;
 20  
 import java.util.Arrays;
 21  
 import java.util.BitSet;
 22  
 import java.util.Comparator;
 23  
 import java.util.HashMap;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.commons.lang3.builder.EqualsBuilder;
 27  
 import org.apache.commons.lang3.builder.HashCodeBuilder;
 28  
 import org.apache.commons.lang3.builder.ToStringBuilder;
 29  
 import org.apache.commons.lang3.builder.ToStringStyle;
 30  
 import org.apache.commons.lang3.math.NumberUtils;
 31  
 import org.apache.commons.lang3.mutable.MutableInt;
 32  
 
 33  
 /**
 34  
  * <p>Operations on arrays, primitive arrays (like {@code int[]}) and
 35  
  * primitive wrapper arrays (like {@code Integer[]}).</p>
 36  
  *
 37  
  * <p>This class tries to handle {@code null} input gracefully.
 38  
  * An exception will not be thrown for a {@code null}
 39  
  * array input. However, an Object array that contains a {@code null}
 40  
  * element may throw an exception. Each method documents its behaviour.</p>
 41  
  *
 42  
  * <p>#ThreadSafe#</p>
 43  
  * @since 2.0
 44  
  * @version $Id: ArrayUtils.java 1645483 2014-12-14 18:22:06Z kinow $
 45  
  */
 46  
 public class ArrayUtils {
 47  
 
 48  
     /**
 49  
      * An empty immutable {@code Object} array.
 50  
      */
 51  1
     public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
 52  
     /**
 53  
      * An empty immutable {@code Class} array.
 54  
      */
 55  1
     public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
 56  
     /**
 57  
      * An empty immutable {@code String} array.
 58  
      */
 59  1
     public static final String[] EMPTY_STRING_ARRAY = new String[0];
 60  
     /**
 61  
      * An empty immutable {@code long} array.
 62  
      */
 63  1
     public static final long[] EMPTY_LONG_ARRAY = new long[0];
 64  
     /**
 65  
      * An empty immutable {@code Long} array.
 66  
      */
 67  1
     public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0];
 68  
     /**
 69  
      * An empty immutable {@code int} array.
 70  
      */
 71  1
     public static final int[] EMPTY_INT_ARRAY = new int[0];
 72  
     /**
 73  
      * An empty immutable {@code Integer} array.
 74  
      */
 75  1
     public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0];
 76  
     /**
 77  
      * An empty immutable {@code short} array.
 78  
      */
 79  1
     public static final short[] EMPTY_SHORT_ARRAY = new short[0];
 80  
     /**
 81  
      * An empty immutable {@code Short} array.
 82  
      */
 83  1
     public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0];
 84  
     /**
 85  
      * An empty immutable {@code byte} array.
 86  
      */
 87  1
     public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
 88  
     /**
 89  
      * An empty immutable {@code Byte} array.
 90  
      */
 91  1
     public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0];
 92  
     /**
 93  
      * An empty immutable {@code double} array.
 94  
      */
 95  1
     public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
 96  
     /**
 97  
      * An empty immutable {@code Double} array.
 98  
      */
 99  1
     public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0];
 100  
     /**
 101  
      * An empty immutable {@code float} array.
 102  
      */
 103  1
     public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
 104  
     /**
 105  
      * An empty immutable {@code Float} array.
 106  
      */
 107  1
     public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0];
 108  
     /**
 109  
      * An empty immutable {@code boolean} array.
 110  
      */
 111  1
     public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];
 112  
     /**
 113  
      * An empty immutable {@code Boolean} array.
 114  
      */
 115  1
     public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0];
 116  
     /**
 117  
      * An empty immutable {@code char} array.
 118  
      */
 119  1
     public static final char[] EMPTY_CHAR_ARRAY = new char[0];
 120  
     /**
 121  
      * An empty immutable {@code Character} array.
 122  
      */
 123  1
     public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0];
 124  
 
 125  
     /**
 126  
      * The index value when an element is not found in a list or array: {@code -1}.
 127  
      * This value is returned by methods in this class and can also be used in comparisons with values returned by
 128  
      * various method from {@link java.util.List}.
 129  
      */
 130  
     public static final int INDEX_NOT_FOUND = -1;
 131  
 
 132  
     /**
 133  
      * <p>ArrayUtils instances should NOT be constructed in standard programming.
 134  
      * Instead, the class should be used as <code>ArrayUtils.clone(new int[] {2})</code>.</p>
 135  
      *
 136  
      * <p>This constructor is public to permit tools that require a JavaBean instance
 137  
      * to operate.</p>
 138  
      */
 139  
     public ArrayUtils() {
 140  1
       super();
 141  1
     }
 142  
 
 143  
 
 144  
     // NOTE: Cannot use {@code} to enclose text which includes {}, but <code></code> is OK
 145  
 
 146  
 
 147  
     // Basic methods handling multi-dimensional arrays
 148  
     //-----------------------------------------------------------------------
 149  
     /**
 150  
      * <p>Outputs an array as a String, treating {@code null} as an empty array.</p>
 151  
      *
 152  
      * <p>Multi-dimensional arrays are handled correctly, including
 153  
      * multi-dimensional primitive arrays.</p>
 154  
      *
 155  
      * <p>The format is that of Java source code, for example <code>{a,b}</code>.</p>
 156  
      *
 157  
      * @param array  the array to get a toString for, may be {@code null}
 158  
      * @return a String representation of the array, '{}' if null array input
 159  
      */
 160  
     public static String toString(final Object array) {
 161  13
         return toString(array, "{}");
 162  
     }
 163  
 
 164  
     /**
 165  
      * <p>Outputs an array as a String handling {@code null}s.</p>
 166  
      *
 167  
      * <p>Multi-dimensional arrays are handled correctly, including
 168  
      * multi-dimensional primitive arrays.</p>
 169  
      *
 170  
      * <p>The format is that of Java source code, for example <code>{a,b}</code>.</p>
 171  
      *
 172  
      * @param array  the array to get a toString for, may be {@code null}
 173  
      * @param stringIfNull  the String to return if the array is {@code null}
 174  
      * @return a String representation of the array
 175  
      */
 176  
     public static String toString(final Object array, final String stringIfNull) {
 177  18
         if (array == null) {
 178  2
             return stringIfNull;
 179  
         }
 180  16
         return new ToStringBuilder(array, ToStringStyle.SIMPLE_STYLE).append(array).toString();
 181  
     }
 182  
 
 183  
     /**
 184  
      * <p>Get a hash code for an array handling multi-dimensional arrays correctly.</p>
 185  
      *
 186  
      * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
 187  
      *
 188  
      * @param array  the array to get a hash code for, {@code null} returns zero
 189  
      * @return a hash code for the array
 190  
      */
 191  
     public static int hashCode(final Object array) {
 192  10
         return new HashCodeBuilder().append(array).toHashCode();
 193  
     }
 194  
 
 195  
     /**
 196  
      * <p>Compares two arrays, using equals(), handling multi-dimensional arrays
 197  
      * correctly.</p>
 198  
      *
 199  
      * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
 200  
      *
 201  
      * @param array1  the left hand array to compare, may be {@code null}
 202  
      * @param array2  the right hand array to compare, may be {@code null}
 203  
      * @return {@code true} if the arrays are equal
 204  
      * @deprecated this method has been replaced by {@code java.util.Objects.deepEquals(Object, Object)} and will be
 205  
      * removed from future releases.
 206  
      */
 207  
     @Deprecated
 208  
     public static boolean isEquals(final Object array1, final Object array2) {
 209  146
         return new EqualsBuilder().append(array1, array2).isEquals();
 210  
     }
 211  
 
 212  
     // To map
 213  
     //-----------------------------------------------------------------------
 214  
     /**
 215  
      * <p>Converts the given array into a {@link java.util.Map}. Each element of the array
 216  
      * must be either a {@link java.util.Map.Entry} or an Array, containing at least two
 217  
      * elements, where the first element is used as key and the second as
 218  
      * value.</p>
 219  
      *
 220  
      * <p>This method can be used to initialize:</p>
 221  
      * <pre>
 222  
      * // Create a Map mapping colors.
 223  
      * Map colorMap = MapUtils.toMap(new String[][] {{
 224  
      *     {"RED", "#FF0000"},
 225  
      *     {"GREEN", "#00FF00"},
 226  
      *     {"BLUE", "#0000FF"}});
 227  
      * </pre>
 228  
      *
 229  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 230  
      *
 231  
      * @param array  an array whose elements are either a {@link java.util.Map.Entry} or
 232  
      *  an Array containing at least two elements, may be {@code null}
 233  
      * @return a {@code Map} that was created from the array
 234  
      * @throws IllegalArgumentException  if one element of this Array is
 235  
      *  itself an Array containing less then two elements
 236  
      * @throws IllegalArgumentException  if the array contains elements other
 237  
      *  than {@link java.util.Map.Entry} and an Array
 238  
      */
 239  
     public static Map<Object, Object> toMap(final Object[] array) {
 240  6
         if (array == null) {
 241  1
             return null;
 242  
         }
 243  5
         final Map<Object, Object> map = new HashMap<Object, Object>((int) (array.length * 1.5));
 244  11
         for (int i = 0; i < array.length; i++) {
 245  9
             final Object object = array[i];
 246  9
             if (object instanceof Map.Entry<?, ?>) {
 247  1
                 final Map.Entry<?,?> entry = (Map.Entry<?,?>) object;
 248  1
                 map.put(entry.getKey(), entry.getValue());
 249  1
             } else if (object instanceof Object[]) {
 250  6
                 final Object[] entry = (Object[]) object;
 251  6
                 if (entry.length < 2) {
 252  1
                     throw new IllegalArgumentException("Array element " + i + ", '"
 253  
                         + object
 254  
                         + "', has a length less than 2");
 255  
                 }
 256  5
                 map.put(entry[0], entry[1]);
 257  5
             } else {
 258  2
                 throw new IllegalArgumentException("Array element " + i + ", '"
 259  
                         + object
 260  
                         + "', is neither of type Map.Entry nor an Array");
 261  
             }
 262  
         }
 263  2
         return map;
 264  
     }
 265  
 
 266  
     // Generic array
 267  
     //-----------------------------------------------------------------------
 268  
     /**
 269  
      * <p>Create a type-safe generic array.</p>
 270  
      *
 271  
      * <p>The Java language does not allow an array to be created from a generic type:</p>
 272  
      *
 273  
      * <pre>
 274  
     public static &lt;T&gt; T[] createAnArray(int size) {
 275  
         return new T[size]; // compiler error here
 276  
     }
 277  
     public static &lt;T&gt; T[] createAnArray(int size) {
 278  
         return (T[])new Object[size]; // ClassCastException at runtime
 279  
     }
 280  
      * </pre>
 281  
      *
 282  
      * <p>Therefore new arrays of generic types can be created with this method.
 283  
      * For example, an array of Strings can be created:</p>
 284  
      *
 285  
      * <pre>
 286  
     String[] array = ArrayUtils.toArray("1", "2");
 287  
     String[] emptyArray = ArrayUtils.&lt;String&gt;toArray();
 288  
      * </pre>
 289  
      *
 290  
      * <p>The method is typically used in scenarios, where the caller itself uses generic types
 291  
      * that have to be combined into an array.</p>
 292  
      *
 293  
      * <p>Note, this method makes only sense to provide arguments of the same type so that the
 294  
      * compiler can deduce the type of the array itself. While it is possible to select the
 295  
      * type explicitly like in
 296  
      * <code>Number[] array = ArrayUtils.&lt;Number&gt;toArray(Integer.valueOf(42), Double.valueOf(Math.PI))</code>,
 297  
      * there is no real advantage when compared to
 298  
      * <code>new Number[] {Integer.valueOf(42), Double.valueOf(Math.PI)}</code>.</p>
 299  
      *
 300  
      * @param  <T>   the array's element type
 301  
      * @param  items  the varargs array items, null allowed
 302  
      * @return the array, not null unless a null array is passed in
 303  
      * @since  3.0
 304  
      */
 305  
     public static <T> T[] toArray(final T... items) {
 306  6
         return items;
 307  
     }
 308  
 
 309  
     // Clone
 310  
     //-----------------------------------------------------------------------
 311  
     /**
 312  
      * <p>Shallow clones an array returning a typecast result and handling
 313  
      * {@code null}.</p>
 314  
      *
 315  
      * <p>The objects in the array are not cloned, thus there is no special
 316  
      * handling for multi-dimensional arrays.</p>
 317  
      *
 318  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 319  
      *
 320  
      * @param <T> the component type of the array
 321  
      * @param array  the array to shallow clone, may be {@code null}
 322  
      * @return the cloned array, {@code null} if {@code null} input
 323  
      */
 324  
     public static <T> T[] clone(final T[] array) {
 325  29
         if (array == null) {
 326  5
             return null;
 327  
         }
 328  24
         return array.clone();
 329  
     }
 330  
 
 331  
     /**
 332  
      * <p>Clones an array returning a typecast result and handling
 333  
      * {@code null}.</p>
 334  
      *
 335  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 336  
      *
 337  
      * @param array  the array to clone, may be {@code null}
 338  
      * @return the cloned array, {@code null} if {@code null} input
 339  
      */
 340  
     public static long[] clone(final long[] array) {
 341  42
         if (array == null) {
 342  4
             return null;
 343  
         }
 344  38
         return array.clone();
 345  
     }
 346  
 
 347  
     /**
 348  
      * <p>Clones an array returning a typecast result and handling
 349  
      * {@code null}.</p>
 350  
      *
 351  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 352  
      *
 353  
      * @param array  the array to clone, may be {@code null}
 354  
      * @return the cloned array, {@code null} if {@code null} input
 355  
      */
 356  
     public static int[] clone(final int[] array) {
 357  162
         if (array == null) {
 358  4
             return null;
 359  
         }
 360  158
         return array.clone();
 361  
     }
 362  
 
 363  
     /**
 364  
      * <p>Clones an array returning a typecast result and handling
 365  
      * {@code null}.</p>
 366  
      *
 367  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 368  
      *
 369  
      * @param array  the array to clone, may be {@code null}
 370  
      * @return the cloned array, {@code null} if {@code null} input
 371  
      */
 372  
     public static short[] clone(final short[] array) {
 373  10
         if (array == null) {
 374  4
             return null;
 375  
         }
 376  6
         return array.clone();
 377  
     }
 378  
 
 379  
     /**
 380  
      * <p>Clones an array returning a typecast result and handling
 381  
      * {@code null}.</p>
 382  
      *
 383  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 384  
      *
 385  
      * @param array  the array to clone, may be {@code null}
 386  
      * @return the cloned array, {@code null} if {@code null} input
 387  
      */
 388  
     public static char[] clone(final char[] array) {
 389  32
         if (array == null) {
 390  9
             return null;
 391  
         }
 392  23
         return array.clone();
 393  
     }
 394  
 
 395  
     /**
 396  
      * <p>Clones an array returning a typecast result and handling
 397  
      * {@code null}.</p>
 398  
      *
 399  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 400  
      *
 401  
      * @param array  the array to clone, may be {@code null}
 402  
      * @return the cloned array, {@code null} if {@code null} input
 403  
      */
 404  
     public static byte[] clone(final byte[] array) {
 405  10
         if (array == null) {
 406  4
             return null;
 407  
         }
 408  6
         return array.clone();
 409  
     }
 410  
 
 411  
     /**
 412  
      * <p>Clones an array returning a typecast result and handling
 413  
      * {@code null}.</p>
 414  
      *
 415  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 416  
      *
 417  
      * @param array  the array to clone, may be {@code null}
 418  
      * @return the cloned array, {@code null} if {@code null} input
 419  
      */
 420  
     public static double[] clone(final double[] array) {
 421  10
         if (array == null) {
 422  4
             return null;
 423  
         }
 424  6
         return array.clone();
 425  
     }
 426  
 
 427  
     /**
 428  
      * <p>Clones an array returning a typecast result and handling
 429  
      * {@code null}.</p>
 430  
      *
 431  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 432  
      *
 433  
      * @param array  the array to clone, may be {@code null}
 434  
      * @return the cloned array, {@code null} if {@code null} input
 435  
      */
 436  
     public static float[] clone(final float[] array) {
 437  10
         if (array == null) {
 438  4
             return null;
 439  
         }
 440  6
         return array.clone();
 441  
     }
 442  
 
 443  
     /**
 444  
      * <p>Clones an array returning a typecast result and handling
 445  
      * {@code null}.</p>
 446  
      *
 447  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 448  
      *
 449  
      * @param array  the array to clone, may be {@code null}
 450  
      * @return the cloned array, {@code null} if {@code null} input
 451  
      */
 452  
     public static boolean[] clone(final boolean[] array) {
 453  10
         if (array == null) {
 454  4
             return null;
 455  
         }
 456  6
         return array.clone();
 457  
     }
 458  
 
 459  
     // nullToEmpty
 460  
     //-----------------------------------------------------------------------
 461  
     /**
 462  
      * <p>Defensive programming technique to change a {@code null}
 463  
      * reference to an empty one.</p>
 464  
      *
 465  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 466  
      *
 467  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 468  
      * the empty {@code public static} references in this class.</p>
 469  
      *
 470  
      * @param array  the array to check for {@code null} or empty
 471  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 472  
      * @since 2.5
 473  
      */
 474  
     public static Object[] nullToEmpty(final Object[] array) {
 475  136
         if (isEmpty(array)) {
 476  38
             return EMPTY_OBJECT_ARRAY;
 477  
         }
 478  98
         return array;
 479  
     }
 480  
 
 481  
     /**
 482  
      * <p>Defensive programming technique to change a {@code null}
 483  
      * reference to an empty one.</p>
 484  
      *
 485  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 486  
      *
 487  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 488  
      * the empty {@code public static} references in this class.</p>
 489  
      *
 490  
      * @param array  the array to check for {@code null} or empty
 491  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 492  
      * @since 3.2
 493  
      */
 494  
     public static Class<?>[] nullToEmpty(final Class<?>[] array) {
 495  75
         if (isEmpty(array)) {
 496  24
             return EMPTY_CLASS_ARRAY;
 497  
         }
 498  51
         return array;
 499  
     }
 500  
 
 501  
     /**
 502  
      * <p>Defensive programming technique to change a {@code null}
 503  
      * reference to an empty one.</p>
 504  
      *
 505  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 506  
      *
 507  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 508  
      * the empty {@code public static} references in this class.</p>
 509  
      *
 510  
      * @param array  the array to check for {@code null} or empty
 511  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 512  
      * @since 2.5
 513  
      */
 514  
     public static String[] nullToEmpty(final String[] array) {
 515  3
         if (isEmpty(array)) {
 516  2
             return EMPTY_STRING_ARRAY;
 517  
         }
 518  1
         return array;
 519  
     }
 520  
 
 521  
     /**
 522  
      * <p>Defensive programming technique to change a {@code null}
 523  
      * reference to an empty one.</p>
 524  
      *
 525  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 526  
      *
 527  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 528  
      * the empty {@code public static} references in this class.</p>
 529  
      *
 530  
      * @param array  the array to check for {@code null} or empty
 531  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 532  
      * @since 2.5
 533  
      */
 534  
     public static long[] nullToEmpty(final long[] array) {
 535  3
         if (isEmpty(array)) {
 536  2
             return EMPTY_LONG_ARRAY;
 537  
         }
 538  1
         return array;
 539  
     }
 540  
 
 541  
     /**
 542  
      * <p>Defensive programming technique to change a {@code null}
 543  
      * reference to an empty one.</p>
 544  
      *
 545  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 546  
      *
 547  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 548  
      * the empty {@code public static} references in this class.</p>
 549  
      *
 550  
      * @param array  the array to check for {@code null} or empty
 551  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 552  
      * @since 2.5
 553  
      */
 554  
     public static int[] nullToEmpty(final int[] array) {
 555  3
         if (isEmpty(array)) {
 556  2
             return EMPTY_INT_ARRAY;
 557  
         }
 558  1
         return array;
 559  
     }
 560  
 
 561  
     /**
 562  
      * <p>Defensive programming technique to change a {@code null}
 563  
      * reference to an empty one.</p>
 564  
      *
 565  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 566  
      *
 567  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 568  
      * the empty {@code public static} references in this class.</p>
 569  
      *
 570  
      * @param array  the array to check for {@code null} or empty
 571  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 572  
      * @since 2.5
 573  
      */
 574  
     public static short[] nullToEmpty(final short[] array) {
 575  3
         if (isEmpty(array)) {
 576  2
             return EMPTY_SHORT_ARRAY;
 577  
         }
 578  1
         return array;
 579  
     }
 580  
 
 581  
     /**
 582  
      * <p>Defensive programming technique to change a {@code null}
 583  
      * reference to an empty one.</p>
 584  
      *
 585  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 586  
      *
 587  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 588  
      * the empty {@code public static} references in this class.</p>
 589  
      *
 590  
      * @param array  the array to check for {@code null} or empty
 591  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 592  
      * @since 2.5
 593  
      */
 594  
     public static char[] nullToEmpty(final char[] array) {
 595  3
         if (isEmpty(array)) {
 596  2
             return EMPTY_CHAR_ARRAY;
 597  
         }
 598  1
         return array;
 599  
     }
 600  
 
 601  
     /**
 602  
      * <p>Defensive programming technique to change a {@code null}
 603  
      * reference to an empty one.</p>
 604  
      *
 605  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 606  
      *
 607  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 608  
      * the empty {@code public static} references in this class.</p>
 609  
      *
 610  
      * @param array  the array to check for {@code null} or empty
 611  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 612  
      * @since 2.5
 613  
      */
 614  
     public static byte[] nullToEmpty(final byte[] array) {
 615  3
         if (isEmpty(array)) {
 616  2
             return EMPTY_BYTE_ARRAY;
 617  
         }
 618  1
         return array;
 619  
     }
 620  
 
 621  
     /**
 622  
      * <p>Defensive programming technique to change a {@code null}
 623  
      * reference to an empty one.</p>
 624  
      *
 625  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 626  
      *
 627  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 628  
      * the empty {@code public static} references in this class.</p>
 629  
      *
 630  
      * @param array  the array to check for {@code null} or empty
 631  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 632  
      * @since 2.5
 633  
      */
 634  
     public static double[] nullToEmpty(final double[] array) {
 635  3
         if (isEmpty(array)) {
 636  2
             return EMPTY_DOUBLE_ARRAY;
 637  
         }
 638  1
         return array;
 639  
     }
 640  
 
 641  
     /**
 642  
      * <p>Defensive programming technique to change a {@code null}
 643  
      * reference to an empty one.</p>
 644  
      *
 645  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 646  
      *
 647  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 648  
      * the empty {@code public static} references in this class.</p>
 649  
      *
 650  
      * @param array  the array to check for {@code null} or empty
 651  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 652  
      * @since 2.5
 653  
      */
 654  
     public static float[] nullToEmpty(final float[] array) {
 655  3
         if (isEmpty(array)) {
 656  2
             return EMPTY_FLOAT_ARRAY;
 657  
         }
 658  1
         return array;
 659  
     }
 660  
 
 661  
     /**
 662  
      * <p>Defensive programming technique to change a {@code null}
 663  
      * reference to an empty one.</p>
 664  
      *
 665  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 666  
      *
 667  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 668  
      * the empty {@code public static} references in this class.</p>
 669  
      *
 670  
      * @param array  the array to check for {@code null} or empty
 671  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 672  
      * @since 2.5
 673  
      */
 674  
     public static boolean[] nullToEmpty(final boolean[] array) {
 675  3
         if (isEmpty(array)) {
 676  2
             return EMPTY_BOOLEAN_ARRAY;
 677  
         }
 678  1
         return array;
 679  
     }
 680  
 
 681  
     /**
 682  
      * <p>Defensive programming technique to change a {@code null}
 683  
      * reference to an empty one.</p>
 684  
      *
 685  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 686  
      *
 687  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 688  
      * the empty {@code public static} references in this class.</p>
 689  
      *
 690  
      * @param array  the array to check for {@code null} or empty
 691  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 692  
      * @since 2.5
 693  
      */
 694  
     public static Long[] nullToEmpty(final Long[] array) {
 695  3
         if (isEmpty(array)) {
 696  2
             return EMPTY_LONG_OBJECT_ARRAY;
 697  
         }
 698  1
         return array;
 699  
     }
 700  
 
 701  
     /**
 702  
      * <p>Defensive programming technique to change a {@code null}
 703  
      * reference to an empty one.</p>
 704  
      *
 705  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 706  
      *
 707  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 708  
      * the empty {@code public static} references in this class.</p>
 709  
      *
 710  
      * @param array  the array to check for {@code null} or empty
 711  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 712  
      * @since 2.5
 713  
      */
 714  
     public static Integer[] nullToEmpty(final Integer[] array) {
 715  3
         if (isEmpty(array)) {
 716  2
             return EMPTY_INTEGER_OBJECT_ARRAY;
 717  
         }
 718  1
         return array;
 719  
     }
 720  
 
 721  
     /**
 722  
      * <p>Defensive programming technique to change a {@code null}
 723  
      * reference to an empty one.</p>
 724  
      *
 725  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 726  
      *
 727  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 728  
      * the empty {@code public static} references in this class.</p>
 729  
      *
 730  
      * @param array  the array to check for {@code null} or empty
 731  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 732  
      * @since 2.5
 733  
      */
 734  
     public static Short[] nullToEmpty(final Short[] array) {
 735  3
         if (isEmpty(array)) {
 736  2
             return EMPTY_SHORT_OBJECT_ARRAY;
 737  
         }
 738  1
         return array;
 739  
     }
 740  
 
 741  
     /**
 742  
      * <p>Defensive programming technique to change a {@code null}
 743  
      * reference to an empty one.</p>
 744  
      *
 745  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 746  
      *
 747  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 748  
      * the empty {@code public static} references in this class.</p>
 749  
      *
 750  
      * @param array  the array to check for {@code null} or empty
 751  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 752  
      * @since 2.5
 753  
      */
 754  
     public static Character[] nullToEmpty(final Character[] array) {
 755  3
         if (isEmpty(array)) {
 756  2
             return EMPTY_CHARACTER_OBJECT_ARRAY;
 757  
         }
 758  1
         return array;
 759  
     }
 760  
 
 761  
     /**
 762  
      * <p>Defensive programming technique to change a {@code null}
 763  
      * reference to an empty one.</p>
 764  
      *
 765  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 766  
      *
 767  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 768  
      * the empty {@code public static} references in this class.</p>
 769  
      *
 770  
      * @param array  the array to check for {@code null} or empty
 771  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 772  
      * @since 2.5
 773  
      */
 774  
     public static Byte[] nullToEmpty(final Byte[] array) {
 775  3
         if (isEmpty(array)) {
 776  2
             return EMPTY_BYTE_OBJECT_ARRAY;
 777  
         }
 778  1
         return array;
 779  
     }
 780  
 
 781  
     /**
 782  
      * <p>Defensive programming technique to change a {@code null}
 783  
      * reference to an empty one.</p>
 784  
      *
 785  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 786  
      *
 787  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 788  
      * the empty {@code public static} references in this class.</p>
 789  
      *
 790  
      * @param array  the array to check for {@code null} or empty
 791  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 792  
      * @since 2.5
 793  
      */
 794  
     public static Double[] nullToEmpty(final Double[] array) {
 795  3
         if (isEmpty(array)) {
 796  2
             return EMPTY_DOUBLE_OBJECT_ARRAY;
 797  
         }
 798  1
         return array;
 799  
     }
 800  
 
 801  
     /**
 802  
      * <p>Defensive programming technique to change a {@code null}
 803  
      * reference to an empty one.</p>
 804  
      *
 805  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 806  
      *
 807  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 808  
      * the empty {@code public static} references in this class.</p>
 809  
      *
 810  
      * @param array  the array to check for {@code null} or empty
 811  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 812  
      * @since 2.5
 813  
      */
 814  
     public static Float[] nullToEmpty(final Float[] array) {
 815  3
         if (isEmpty(array)) {
 816  2
             return EMPTY_FLOAT_OBJECT_ARRAY;
 817  
         }
 818  1
         return array;
 819  
     }
 820  
 
 821  
     /**
 822  
      * <p>Defensive programming technique to change a {@code null}
 823  
      * reference to an empty one.</p>
 824  
      *
 825  
      * <p>This method returns an empty array for a {@code null} input array.</p>
 826  
      *
 827  
      * <p>As a memory optimizing technique an empty array passed in will be overridden with
 828  
      * the empty {@code public static} references in this class.</p>
 829  
      *
 830  
      * @param array  the array to check for {@code null} or empty
 831  
      * @return the same array, {@code public static} empty array if {@code null} or empty input
 832  
      * @since 2.5
 833  
      */
 834  
     public static Boolean[] nullToEmpty(final Boolean[] array) {
 835  3
         if (isEmpty(array)) {
 836  2
             return EMPTY_BOOLEAN_OBJECT_ARRAY;
 837  
         }
 838  1
         return array;
 839  
     }
 840  
 
 841  
     // Subarrays
 842  
     //-----------------------------------------------------------------------
 843  
     /**
 844  
      * <p>Produces a new array containing the elements between
 845  
      * the start and end indices.</p>
 846  
      *
 847  
      * <p>The start index is inclusive, the end index exclusive.
 848  
      * Null array input produces null output.</p>
 849  
      *
 850  
      * <p>The component type of the subarray is always the same as
 851  
      * that of the input array. Thus, if the input is an array of type
 852  
      * {@code Date}, the following usage is envisaged:</p>
 853  
      *
 854  
      * <pre>
 855  
      * Date[] someDates = (Date[])ArrayUtils.subarray(allDates, 2, 5);
 856  
      * </pre>
 857  
      *
 858  
      * @param <T> the component type of the array
 859  
      * @param array  the array
 860  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 861  
      *      is promoted to 0, overvalue (&gt;array.length) results
 862  
      *      in an empty array.
 863  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 864  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 865  
      *      empty array, overvalue (&gt;array.length) is demoted to
 866  
      *      array length.
 867  
      * @return a new array containing the elements between
 868  
      *      the start and end indices.
 869  
      * @since 2.1
 870  
      * @see Arrays#copyOfRange(Object[], int, int)
 871  
      */
 872  
     public static <T> T[] subarray(final T[] array, int startIndexInclusive, int endIndexExclusive) {
 873  16
         if (array == null) {
 874  1
             return null;
 875  
         }
 876  15
         if (startIndexInclusive < 0) {
 877  2
             startIndexInclusive = 0;
 878  
         }
 879  15
         if (endIndexExclusive > array.length) {
 880  3
             endIndexExclusive = array.length;
 881  
         }
 882  15
         final int newSize = endIndexExclusive - startIndexInclusive;
 883  15
         final Class<?> type = array.getClass().getComponentType();
 884  15
         if (newSize <= 0) {
 885  
             @SuppressWarnings("unchecked") // OK, because array is of type T
 886  4
             final T[] emptyArray = (T[]) Array.newInstance(type, 0);
 887  4
             return emptyArray;
 888  
         }
 889  
         @SuppressWarnings("unchecked") // OK, because array is of type T
 890  
         final
 891  11
         T[] subarray = (T[]) Array.newInstance(type, newSize);
 892  11
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 893  11
         return subarray;
 894  
     }
 895  
 
 896  
     /**
 897  
      * <p>Produces a new {@code long} array containing the elements
 898  
      * between the start and end indices.</p>
 899  
      *
 900  
      * <p>The start index is inclusive, the end index exclusive.
 901  
      * Null array input produces null output.</p>
 902  
      *
 903  
      * @param array  the array
 904  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 905  
      *      is promoted to 0, overvalue (&gt;array.length) results
 906  
      *      in an empty array.
 907  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 908  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 909  
      *      empty array, overvalue (&gt;array.length) is demoted to
 910  
      *      array length.
 911  
      * @return a new array containing the elements between
 912  
      *      the start and end indices.
 913  
      * @since 2.1
 914  
      * @see Arrays#copyOfRange(long[], int, int)
 915  
      */
 916  
     public static long[] subarray(final long[] array, int startIndexInclusive, int endIndexExclusive) {
 917  17
         if (array == null) {
 918  1
             return null;
 919  
         }
 920  16
         if (startIndexInclusive < 0) {
 921  2
             startIndexInclusive = 0;
 922  
         }
 923  16
         if (endIndexExclusive > array.length) {
 924  4
             endIndexExclusive = array.length;
 925  
         }
 926  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 927  16
         if (newSize <= 0) {
 928  8
             return EMPTY_LONG_ARRAY;
 929  
         }
 930  
 
 931  8
         final long[] subarray = new long[newSize];
 932  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 933  8
         return subarray;
 934  
     }
 935  
 
 936  
     /**
 937  
      * <p>Produces a new {@code int} array containing the elements
 938  
      * between the start and end indices.</p>
 939  
      *
 940  
      * <p>The start index is inclusive, the end index exclusive.
 941  
      * Null array input produces null output.</p>
 942  
      *
 943  
      * @param array  the array
 944  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 945  
      *      is promoted to 0, overvalue (&gt;array.length) results
 946  
      *      in an empty array.
 947  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 948  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 949  
      *      empty array, overvalue (&gt;array.length) is demoted to
 950  
      *      array length.
 951  
      * @return a new array containing the elements between
 952  
      *      the start and end indices.
 953  
      * @since 2.1
 954  
      * @see Arrays#copyOfRange(int[], int, int)
 955  
      */
 956  
     public static int[] subarray(final int[] array, int startIndexInclusive, int endIndexExclusive) {
 957  17
         if (array == null) {
 958  1
             return null;
 959  
         }
 960  16
         if (startIndexInclusive < 0) {
 961  2
             startIndexInclusive = 0;
 962  
         }
 963  16
         if (endIndexExclusive > array.length) {
 964  4
             endIndexExclusive = array.length;
 965  
         }
 966  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 967  16
         if (newSize <= 0) {
 968  8
             return EMPTY_INT_ARRAY;
 969  
         }
 970  
 
 971  8
         final int[] subarray = new int[newSize];
 972  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 973  8
         return subarray;
 974  
     }
 975  
 
 976  
     /**
 977  
      * <p>Produces a new {@code short} array containing the elements
 978  
      * between the start and end indices.</p>
 979  
      *
 980  
      * <p>The start index is inclusive, the end index exclusive.
 981  
      * Null array input produces null output.</p>
 982  
      *
 983  
      * @param array  the array
 984  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 985  
      *      is promoted to 0, overvalue (&gt;array.length) results
 986  
      *      in an empty array.
 987  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 988  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 989  
      *      empty array, overvalue (&gt;array.length) is demoted to
 990  
      *      array length.
 991  
      * @return a new array containing the elements between
 992  
      *      the start and end indices.
 993  
      * @since 2.1
 994  
      * @see Arrays#copyOfRange(short[], int, int)
 995  
      */
 996  
     public static short[] subarray(final short[] array, int startIndexInclusive, int endIndexExclusive) {
 997  17
         if (array == null) {
 998  1
             return null;
 999  
         }
 1000  16
         if (startIndexInclusive < 0) {
 1001  2
             startIndexInclusive = 0;
 1002  
         }
 1003  16
         if (endIndexExclusive > array.length) {
 1004  4
             endIndexExclusive = array.length;
 1005  
         }
 1006  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1007  16
         if (newSize <= 0) {
 1008  8
             return EMPTY_SHORT_ARRAY;
 1009  
         }
 1010  
 
 1011  8
         final short[] subarray = new short[newSize];
 1012  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1013  8
         return subarray;
 1014  
     }
 1015  
 
 1016  
     /**
 1017  
      * <p>Produces a new {@code char} array containing the elements
 1018  
      * between the start and end indices.</p>
 1019  
      *
 1020  
      * <p>The start index is inclusive, the end index exclusive.
 1021  
      * Null array input produces null output.</p>
 1022  
      *
 1023  
      * @param array  the array
 1024  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 1025  
      *      is promoted to 0, overvalue (&gt;array.length) results
 1026  
      *      in an empty array.
 1027  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 1028  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 1029  
      *      empty array, overvalue (&gt;array.length) is demoted to
 1030  
      *      array length.
 1031  
      * @return a new array containing the elements between
 1032  
      *      the start and end indices.
 1033  
      * @since 2.1
 1034  
      * @see Arrays#copyOfRange(char[], int, int)
 1035  
      */
 1036  
     public static char[] subarray(final char[] array, int startIndexInclusive, int endIndexExclusive) {
 1037  17
         if (array == null) {
 1038  1
             return null;
 1039  
         }
 1040  16
         if (startIndexInclusive < 0) {
 1041  2
             startIndexInclusive = 0;
 1042  
         }
 1043  16
         if (endIndexExclusive > array.length) {
 1044  4
             endIndexExclusive = array.length;
 1045  
         }
 1046  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1047  16
         if (newSize <= 0) {
 1048  8
             return EMPTY_CHAR_ARRAY;
 1049  
         }
 1050  
 
 1051  8
         final char[] subarray = new char[newSize];
 1052  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1053  8
         return subarray;
 1054  
     }
 1055  
 
 1056  
     /**
 1057  
      * <p>Produces a new {@code byte} array containing the elements
 1058  
      * between the start and end indices.</p>
 1059  
      *
 1060  
      * <p>The start index is inclusive, the end index exclusive.
 1061  
      * Null array input produces null output.</p>
 1062  
      *
 1063  
      * @param array  the array
 1064  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 1065  
      *      is promoted to 0, overvalue (&gt;array.length) results
 1066  
      *      in an empty array.
 1067  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 1068  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 1069  
      *      empty array, overvalue (&gt;array.length) is demoted to
 1070  
      *      array length.
 1071  
      * @return a new array containing the elements between
 1072  
      *      the start and end indices.
 1073  
      * @since 2.1
 1074  
      * @see Arrays#copyOfRange(byte[], int, int)
 1075  
      */
 1076  
     public static byte[] subarray(final byte[] array, int startIndexInclusive, int endIndexExclusive) {
 1077  17
         if (array == null) {
 1078  1
             return null;
 1079  
         }
 1080  16
         if (startIndexInclusive < 0) {
 1081  2
             startIndexInclusive = 0;
 1082  
         }
 1083  16
         if (endIndexExclusive > array.length) {
 1084  4
             endIndexExclusive = array.length;
 1085  
         }
 1086  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1087  16
         if (newSize <= 0) {
 1088  8
             return EMPTY_BYTE_ARRAY;
 1089  
         }
 1090  
 
 1091  8
         final byte[] subarray = new byte[newSize];
 1092  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1093  8
         return subarray;
 1094  
     }
 1095  
 
 1096  
     /**
 1097  
      * <p>Produces a new {@code double} array containing the elements
 1098  
      * between the start and end indices.</p>
 1099  
      *
 1100  
      * <p>The start index is inclusive, the end index exclusive.
 1101  
      * Null array input produces null output.</p>
 1102  
      *
 1103  
      * @param array  the array
 1104  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 1105  
      *      is promoted to 0, overvalue (&gt;array.length) results
 1106  
      *      in an empty array.
 1107  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 1108  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 1109  
      *      empty array, overvalue (&gt;array.length) is demoted to
 1110  
      *      array length.
 1111  
      * @return a new array containing the elements between
 1112  
      *      the start and end indices.
 1113  
      * @since 2.1
 1114  
      * @see Arrays#copyOfRange(double[], int, int)
 1115  
      */
 1116  
     public static double[] subarray(final double[] array, int startIndexInclusive, int endIndexExclusive) {
 1117  17
         if (array == null) {
 1118  1
             return null;
 1119  
         }
 1120  16
         if (startIndexInclusive < 0) {
 1121  2
             startIndexInclusive = 0;
 1122  
         }
 1123  16
         if (endIndexExclusive > array.length) {
 1124  4
             endIndexExclusive = array.length;
 1125  
         }
 1126  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1127  16
         if (newSize <= 0) {
 1128  8
             return EMPTY_DOUBLE_ARRAY;
 1129  
         }
 1130  
 
 1131  8
         final double[] subarray = new double[newSize];
 1132  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1133  8
         return subarray;
 1134  
     }
 1135  
 
 1136  
     /**
 1137  
      * <p>Produces a new {@code float} array containing the elements
 1138  
      * between the start and end indices.</p>
 1139  
      *
 1140  
      * <p>The start index is inclusive, the end index exclusive.
 1141  
      * Null array input produces null output.</p>
 1142  
      *
 1143  
      * @param array  the array
 1144  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 1145  
      *      is promoted to 0, overvalue (&gt;array.length) results
 1146  
      *      in an empty array.
 1147  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 1148  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 1149  
      *      empty array, overvalue (&gt;array.length) is demoted to
 1150  
      *      array length.
 1151  
      * @return a new array containing the elements between
 1152  
      *      the start and end indices.
 1153  
      * @since 2.1
 1154  
      * @see Arrays#copyOfRange(float[], int, int)
 1155  
      */
 1156  
     public static float[] subarray(final float[] array, int startIndexInclusive, int endIndexExclusive) {
 1157  17
         if (array == null) {
 1158  1
             return null;
 1159  
         }
 1160  16
         if (startIndexInclusive < 0) {
 1161  2
             startIndexInclusive = 0;
 1162  
         }
 1163  16
         if (endIndexExclusive > array.length) {
 1164  4
             endIndexExclusive = array.length;
 1165  
         }
 1166  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1167  16
         if (newSize <= 0) {
 1168  8
             return EMPTY_FLOAT_ARRAY;
 1169  
         }
 1170  
 
 1171  8
         final float[] subarray = new float[newSize];
 1172  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1173  8
         return subarray;
 1174  
     }
 1175  
 
 1176  
     /**
 1177  
      * <p>Produces a new {@code boolean} array containing the elements
 1178  
      * between the start and end indices.</p>
 1179  
      *
 1180  
      * <p>The start index is inclusive, the end index exclusive.
 1181  
      * Null array input produces null output.</p>
 1182  
      *
 1183  
      * @param array  the array
 1184  
      * @param startIndexInclusive  the starting index. Undervalue (&lt;0)
 1185  
      *      is promoted to 0, overvalue (&gt;array.length) results
 1186  
      *      in an empty array.
 1187  
      * @param endIndexExclusive  elements up to endIndex-1 are present in the
 1188  
      *      returned subarray. Undervalue (&lt; startIndex) produces
 1189  
      *      empty array, overvalue (&gt;array.length) is demoted to
 1190  
      *      array length.
 1191  
      * @return a new array containing the elements between
 1192  
      *      the start and end indices.
 1193  
      * @since 2.1
 1194  
      * @see Arrays#copyOfRange(boolean[], int, int)
 1195  
      */
 1196  
     public static boolean[] subarray(final boolean[] array, int startIndexInclusive, int endIndexExclusive) {
 1197  17
         if (array == null) {
 1198  1
             return null;
 1199  
         }
 1200  16
         if (startIndexInclusive < 0) {
 1201  2
             startIndexInclusive = 0;
 1202  
         }
 1203  16
         if (endIndexExclusive > array.length) {
 1204  4
             endIndexExclusive = array.length;
 1205  
         }
 1206  16
         final int newSize = endIndexExclusive - startIndexInclusive;
 1207  16
         if (newSize <= 0) {
 1208  8
             return EMPTY_BOOLEAN_ARRAY;
 1209  
         }
 1210  
 
 1211  8
         final boolean[] subarray = new boolean[newSize];
 1212  8
         System.arraycopy(array, startIndexInclusive, subarray, 0, newSize);
 1213  8
         return subarray;
 1214  
     }
 1215  
 
 1216  
     // Is same length
 1217  
     //-----------------------------------------------------------------------
 1218  
     /**
 1219  
      * <p>Checks whether two arrays are the same length, treating
 1220  
      * {@code null} arrays as length {@code 0}.
 1221  
      *
 1222  
      * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
 1223  
      *
 1224  
      * @param array1 the first array, may be {@code null}
 1225  
      * @param array2 the second array, may be {@code null}
 1226  
      * @return {@code true} if length of arrays matches, treating
 1227  
      *  {@code null} as an empty array
 1228  
      */
 1229  
     public static boolean isSameLength(final Object[] array1, final Object[] array2) {
 1230  297
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1231  
             (array2 == null && array1 != null && array1.length > 0) ||
 1232  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1233  59
                 return false;
 1234  
         }
 1235  238
         return true;
 1236  
     }
 1237  
 
 1238  
     /**
 1239  
      * <p>Checks whether two arrays are the same length, treating
 1240  
      * {@code null} arrays as length {@code 0}.</p>
 1241  
      *
 1242  
      * @param array1 the first array, may be {@code null}
 1243  
      * @param array2 the second array, may be {@code null}
 1244  
      * @return {@code true} if length of arrays matches, treating
 1245  
      *  {@code null} as an empty array
 1246  
      */
 1247  
     public static boolean isSameLength(final long[] array1, final long[] array2) {
 1248  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1249  
             (array2 == null && array1 != null && array1.length > 0) ||
 1250  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1251  10
                 return false;
 1252  
         }
 1253  6
         return true;
 1254  
     }
 1255  
 
 1256  
     /**
 1257  
      * <p>Checks whether two arrays are the same length, treating
 1258  
      * {@code null} arrays as length {@code 0}.</p>
 1259  
      *
 1260  
      * @param array1 the first array, may be {@code null}
 1261  
      * @param array2 the second array, may be {@code null}
 1262  
      * @return {@code true} if length of arrays matches, treating
 1263  
      *  {@code null} as an empty array
 1264  
      */
 1265  
     public static boolean isSameLength(final int[] array1, final int[] array2) {
 1266  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1267  
             (array2 == null && array1 != null && array1.length > 0) ||
 1268  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1269  10
                 return false;
 1270  
         }
 1271  6
         return true;
 1272  
     }
 1273  
 
 1274  
     /**
 1275  
      * <p>Checks whether two arrays are the same length, treating
 1276  
      * {@code null} arrays as length {@code 0}.</p>
 1277  
      *
 1278  
      * @param array1 the first array, may be {@code null}
 1279  
      * @param array2 the second array, may be {@code null}
 1280  
      * @return {@code true} if length of arrays matches, treating
 1281  
      *  {@code null} as an empty array
 1282  
      */
 1283  
     public static boolean isSameLength(final short[] array1, final short[] array2) {
 1284  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1285  
             (array2 == null && array1 != null && array1.length > 0) ||
 1286  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1287  10
                 return false;
 1288  
         }
 1289  6
         return true;
 1290  
     }
 1291  
 
 1292  
     /**
 1293  
      * <p>Checks whether two arrays are the same length, treating
 1294  
      * {@code null} arrays as length {@code 0}.</p>
 1295  
      *
 1296  
      * @param array1 the first array, may be {@code null}
 1297  
      * @param array2 the second array, may be {@code null}
 1298  
      * @return {@code true} if length of arrays matches, treating
 1299  
      *  {@code null} as an empty array
 1300  
      */
 1301  
     public static boolean isSameLength(final char[] array1, final char[] array2) {
 1302  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1303  
             (array2 == null && array1 != null && array1.length > 0) ||
 1304  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1305  10
                 return false;
 1306  
         }
 1307  6
         return true;
 1308  
     }
 1309  
 
 1310  
     /**
 1311  
      * <p>Checks whether two arrays are the same length, treating
 1312  
      * {@code null} arrays as length {@code 0}.</p>
 1313  
      *
 1314  
      * @param array1 the first array, may be {@code null}
 1315  
      * @param array2 the second array, may be {@code null}
 1316  
      * @return {@code true} if length of arrays matches, treating
 1317  
      *  {@code null} as an empty array
 1318  
      */
 1319  
     public static boolean isSameLength(final byte[] array1, final byte[] array2) {
 1320  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1321  
             (array2 == null && array1 != null && array1.length > 0) ||
 1322  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1323  10
                 return false;
 1324  
         }
 1325  6
         return true;
 1326  
     }
 1327  
 
 1328  
     /**
 1329  
      * <p>Checks whether two arrays are the same length, treating
 1330  
      * {@code null} arrays as length {@code 0}.</p>
 1331  
      *
 1332  
      * @param array1 the first array, may be {@code null}
 1333  
      * @param array2 the second array, may be {@code null}
 1334  
      * @return {@code true} if length of arrays matches, treating
 1335  
      *  {@code null} as an empty array
 1336  
      */
 1337  
     public static boolean isSameLength(final double[] array1, final double[] array2) {
 1338  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1339  
             (array2 == null && array1 != null && array1.length > 0) ||
 1340  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1341  10
                 return false;
 1342  
         }
 1343  6
         return true;
 1344  
     }
 1345  
 
 1346  
     /**
 1347  
      * <p>Checks whether two arrays are the same length, treating
 1348  
      * {@code null} arrays as length {@code 0}.</p>
 1349  
      *
 1350  
      * @param array1 the first array, may be {@code null}
 1351  
      * @param array2 the second array, may be {@code null}
 1352  
      * @return {@code true} if length of arrays matches, treating
 1353  
      *  {@code null} as an empty array
 1354  
      */
 1355  
     public static boolean isSameLength(final float[] array1, final float[] array2) {
 1356  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1357  
             (array2 == null && array1 != null && array1.length > 0) ||
 1358  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1359  10
                 return false;
 1360  
         }
 1361  6
         return true;
 1362  
     }
 1363  
 
 1364  
     /**
 1365  
      * <p>Checks whether two arrays are the same length, treating
 1366  
      * {@code null} arrays as length {@code 0}.</p>
 1367  
      *
 1368  
      * @param array1 the first array, may be {@code null}
 1369  
      * @param array2 the second array, may be {@code null}
 1370  
      * @return {@code true} if length of arrays matches, treating
 1371  
      *  {@code null} as an empty array
 1372  
      */
 1373  
     public static boolean isSameLength(final boolean[] array1, final boolean[] array2) {
 1374  16
         if ((array1 == null && array2 != null && array2.length > 0) ||
 1375  
             (array2 == null && array1 != null && array1.length > 0) ||
 1376  
             (array1 != null && array2 != null && array1.length != array2.length)) {
 1377  10
                 return false;
 1378  
         }
 1379  6
         return true;
 1380  
     }
 1381  
 
 1382  
     //-----------------------------------------------------------------------
 1383  
     /**
 1384  
      * <p>Returns the length of the specified array.
 1385  
      * This method can deal with {@code Object} arrays and with primitive arrays.</p>
 1386  
      *
 1387  
      * <p>If the input array is {@code null}, {@code 0} is returned.</p>
 1388  
      *
 1389  
      * <pre>
 1390  
      * ArrayUtils.getLength(null)            = 0
 1391  
      * ArrayUtils.getLength([])              = 0
 1392  
      * ArrayUtils.getLength([null])          = 1
 1393  
      * ArrayUtils.getLength([true, false])   = 2
 1394  
      * ArrayUtils.getLength([1, 2, 3])       = 3
 1395  
      * ArrayUtils.getLength(["a", "b", "c"]) = 3
 1396  
      * </pre>
 1397  
      *
 1398  
      * @param array  the array to retrieve the length from, may be null
 1399  
      * @return The length of the array, or {@code 0} if the array is {@code null}
 1400  
      * @throws IllegalArgumentException if the object argument is not an array.
 1401  
      * @since 2.1
 1402  
      */
 1403  
     public static int getLength(final Object array) {
 1404  180353
         if (array == null) {
 1405  27
             return 0;
 1406  
         }
 1407  180326
         return Array.getLength(array);
 1408  
     }
 1409  
 
 1410  
     /**
 1411  
      * <p>Checks whether two arrays are the same type taking into account
 1412  
      * multi-dimensional arrays.</p>
 1413  
      *
 1414  
      * @param array1 the first array, must not be {@code null}
 1415  
      * @param array2 the second array, must not be {@code null}
 1416  
      * @return {@code true} if type of arrays matches
 1417  
      * @throws IllegalArgumentException if either array is {@code null}
 1418  
      */
 1419  
     public static boolean isSameType(final Object array1, final Object array2) {
 1420  8
         if (array1 == null || array2 == null) {
 1421  3
             throw new IllegalArgumentException("The Array must not be null");
 1422  
         }
 1423  5
         return array1.getClass().getName().equals(array2.getClass().getName());
 1424  
     }
 1425  
 
 1426  
     // Reverse
 1427  
     //-----------------------------------------------------------------------
 1428  
     /**
 1429  
      * <p>Reverses the order of the given array.</p>
 1430  
      *
 1431  
      * <p>There is no special handling for multi-dimensional arrays.</p>
 1432  
      *
 1433  
      * <p>This method does nothing for a {@code null} input array.</p>
 1434  
      *
 1435  
      * @param array  the array to reverse, may be {@code null}
 1436  
      */
 1437  
     public static void reverse(final Object[] array) {
 1438  7
         if (array == null) {
 1439  1
             return;
 1440  
         }
 1441  6
         reverse(array, 0, array.length);
 1442  6
     }
 1443  
 
 1444  
     /**
 1445  
      * <p>Reverses the order of the given array.</p>
 1446  
      *
 1447  
      * <p>This method does nothing for a {@code null} input array.</p>
 1448  
      *
 1449  
      * @param array  the array to reverse, may be {@code null}
 1450  
      */
 1451  
     public static void reverse(final long[] array) {
 1452  51
         if (array == null) {
 1453  1
             return;
 1454  
         }
 1455  50
         reverse(array, 0, array.length);
 1456  50
     }
 1457  
 
 1458  
     /**
 1459  
      * <p>Reverses the order of the given array.</p>
 1460  
      *
 1461  
      * <p>This method does nothing for a {@code null} input array.</p>
 1462  
      *
 1463  
      * @param array  the array to reverse, may be {@code null}
 1464  
      */
 1465  
     public static void reverse(final int[] array) {
 1466  2
         if (array == null) {
 1467  1
             return;
 1468  
         }
 1469  1
         reverse(array, 0, array.length);
 1470  1
     }
 1471  
 
 1472  
     /**
 1473  
      * <p>Reverses the order of the given array.</p>
 1474  
      *
 1475  
      * <p>This method does nothing for a {@code null} input array.</p>
 1476  
      *
 1477  
      * @param array  the array to reverse, may be {@code null}
 1478  
      */
 1479  
     public static void reverse(final short[] array) {
 1480  2
         if (array == null) {
 1481  1
             return;
 1482  
         }
 1483  1
         reverse(array, 0, array.length);
 1484  1
     }
 1485  
 
 1486  
     /**
 1487  
      * <p>Reverses the order of the given array.</p>
 1488  
      *
 1489  
      * <p>This method does nothing for a {@code null} input array.</p>
 1490  
      *
 1491  
      * @param array  the array to reverse, may be {@code null}
 1492  
      */
 1493  
     public static void reverse(final char[] array) {
 1494  2
         if (array == null) {
 1495  1
             return;
 1496  
         }
 1497  1
         reverse(array, 0, array.length);
 1498  1
     }
 1499  
 
 1500  
     /**
 1501  
      * <p>Reverses the order of the given array.</p>
 1502  
      *
 1503  
      * <p>This method does nothing for a {@code null} input array.</p>
 1504  
      *
 1505  
      * @param array  the array to reverse, may be {@code null}
 1506  
      */
 1507  
     public static void reverse(final byte[] array) {
 1508  2
         if (array == null) {
 1509  1
             return;
 1510  
         }
 1511  1
         reverse(array, 0, array.length);
 1512  1
     }
 1513  
 
 1514  
     /**
 1515  
      * <p>Reverses the order of the given array.</p>
 1516  
      *
 1517  
      * <p>This method does nothing for a {@code null} input array.</p>
 1518  
      *
 1519  
      * @param array  the array to reverse, may be {@code null}
 1520  
      */
 1521  
     public static void reverse(final double[] array) {
 1522  2
         if (array == null) {
 1523  1
             return;
 1524  
         }
 1525  1
         reverse(array, 0, array.length);
 1526  1
     }
 1527  
 
 1528  
     /**
 1529  
      * <p>Reverses the order of the given array.</p>
 1530  
      *
 1531  
      * <p>This method does nothing for a {@code null} input array.</p>
 1532  
      *
 1533  
      * @param array  the array to reverse, may be {@code null}
 1534  
      */
 1535  
     public static void reverse(final float[] array) {
 1536  2
         if (array == null) {
 1537  1
             return;
 1538  
         }
 1539  1
         reverse(array, 0, array.length);
 1540  1
     }
 1541  
 
 1542  
     /**
 1543  
      * <p>Reverses the order of the given array.</p>
 1544  
      *
 1545  
      * <p>This method does nothing for a {@code null} input array.</p>
 1546  
      *
 1547  
      * @param array  the array to reverse, may be {@code null}
 1548  
      */
 1549  
     public static void reverse(final boolean[] array) {
 1550  2
         if (array == null) {
 1551  1
             return;
 1552  
         }
 1553  1
         reverse(array, 0, array.length);
 1554  1
     }
 1555  
 
 1556  
     /**
 1557  
      * <p>
 1558  
      * Reverses the order of the given array in the given range.
 1559  
      * </p>
 1560  
      * 
 1561  
      * <p>
 1562  
      * This method does nothing for a {@code null} input array.
 1563  
      * </p>
 1564  
      * 
 1565  
      * @param array
 1566  
      *            the array to reverse, may be {@code null}
 1567  
      * @param startIndexInclusive
 1568  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1569  
      *            change.
 1570  
      * @param endIndexExclusive
 1571  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1572  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1573  
      * @since 3.2
 1574  
      */
 1575  
     public static void reverse(final boolean[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1576  6
         if (array == null) {
 1577  1
             return;
 1578  
         }
 1579  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1580  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1581  
         boolean tmp;
 1582  10
         while (j > i) {
 1583  5
             tmp = array[j];
 1584  5
             array[j] = array[i];
 1585  5
             array[i] = tmp;
 1586  5
             j--;
 1587  5
             i++;
 1588  
         }
 1589  5
     }
 1590  
 
 1591  
     /**
 1592  
      * <p>
 1593  
      * Reverses the order of the given array in the given range.
 1594  
      * </p>
 1595  
      * 
 1596  
      * <p>
 1597  
      * This method does nothing for a {@code null} input array.
 1598  
      * </p>
 1599  
      * 
 1600  
      * @param array
 1601  
      *            the array to reverse, may be {@code null}
 1602  
      * @param startIndexInclusive
 1603  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1604  
      *            change.
 1605  
      * @param endIndexExclusive
 1606  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1607  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1608  
      * @since 3.2
 1609  
      */
 1610  
     public static void reverse(final byte[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1611  6
         if (array == null) {
 1612  1
             return;
 1613  
         }
 1614  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1615  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1616  
         byte tmp;
 1617  10
         while (j > i) {
 1618  5
             tmp = array[j];
 1619  5
             array[j] = array[i];
 1620  5
             array[i] = tmp;
 1621  5
             j--;
 1622  5
             i++;
 1623  
         }
 1624  5
     }
 1625  
 
 1626  
     /**
 1627  
      * <p>
 1628  
      * Reverses the order of the given array in the given range.
 1629  
      * </p>
 1630  
      * 
 1631  
      * <p>
 1632  
      * This method does nothing for a {@code null} input array.
 1633  
      * </p>
 1634  
      * 
 1635  
      * @param array
 1636  
      *            the array to reverse, may be {@code null}
 1637  
      * @param startIndexInclusive
 1638  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1639  
      *            change.
 1640  
      * @param endIndexExclusive
 1641  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1642  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1643  
      * @since 3.2
 1644  
      */
 1645  
     public static void reverse(final char[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1646  6
         if (array == null) {
 1647  1
             return;
 1648  
         }
 1649  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1650  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1651  
         char tmp;
 1652  10
         while (j > i) {
 1653  5
             tmp = array[j];
 1654  5
             array[j] = array[i];
 1655  5
             array[i] = tmp;
 1656  5
             j--;
 1657  5
             i++;
 1658  
         }
 1659  5
     }
 1660  
 
 1661  
     /**
 1662  
      * <p>
 1663  
      * Reverses the order of the given array in the given range.
 1664  
      * </p>
 1665  
      * 
 1666  
      * <p>
 1667  
      * This method does nothing for a {@code null} input array.
 1668  
      * </p>
 1669  
      * 
 1670  
      * @param array
 1671  
      *            the array to reverse, may be {@code null}
 1672  
      * @param startIndexInclusive
 1673  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1674  
      *            change.
 1675  
      * @param endIndexExclusive
 1676  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1677  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1678  
      * @since 3.2
 1679  
      */
 1680  
     public static void reverse(final double[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1681  6
         if (array == null) {
 1682  1
             return;
 1683  
         }
 1684  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1685  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1686  
         double tmp;
 1687  10
         while (j > i) {
 1688  5
             tmp = array[j];
 1689  5
             array[j] = array[i];
 1690  5
             array[i] = tmp;
 1691  5
             j--;
 1692  5
             i++;
 1693  
         }
 1694  5
     }
 1695  
 
 1696  
     /**
 1697  
      * <p>
 1698  
      * Reverses the order of the given array in the given range.
 1699  
      * </p>
 1700  
      * 
 1701  
      * <p>
 1702  
      * This method does nothing for a {@code null} input array.
 1703  
      * </p>
 1704  
      * 
 1705  
      * @param array
 1706  
      *            the array to reverse, may be {@code null}
 1707  
      * @param startIndexInclusive
 1708  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1709  
      *            change.
 1710  
      * @param endIndexExclusive
 1711  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1712  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1713  
      * @since 3.2
 1714  
      */
 1715  
     public static void reverse(final float[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1716  6
         if (array == null) {
 1717  1
             return;
 1718  
         }
 1719  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1720  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1721  
         float tmp;
 1722  10
         while (j > i) {
 1723  5
             tmp = array[j];
 1724  5
             array[j] = array[i];
 1725  5
             array[i] = tmp;
 1726  5
             j--;
 1727  5
             i++;
 1728  
         }
 1729  5
     }
 1730  
 
 1731  
     /**
 1732  
      * <p>
 1733  
      * Reverses the order of the given array in the given range.
 1734  
      * </p>
 1735  
      * 
 1736  
      * <p>
 1737  
      * This method does nothing for a {@code null} input array.
 1738  
      * </p>
 1739  
      * 
 1740  
      * @param array
 1741  
      *            the array to reverse, may be {@code null}
 1742  
      * @param startIndexInclusive
 1743  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1744  
      *            change.
 1745  
      * @param endIndexExclusive
 1746  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1747  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1748  
      * @since 3.2
 1749  
      */
 1750  
     public static void reverse(final int[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1751  6
         if (array == null) {
 1752  1
             return;
 1753  
         }
 1754  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1755  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1756  
         int tmp;
 1757  10
         while (j > i) {
 1758  5
             tmp = array[j];
 1759  5
             array[j] = array[i];
 1760  5
             array[i] = tmp;
 1761  5
             j--;
 1762  5
             i++;
 1763  
         }
 1764  5
     }
 1765  
 
 1766  
     /**
 1767  
      * <p>
 1768  
      * Reverses the order of the given array in the given range.
 1769  
      * </p>
 1770  
      * 
 1771  
      * <p>
 1772  
      * This method does nothing for a {@code null} input array.
 1773  
      * </p>
 1774  
      * 
 1775  
      * @param array
 1776  
      *            the array to reverse, may be {@code null}
 1777  
      * @param startIndexInclusive
 1778  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1779  
      *            change.
 1780  
      * @param endIndexExclusive
 1781  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1782  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1783  
      * @since 3.2
 1784  
      */
 1785  
     public static void reverse(final long[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1786  55
         if (array == null) {
 1787  1
             return;
 1788  
         }
 1789  54
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1790  54
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1791  
         long tmp;
 1792  75
         while (j > i) {
 1793  21
             tmp = array[j];
 1794  21
             array[j] = array[i];
 1795  21
             array[i] = tmp;
 1796  21
             j--;
 1797  21
             i++;
 1798  
         }
 1799  54
     }
 1800  
 
 1801  
     /**
 1802  
      * <p>
 1803  
      * Reverses the order of the given array in the given range.
 1804  
      * </p>
 1805  
      * 
 1806  
      * <p>
 1807  
      * This method does nothing for a {@code null} input array.
 1808  
      * </p>
 1809  
      * 
 1810  
      * @param array
 1811  
      *            the array to reverse, may be {@code null}
 1812  
      * @param startIndexInclusive
 1813  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1814  
      *            change.
 1815  
      * @param endIndexExclusive
 1816  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1817  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1818  
      * @since 3.2
 1819  
      */
 1820  
     public static void reverse(final Object[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1821  11
         if (array == null) {
 1822  1
             return;
 1823  
         }
 1824  10
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1825  10
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1826  
         Object tmp;
 1827  18
         while (j > i) {
 1828  8
             tmp = array[j];
 1829  8
             array[j] = array[i];
 1830  8
             array[i] = tmp;
 1831  8
             j--;
 1832  8
             i++;
 1833  
         }
 1834  10
     }
 1835  
 
 1836  
     /**
 1837  
      * <p>
 1838  
      * Reverses the order of the given array in the given range.
 1839  
      * </p>
 1840  
      * 
 1841  
      * <p>
 1842  
      * This method does nothing for a {@code null} input array.
 1843  
      * </p>
 1844  
      * 
 1845  
      * @param array
 1846  
      *            the array to reverse, may be {@code null}
 1847  
      * @param startIndexInclusive
 1848  
      *            the starting index. Undervalue (&lt;0) is promoted to 0, overvalue (&gt;array.length) results in no
 1849  
      *            change.
 1850  
      * @param endIndexExclusive
 1851  
      *            elements up to endIndex-1 are reversed in the array. Undervalue (&lt; start index) results in no
 1852  
      *            change. Overvalue (&gt;array.length) is demoted to array length.
 1853  
      * @since 3.2
 1854  
      */
 1855  
     public static void reverse(final short[] array, final int startIndexInclusive, final int endIndexExclusive) {
 1856  6
         if (array == null) {
 1857  1
             return;
 1858  
         }
 1859  5
         int i = startIndexInclusive < 0 ? 0 : startIndexInclusive;
 1860  5
         int j = Math.min(array.length, endIndexExclusive) - 1;
 1861  
         short tmp;
 1862  10
         while (j > i) {
 1863  5
             tmp = array[j];
 1864  5
             array[j] = array[i];
 1865  5
             array[i] = tmp;
 1866  5
             j--;
 1867  5
             i++;
 1868  
         }
 1869  5
     }
 1870  
 
 1871  
     // IndexOf search
 1872  
     // ----------------------------------------------------------------------
 1873  
 
 1874  
     // Object IndexOf
 1875  
     //-----------------------------------------------------------------------
 1876  
     /**
 1877  
      * <p>Finds the index of the given object in the array.</p>
 1878  
      *
 1879  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 1880  
      *
 1881  
      * @param array  the array to search through for the object, may be {@code null}
 1882  
      * @param objectToFind  the object to find, may be {@code null}
 1883  
      * @return the index of the object within the array,
 1884  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 1885  
      */
 1886  
     public static int indexOf(final Object[] array, final Object objectToFind) {
 1887  1143
         return indexOf(array, objectToFind, 0);
 1888  
     }
 1889  
 
 1890  
     /**
 1891  
      * <p>Finds the index of the given object in the array starting at the given index.</p>
 1892  
      *
 1893  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 1894  
      *
 1895  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 1896  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 1897  
      *
 1898  
      * @param array  the array to search through for the object, may be {@code null}
 1899  
      * @param objectToFind  the object to find, may be {@code null}
 1900  
      * @param startIndex  the index to start searching at
 1901  
      * @return the index of the object within the array starting at the index,
 1902  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 1903  
      */
 1904  
     public static int indexOf(final Object[] array, final Object objectToFind, int startIndex) {
 1905  1170
         if (array == null) {
 1906  72
             return INDEX_NOT_FOUND;
 1907  
         }
 1908  1098
         if (startIndex < 0) {
 1909  1
             startIndex = 0;
 1910  
         }
 1911  1098
         if (objectToFind == null) {
 1912  19
             for (int i = startIndex; i < array.length; i++) {
 1913  18
                 if (array[i] == null) {
 1914  4
                     return i;
 1915  
                 }
 1916  
             }
 1917  1093
         } else if (array.getClass().getComponentType().isInstance(objectToFind)) {
 1918  1223
             for (int i = startIndex; i < array.length; i++) {
 1919  255
                 if (objectToFind.equals(array[i])) {
 1920  125
                     return i;
 1921  
                 }
 1922  
             }
 1923  
         }
 1924  969
         return INDEX_NOT_FOUND;
 1925  
     }
 1926  
 
 1927  
     /**
 1928  
      * <p>Finds the last index of the given object within the array.</p>
 1929  
      *
 1930  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 1931  
      *
 1932  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 1933  
      * @param objectToFind  the object to find, may be {@code null}
 1934  
      * @return the last index of the object within the array,
 1935  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 1936  
      */
 1937  
     public static int lastIndexOf(final Object[] array, final Object objectToFind) {
 1938  8
         return lastIndexOf(array, objectToFind, Integer.MAX_VALUE);
 1939  
     }
 1940  
 
 1941  
     /**
 1942  
      * <p>Finds the last index of the given object in the array starting at the given index.</p>
 1943  
      *
 1944  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 1945  
      *
 1946  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than
 1947  
      * the array length will search from the end of the array.</p>
 1948  
      *
 1949  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 1950  
      * @param objectToFind  the object to find, may be {@code null}
 1951  
      * @param startIndex  the start index to travers backwards from
 1952  
      * @return the last index of the object within the array,
 1953  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 1954  
      */
 1955  
     public static int lastIndexOf(final Object[] array, final Object objectToFind, int startIndex) {
 1956  20
         if (array == null) {
 1957  4
             return INDEX_NOT_FOUND;
 1958  
         }
 1959  16
         if (startIndex < 0) {
 1960  2
             return INDEX_NOT_FOUND;
 1961  14
         } else if (startIndex >= array.length) {
 1962  7
             startIndex = array.length - 1;
 1963  
         }
 1964  14
         if (objectToFind == null) {
 1965  8
             for (int i = startIndex; i >= 0; i--) {
 1966  7
                 if (array[i] == null) {
 1967  2
                     return i;
 1968  
                 }
 1969  
             }
 1970  11
         } else if (array.getClass().getComponentType().isInstance(objectToFind)) {
 1971  38
             for (int i = startIndex; i >= 0; i--) {
 1972  35
                 if (objectToFind.equals(array[i])) {
 1973  8
                     return i;
 1974  
                 }
 1975  
             }
 1976  
         }
 1977  4
         return INDEX_NOT_FOUND;
 1978  
     }
 1979  
 
 1980  
     /**
 1981  
      * <p>Checks if the object is in the given array.</p>
 1982  
      *
 1983  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 1984  
      *
 1985  
      * @param array  the array to search through
 1986  
      * @param objectToFind  the object to find
 1987  
      * @return {@code true} if the array contains the object
 1988  
      */
 1989  
     public static boolean contains(final Object[] array, final Object objectToFind) {
 1990  1129
         return indexOf(array, objectToFind) != INDEX_NOT_FOUND;
 1991  
     }
 1992  
 
 1993  
     // long IndexOf
 1994  
     //-----------------------------------------------------------------------
 1995  
     /**
 1996  
      * <p>Finds the index of the given value in the array.</p>
 1997  
      *
 1998  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 1999  
      *
 2000  
      * @param array  the array to search through for the object, may be {@code null}
 2001  
      * @param valueToFind  the value to find
 2002  
      * @return the index of the value within the array,
 2003  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2004  
      */
 2005  
     public static int indexOf(final long[] array, final long valueToFind) {
 2006  17
         return indexOf(array, valueToFind, 0);
 2007  
     }
 2008  
 
 2009  
     /**
 2010  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2011  
      *
 2012  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2013  
      *
 2014  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2015  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2016  
      *
 2017  
      * @param array  the array to search through for the object, may be {@code null}
 2018  
      * @param valueToFind  the value to find
 2019  
      * @param startIndex  the index to start searching at
 2020  
      * @return the index of the value within the array,
 2021  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2022  
      */
 2023  
     public static int indexOf(final long[] array, final long valueToFind, int startIndex) {
 2024  41
         if (array == null) {
 2025  4
             return INDEX_NOT_FOUND;
 2026  
         }
 2027  37
         if (startIndex < 0) {
 2028  1
             startIndex = 0;
 2029  
         }
 2030  78
         for (int i = startIndex; i < array.length; i++) {
 2031  69
             if (valueToFind == array[i]) {
 2032  28
                 return i;
 2033  
             }
 2034  
         }
 2035  9
         return INDEX_NOT_FOUND;
 2036  
     }
 2037  
 
 2038  
     /**
 2039  
      * <p>Finds the last index of the given value within the array.</p>
 2040  
      *
 2041  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2042  
      *
 2043  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2044  
      * @param valueToFind  the object to find
 2045  
      * @return the last index of the value within the array,
 2046  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2047  
      */
 2048  
     public static int lastIndexOf(final long[] array, final long valueToFind) {
 2049  6
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2050  
     }
 2051  
 
 2052  
     /**
 2053  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2054  
      *
 2055  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2056  
      *
 2057  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2058  
      * array length will search from the end of the array.</p>
 2059  
      *
 2060  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2061  
      * @param valueToFind  the value to find
 2062  
      * @param startIndex  the start index to travers backwards from
 2063  
      * @return the last index of the value within the array,
 2064  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2065  
      */
 2066  
     public static int lastIndexOf(final long[] array, final long valueToFind, int startIndex) {
 2067  14
         if (array == null) {
 2068  2
             return INDEX_NOT_FOUND;
 2069  
         }
 2070  12
         if (startIndex < 0) {
 2071  1
             return INDEX_NOT_FOUND;
 2072  11
         } else if (startIndex >= array.length) {
 2073  6
             startIndex = array.length - 1;
 2074  
         }
 2075  33
         for (int i = startIndex; i >= 0; i--) {
 2076  30
             if (valueToFind == array[i]) {
 2077  8
                 return i;
 2078  
             }
 2079  
         }
 2080  3
         return INDEX_NOT_FOUND;
 2081  
     }
 2082  
 
 2083  
     /**
 2084  
      * <p>Checks if the value is in the given array.</p>
 2085  
      *
 2086  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2087  
      *
 2088  
      * @param array  the array to search through
 2089  
      * @param valueToFind  the value to find
 2090  
      * @return {@code true} if the array contains the object
 2091  
      */
 2092  
     public static boolean contains(final long[] array, final long valueToFind) {
 2093  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2094  
     }
 2095  
 
 2096  
     // int IndexOf
 2097  
     //-----------------------------------------------------------------------
 2098  
     /**
 2099  
      * <p>Finds the index of the given value in the array.</p>
 2100  
      *
 2101  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2102  
      *
 2103  
      * @param array  the array to search through for the object, may be {@code null}
 2104  
      * @param valueToFind  the value to find
 2105  
      * @return the index of the value within the array,
 2106  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2107  
      */
 2108  
     public static int indexOf(final int[] array, final int valueToFind) {
 2109  17
         return indexOf(array, valueToFind, 0);
 2110  
     }
 2111  
 
 2112  
     /**
 2113  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2114  
      *
 2115  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2116  
      *
 2117  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2118  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2119  
      *
 2120  
      * @param array  the array to search through for the object, may be {@code null}
 2121  
      * @param valueToFind  the value to find
 2122  
      * @param startIndex  the index to start searching at
 2123  
      * @return the index of the value within the array,
 2124  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2125  
      */
 2126  
     public static int indexOf(final int[] array, final int valueToFind, int startIndex) {
 2127  41
         if (array == null) {
 2128  4
             return INDEX_NOT_FOUND;
 2129  
         }
 2130  37
         if (startIndex < 0) {
 2131  1
             startIndex = 0;
 2132  
         }
 2133  78
         for (int i = startIndex; i < array.length; i++) {
 2134  69
             if (valueToFind == array[i]) {
 2135  28
                 return i;
 2136  
             }
 2137  
         }
 2138  9
         return INDEX_NOT_FOUND;
 2139  
     }
 2140  
 
 2141  
     /**
 2142  
      * <p>Finds the last index of the given value within the array.</p>
 2143  
      *
 2144  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2145  
      *
 2146  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2147  
      * @param valueToFind  the object to find
 2148  
      * @return the last index of the value within the array,
 2149  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2150  
      */
 2151  
     public static int lastIndexOf(final int[] array, final int valueToFind) {
 2152  7
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2153  
     }
 2154  
 
 2155  
     /**
 2156  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2157  
      *
 2158  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2159  
      *
 2160  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2161  
      * array length will search from the end of the array.</p>
 2162  
      *
 2163  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2164  
      * @param valueToFind  the value to find
 2165  
      * @param startIndex  the start index to travers backwards from
 2166  
      * @return the last index of the value within the array,
 2167  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2168  
      */
 2169  
     public static int lastIndexOf(final int[] array, final int valueToFind, int startIndex) {
 2170  14
         if (array == null) {
 2171  2
             return INDEX_NOT_FOUND;
 2172  
         }
 2173  12
         if (startIndex < 0) {
 2174  1
             return INDEX_NOT_FOUND;
 2175  11
         } else if (startIndex >= array.length) {
 2176  7
             startIndex = array.length - 1;
 2177  
         }
 2178  33
         for (int i = startIndex; i >= 0; i--) {
 2179  30
             if (valueToFind == array[i]) {
 2180  8
                 return i;
 2181  
             }
 2182  
         }
 2183  3
         return INDEX_NOT_FOUND;
 2184  
     }
 2185  
 
 2186  
     /**
 2187  
      * <p>Checks if the value is in the given array.</p>
 2188  
      *
 2189  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2190  
      *
 2191  
      * @param array  the array to search through
 2192  
      * @param valueToFind  the value to find
 2193  
      * @return {@code true} if the array contains the object
 2194  
      */
 2195  
     public static boolean contains(final int[] array, final int valueToFind) {
 2196  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2197  
     }
 2198  
 
 2199  
     // short IndexOf
 2200  
     //-----------------------------------------------------------------------
 2201  
     /**
 2202  
      * <p>Finds the index of the given value in the array.</p>
 2203  
      *
 2204  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2205  
      *
 2206  
      * @param array  the array to search through for the object, may be {@code null}
 2207  
      * @param valueToFind  the value to find
 2208  
      * @return the index of the value within the array,
 2209  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2210  
      */
 2211  
     public static int indexOf(final short[] array, final short valueToFind) {
 2212  17
         return indexOf(array, valueToFind, 0);
 2213  
     }
 2214  
 
 2215  
     /**
 2216  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2217  
      *
 2218  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2219  
      *
 2220  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2221  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2222  
      *
 2223  
      * @param array  the array to search through for the object, may be {@code null}
 2224  
      * @param valueToFind  the value to find
 2225  
      * @param startIndex  the index to start searching at
 2226  
      * @return the index of the value within the array,
 2227  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2228  
      */
 2229  
     public static int indexOf(final short[] array, final short valueToFind, int startIndex) {
 2230  41
         if (array == null) {
 2231  4
             return INDEX_NOT_FOUND;
 2232  
         }
 2233  37
         if (startIndex < 0) {
 2234  1
             startIndex = 0;
 2235  
         }
 2236  78
         for (int i = startIndex; i < array.length; i++) {
 2237  69
             if (valueToFind == array[i]) {
 2238  28
                 return i;
 2239  
             }
 2240  
         }
 2241  9
         return INDEX_NOT_FOUND;
 2242  
     }
 2243  
 
 2244  
     /**
 2245  
      * <p>Finds the last index of the given value within the array.</p>
 2246  
      *
 2247  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2248  
      *
 2249  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2250  
      * @param valueToFind  the object to find
 2251  
      * @return the last index of the value within the array,
 2252  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2253  
      */
 2254  
     public static int lastIndexOf(final short[] array, final short valueToFind) {
 2255  7
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2256  
     }
 2257  
 
 2258  
     /**
 2259  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2260  
      *
 2261  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2262  
      *
 2263  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2264  
      * array length will search from the end of the array.</p>
 2265  
      *
 2266  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2267  
      * @param valueToFind  the value to find
 2268  
      * @param startIndex  the start index to travers backwards from
 2269  
      * @return the last index of the value within the array,
 2270  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2271  
      */
 2272  
     public static int lastIndexOf(final short[] array, final short valueToFind, int startIndex) {
 2273  14
         if (array == null) {
 2274  2
             return INDEX_NOT_FOUND;
 2275  
         }
 2276  12
         if (startIndex < 0) {
 2277  1
             return INDEX_NOT_FOUND;
 2278  11
         } else if (startIndex >= array.length) {
 2279  7
             startIndex = array.length - 1;
 2280  
         }
 2281  33
         for (int i = startIndex; i >= 0; i--) {
 2282  30
             if (valueToFind == array[i]) {
 2283  8
                 return i;
 2284  
             }
 2285  
         }
 2286  3
         return INDEX_NOT_FOUND;
 2287  
     }
 2288  
 
 2289  
     /**
 2290  
      * <p>Checks if the value is in the given array.</p>
 2291  
      *
 2292  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2293  
      *
 2294  
      * @param array  the array to search through
 2295  
      * @param valueToFind  the value to find
 2296  
      * @return {@code true} if the array contains the object
 2297  
      */
 2298  
     public static boolean contains(final short[] array, final short valueToFind) {
 2299  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2300  
     }
 2301  
 
 2302  
     // char IndexOf
 2303  
     //-----------------------------------------------------------------------
 2304  
     /**
 2305  
      * <p>Finds the index of the given value in the array.</p>
 2306  
      *
 2307  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2308  
      *
 2309  
      * @param array  the array to search through for the object, may be {@code null}
 2310  
      * @param valueToFind  the value to find
 2311  
      * @return the index of the value within the array,
 2312  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2313  
      * @since 2.1
 2314  
      */
 2315  
     public static int indexOf(final char[] array, final char valueToFind) {
 2316  17
         return indexOf(array, valueToFind, 0);
 2317  
     }
 2318  
 
 2319  
     /**
 2320  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2321  
      *
 2322  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2323  
      *
 2324  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2325  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2326  
      *
 2327  
      * @param array  the array to search through for the object, may be {@code null}
 2328  
      * @param valueToFind  the value to find
 2329  
      * @param startIndex  the index to start searching at
 2330  
      * @return the index of the value within the array,
 2331  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2332  
      * @since 2.1
 2333  
      */
 2334  
     public static int indexOf(final char[] array, final char valueToFind, int startIndex) {
 2335  41
         if (array == null) {
 2336  4
             return INDEX_NOT_FOUND;
 2337  
         }
 2338  37
         if (startIndex < 0) {
 2339  1
             startIndex = 0;
 2340  
         }
 2341  79
         for (int i = startIndex; i < array.length; i++) {
 2342  70
             if (valueToFind == array[i]) {
 2343  28
                 return i;
 2344  
             }
 2345  
         }
 2346  9
         return INDEX_NOT_FOUND;
 2347  
     }
 2348  
 
 2349  
     /**
 2350  
      * <p>Finds the last index of the given value within the array.</p>
 2351  
      *
 2352  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2353  
      *
 2354  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2355  
      * @param valueToFind  the object to find
 2356  
      * @return the last index of the value within the array,
 2357  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2358  
      * @since 2.1
 2359  
      */
 2360  
     public static int lastIndexOf(final char[] array, final char valueToFind) {
 2361  7
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2362  
     }
 2363  
 
 2364  
     /**
 2365  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2366  
      *
 2367  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2368  
      *
 2369  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2370  
      * array length will search from the end of the array.</p>
 2371  
      *
 2372  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2373  
      * @param valueToFind  the value to find
 2374  
      * @param startIndex  the start index to travers backwards from
 2375  
      * @return the last index of the value within the array,
 2376  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2377  
      * @since 2.1
 2378  
      */
 2379  
     public static int lastIndexOf(final char[] array, final char valueToFind, int startIndex) {
 2380  14
         if (array == null) {
 2381  2
             return INDEX_NOT_FOUND;
 2382  
         }
 2383  12
         if (startIndex < 0) {
 2384  1
             return INDEX_NOT_FOUND;
 2385  11
         } else if (startIndex >= array.length) {
 2386  7
             startIndex = array.length - 1;
 2387  
         }
 2388  33
         for (int i = startIndex; i >= 0; i--) {
 2389  30
             if (valueToFind == array[i]) {
 2390  8
                 return i;
 2391  
             }
 2392  
         }
 2393  3
         return INDEX_NOT_FOUND;
 2394  
     }
 2395  
 
 2396  
     /**
 2397  
      * <p>Checks if the value is in the given array.</p>
 2398  
      *
 2399  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2400  
      *
 2401  
      * @param array  the array to search through
 2402  
      * @param valueToFind  the value to find
 2403  
      * @return {@code true} if the array contains the object
 2404  
      * @since 2.1
 2405  
      */
 2406  
     public static boolean contains(final char[] array, final char valueToFind) {
 2407  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2408  
     }
 2409  
 
 2410  
     // byte IndexOf
 2411  
     //-----------------------------------------------------------------------
 2412  
     /**
 2413  
      * <p>Finds the index of the given value in the array.</p>
 2414  
      *
 2415  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2416  
      *
 2417  
      * @param array  the array to search through for the object, may be {@code null}
 2418  
      * @param valueToFind  the value to find
 2419  
      * @return the index of the value within the array,
 2420  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2421  
      */
 2422  
     public static int indexOf(final byte[] array, final byte valueToFind) {
 2423  17
         return indexOf(array, valueToFind, 0);
 2424  
     }
 2425  
 
 2426  
     /**
 2427  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2428  
      *
 2429  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2430  
      *
 2431  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2432  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2433  
      *
 2434  
      * @param array  the array to search through for the object, may be {@code null}
 2435  
      * @param valueToFind  the value to find
 2436  
      * @param startIndex  the index to start searching at
 2437  
      * @return the index of the value within the array,
 2438  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2439  
      */
 2440  
     public static int indexOf(final byte[] array, final byte valueToFind, int startIndex) {
 2441  41
         if (array == null) {
 2442  4
             return INDEX_NOT_FOUND;
 2443  
         }
 2444  37
         if (startIndex < 0) {
 2445  1
             startIndex = 0;
 2446  
         }
 2447  79
         for (int i = startIndex; i < array.length; i++) {
 2448  70
             if (valueToFind == array[i]) {
 2449  28
                 return i;
 2450  
             }
 2451  
         }
 2452  9
         return INDEX_NOT_FOUND;
 2453  
     }
 2454  
 
 2455  
     /**
 2456  
      * <p>Finds the last index of the given value within the array.</p>
 2457  
      *
 2458  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2459  
      *
 2460  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2461  
      * @param valueToFind  the object to find
 2462  
      * @return the last index of the value within the array,
 2463  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2464  
      */
 2465  
     public static int lastIndexOf(final byte[] array, final byte valueToFind) {
 2466  7
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2467  
     }
 2468  
 
 2469  
     /**
 2470  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2471  
      *
 2472  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2473  
      *
 2474  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2475  
      * array length will search from the end of the array.</p>
 2476  
      *
 2477  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2478  
      * @param valueToFind  the value to find
 2479  
      * @param startIndex  the start index to travers backwards from
 2480  
      * @return the last index of the value within the array,
 2481  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2482  
      */
 2483  
     public static int lastIndexOf(final byte[] array, final byte valueToFind, int startIndex) {
 2484  14
         if (array == null) {
 2485  2
             return INDEX_NOT_FOUND;
 2486  
         }
 2487  12
         if (startIndex < 0) {
 2488  1
             return INDEX_NOT_FOUND;
 2489  11
         } else if (startIndex >= array.length) {
 2490  7
             startIndex = array.length - 1;
 2491  
         }
 2492  33
         for (int i = startIndex; i >= 0; i--) {
 2493  30
             if (valueToFind == array[i]) {
 2494  8
                 return i;
 2495  
             }
 2496  
         }
 2497  3
         return INDEX_NOT_FOUND;
 2498  
     }
 2499  
 
 2500  
     /**
 2501  
      * <p>Checks if the value is in the given array.</p>
 2502  
      *
 2503  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2504  
      *
 2505  
      * @param array  the array to search through
 2506  
      * @param valueToFind  the value to find
 2507  
      * @return {@code true} if the array contains the object
 2508  
      */
 2509  
     public static boolean contains(final byte[] array, final byte valueToFind) {
 2510  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2511  
     }
 2512  
 
 2513  
     // double IndexOf
 2514  
     //-----------------------------------------------------------------------
 2515  
     /**
 2516  
      * <p>Finds the index of the given value in the array.</p>
 2517  
      *
 2518  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2519  
      *
 2520  
      * @param array  the array to search through for the object, may be {@code null}
 2521  
      * @param valueToFind  the value to find
 2522  
      * @return the index of the value within the array,
 2523  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2524  
      */
 2525  
     public static int indexOf(final double[] array, final double valueToFind) {
 2526  18
         return indexOf(array, valueToFind, 0);
 2527  
     }
 2528  
 
 2529  
     /**
 2530  
      * <p>Finds the index of the given value within a given tolerance in the array.
 2531  
      * This method will return the index of the first value which falls between the region
 2532  
      * defined by valueToFind - tolerance and valueToFind + tolerance.</p>
 2533  
      *
 2534  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2535  
      *
 2536  
      * @param array  the array to search through for the object, may be {@code null}
 2537  
      * @param valueToFind  the value to find
 2538  
      * @param tolerance tolerance of the search
 2539  
      * @return the index of the value within the array,
 2540  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2541  
      */
 2542  
     public static int indexOf(final double[] array, final double valueToFind, final double tolerance) {
 2543  6
         return indexOf(array, valueToFind, 0, tolerance);
 2544  
     }
 2545  
 
 2546  
     /**
 2547  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2548  
      *
 2549  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2550  
      *
 2551  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2552  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2553  
      *
 2554  
      * @param array  the array to search through for the object, may be {@code null}
 2555  
      * @param valueToFind  the value to find
 2556  
      * @param startIndex  the index to start searching at
 2557  
      * @return the index of the value within the array,
 2558  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2559  
      */
 2560  
     public static int indexOf(final double[] array, final double valueToFind, int startIndex) {
 2561  43
         if (ArrayUtils.isEmpty(array)) {
 2562  7
             return INDEX_NOT_FOUND;
 2563  
         }
 2564  36
         if (startIndex < 0) {
 2565  1
             startIndex = 0;
 2566  
         }
 2567  78
         for (int i = startIndex; i < array.length; i++) {
 2568  70
             if (valueToFind == array[i]) {
 2569  28
                 return i;
 2570  
             }
 2571  
         }
 2572  8
         return INDEX_NOT_FOUND;
 2573  
     }
 2574  
 
 2575  
     /**
 2576  
      * <p>Finds the index of the given value in the array starting at the given index.
 2577  
      * This method will return the index of the first value which falls between the region
 2578  
      * defined by valueToFind - tolerance and valueToFind + tolerance.</p>
 2579  
      *
 2580  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2581  
      *
 2582  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2583  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2584  
      *
 2585  
      * @param array  the array to search through for the object, may be {@code null}
 2586  
      * @param valueToFind  the value to find
 2587  
      * @param startIndex  the index to start searching at
 2588  
      * @param tolerance tolerance of the search
 2589  
      * @return the index of the value within the array,
 2590  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2591  
      */
 2592  
     public static int indexOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
 2593  21
         if (ArrayUtils.isEmpty(array)) {
 2594  5
             return INDEX_NOT_FOUND;
 2595  
         }
 2596  16
         if (startIndex < 0) {
 2597  2
             startIndex = 0;
 2598  
         }
 2599  16
         final double min = valueToFind - tolerance;
 2600  16
         final double max = valueToFind + tolerance;
 2601  47
         for (int i = startIndex; i < array.length; i++) {
 2602  44
             if (array[i] >= min && array[i] <= max) {
 2603  13
                 return i;
 2604  
             }
 2605  
         }
 2606  3
         return INDEX_NOT_FOUND;
 2607  
     }
 2608  
 
 2609  
     /**
 2610  
      * <p>Finds the last index of the given value within the array.</p>
 2611  
      *
 2612  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2613  
      *
 2614  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2615  
      * @param valueToFind  the object to find
 2616  
      * @return the last index of the value within the array,
 2617  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2618  
      */
 2619  
     public static int lastIndexOf(final double[] array, final double valueToFind) {
 2620  8
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2621  
     }
 2622  
 
 2623  
     /**
 2624  
      * <p>Finds the last index of the given value within a given tolerance in the array.
 2625  
      * This method will return the index of the last value which falls between the region
 2626  
      * defined by valueToFind - tolerance and valueToFind + tolerance.</p>
 2627  
      *
 2628  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2629  
      *
 2630  
      * @param array  the array to search through for the object, may be {@code null}
 2631  
      * @param valueToFind  the value to find
 2632  
      * @param tolerance tolerance of the search
 2633  
      * @return the index of the value within the array,
 2634  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2635  
      */
 2636  
     public static int lastIndexOf(final double[] array, final double valueToFind, final double tolerance) {
 2637  6
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE, tolerance);
 2638  
     }
 2639  
 
 2640  
     /**
 2641  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2642  
      *
 2643  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2644  
      *
 2645  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2646  
      * array length will search from the end of the array.</p>
 2647  
      *
 2648  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2649  
      * @param valueToFind  the value to find
 2650  
      * @param startIndex  the start index to travers backwards from
 2651  
      * @return the last index of the value within the array,
 2652  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2653  
      */
 2654  
     public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex) {
 2655  16
         if (ArrayUtils.isEmpty(array)) {
 2656  4
             return INDEX_NOT_FOUND;
 2657  
         }
 2658  12
         if (startIndex < 0) {
 2659  1
             return INDEX_NOT_FOUND;
 2660  11
         } else if (startIndex >= array.length) {
 2661  7
             startIndex = array.length - 1;
 2662  
         }
 2663  33
         for (int i = startIndex; i >= 0; i--) {
 2664  30
             if (valueToFind == array[i]) {
 2665  8
                 return i;
 2666  
             }
 2667  
         }
 2668  3
         return INDEX_NOT_FOUND;
 2669  
     }
 2670  
 
 2671  
     /**
 2672  
      * <p>Finds the last index of the given value in the array starting at the given index.
 2673  
      * This method will return the index of the last value which falls between the region
 2674  
      * defined by valueToFind - tolerance and valueToFind + tolerance.</p>
 2675  
      *
 2676  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2677  
      *
 2678  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2679  
      * array length will search from the end of the array.</p>
 2680  
      *
 2681  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2682  
      * @param valueToFind  the value to find
 2683  
      * @param startIndex  the start index to travers backwards from
 2684  
      * @param tolerance  search for value within plus/minus this amount
 2685  
      * @return the last index of the value within the array,
 2686  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2687  
      */
 2688  
     public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex, final double tolerance) {
 2689  15
         if (ArrayUtils.isEmpty(array)) {
 2690  4
             return INDEX_NOT_FOUND;
 2691  
         }
 2692  11
         if (startIndex < 0) {
 2693  1
             return INDEX_NOT_FOUND;
 2694  10
         } else if (startIndex >= array.length) {
 2695  7
             startIndex = array.length - 1;
 2696  
         }
 2697  10
         final double min = valueToFind - tolerance;
 2698  10
         final double max = valueToFind + tolerance;
 2699  25
         for (int i = startIndex; i >= 0; i--) {
 2700  24
             if (array[i] >= min && array[i] <= max) {
 2701  9
                 return i;
 2702  
             }
 2703  
         }
 2704  1
         return INDEX_NOT_FOUND;
 2705  
     }
 2706  
 
 2707  
     /**
 2708  
      * <p>Checks if the value is in the given array.</p>
 2709  
      *
 2710  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2711  
      *
 2712  
      * @param array  the array to search through
 2713  
      * @param valueToFind  the value to find
 2714  
      * @return {@code true} if the array contains the object
 2715  
      */
 2716  
     public static boolean contains(final double[] array, final double valueToFind) {
 2717  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2718  
     }
 2719  
 
 2720  
     /**
 2721  
      * <p>Checks if a value falling within the given tolerance is in the
 2722  
      * given array.  If the array contains a value within the inclusive range
 2723  
      * defined by (value - tolerance) to (value + tolerance).</p>
 2724  
      *
 2725  
      * <p>The method returns {@code false} if a {@code null} array
 2726  
      * is passed in.</p>
 2727  
      *
 2728  
      * @param array  the array to search
 2729  
      * @param valueToFind  the value to find
 2730  
      * @param tolerance  the array contains the tolerance of the search
 2731  
      * @return true if value falling within tolerance is in array
 2732  
      */
 2733  
     public static boolean contains(final double[] array, final double valueToFind, final double tolerance) {
 2734  5
         return indexOf(array, valueToFind, 0, tolerance) != INDEX_NOT_FOUND;
 2735  
     }
 2736  
 
 2737  
     // float IndexOf
 2738  
     //-----------------------------------------------------------------------
 2739  
     /**
 2740  
      * <p>Finds the index of the given value in the array.</p>
 2741  
      *
 2742  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2743  
      *
 2744  
      * @param array  the array to search through for the object, may be {@code null}
 2745  
      * @param valueToFind  the value to find
 2746  
      * @return the index of the value within the array,
 2747  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2748  
      */
 2749  
     public static int indexOf(final float[] array, final float valueToFind) {
 2750  18
         return indexOf(array, valueToFind, 0);
 2751  
     }
 2752  
 
 2753  
     /**
 2754  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2755  
      *
 2756  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2757  
      *
 2758  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2759  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2760  
      *
 2761  
      * @param array  the array to search through for the object, may be {@code null}
 2762  
      * @param valueToFind  the value to find
 2763  
      * @param startIndex  the index to start searching at
 2764  
      * @return the index of the value within the array,
 2765  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2766  
      */
 2767  
     public static int indexOf(final float[] array, final float valueToFind, int startIndex) {
 2768  43
         if (ArrayUtils.isEmpty(array)) {
 2769  7
             return INDEX_NOT_FOUND;
 2770  
         }
 2771  36
         if (startIndex < 0) {
 2772  1
             startIndex = 0;
 2773  
         }
 2774  77
         for (int i = startIndex; i < array.length; i++) {
 2775  69
             if (valueToFind == array[i]) {
 2776  28
                 return i;
 2777  
             }
 2778  
         }
 2779  8
         return INDEX_NOT_FOUND;
 2780  
     }
 2781  
 
 2782  
     /**
 2783  
      * <p>Finds the last index of the given value within the array.</p>
 2784  
      *
 2785  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2786  
      *
 2787  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2788  
      * @param valueToFind  the object to find
 2789  
      * @return the last index of the value within the array,
 2790  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2791  
      */
 2792  
     public static int lastIndexOf(final float[] array, final float valueToFind) {
 2793  8
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2794  
     }
 2795  
 
 2796  
     /**
 2797  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2798  
      *
 2799  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2800  
      *
 2801  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than the
 2802  
      * array length will search from the end of the array.</p>
 2803  
      *
 2804  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2805  
      * @param valueToFind  the value to find
 2806  
      * @param startIndex  the start index to travers backwards from
 2807  
      * @return the last index of the value within the array,
 2808  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2809  
      */
 2810  
     public static int lastIndexOf(final float[] array, final float valueToFind, int startIndex) {
 2811  16
         if (ArrayUtils.isEmpty(array)) {
 2812  4
             return INDEX_NOT_FOUND;
 2813  
         }
 2814  12
         if (startIndex < 0) {
 2815  1
             return INDEX_NOT_FOUND;
 2816  11
         } else if (startIndex >= array.length) {
 2817  7
             startIndex = array.length - 1;
 2818  
         }
 2819  33
         for (int i = startIndex; i >= 0; i--) {
 2820  30
             if (valueToFind == array[i]) {
 2821  8
                 return i;
 2822  
             }
 2823  
         }
 2824  3
         return INDEX_NOT_FOUND;
 2825  
     }
 2826  
 
 2827  
     /**
 2828  
      * <p>Checks if the value is in the given array.</p>
 2829  
      *
 2830  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2831  
      *
 2832  
      * @param array  the array to search through
 2833  
      * @param valueToFind  the value to find
 2834  
      * @return {@code true} if the array contains the object
 2835  
      */
 2836  
     public static boolean contains(final float[] array, final float valueToFind) {
 2837  6
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2838  
     }
 2839  
 
 2840  
     // boolean IndexOf
 2841  
     //-----------------------------------------------------------------------
 2842  
     /**
 2843  
      * <p>Finds the index of the given value in the array.</p>
 2844  
      *
 2845  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2846  
      *
 2847  
      * @param array  the array to search through for the object, may be {@code null}
 2848  
      * @param valueToFind  the value to find
 2849  
      * @return the index of the value within the array,
 2850  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2851  
      */
 2852  
     public static int indexOf(final boolean[] array, final boolean valueToFind) {
 2853  15
         return indexOf(array, valueToFind, 0);
 2854  
     }
 2855  
 
 2856  
     /**
 2857  
      * <p>Finds the index of the given value in the array starting at the given index.</p>
 2858  
      *
 2859  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2860  
      *
 2861  
      * <p>A negative startIndex is treated as zero. A startIndex larger than the array
 2862  
      * length will return {@link #INDEX_NOT_FOUND} ({@code -1}).</p>
 2863  
      *
 2864  
      * @param array  the array to search through for the object, may be {@code null}
 2865  
      * @param valueToFind  the value to find
 2866  
      * @param startIndex  the index to start searching at
 2867  
      * @return the index of the value within the array,
 2868  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null}
 2869  
      *  array input
 2870  
      */
 2871  
     public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
 2872  39
         if (ArrayUtils.isEmpty(array)) {
 2873  7
             return INDEX_NOT_FOUND;
 2874  
         }
 2875  32
         if (startIndex < 0) {
 2876  2
             startIndex = 0;
 2877  
         }
 2878  52
         for (int i = startIndex; i < array.length; i++) {
 2879  44
             if (valueToFind == array[i]) {
 2880  24
                 return i;
 2881  
             }
 2882  
         }
 2883  8
         return INDEX_NOT_FOUND;
 2884  
     }
 2885  
 
 2886  
     /**
 2887  
      * <p>Finds the last index of the given value within the array.</p>
 2888  
      *
 2889  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) if
 2890  
      * {@code null} array input.</p>
 2891  
      *
 2892  
      * @param array  the array to travers backwords looking for the object, may be {@code null}
 2893  
      * @param valueToFind  the object to find
 2894  
      * @return the last index of the value within the array,
 2895  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2896  
      */
 2897  
     public static int lastIndexOf(final boolean[] array, final boolean valueToFind) {
 2898  5
         return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
 2899  
     }
 2900  
 
 2901  
     /**
 2902  
      * <p>Finds the last index of the given value in the array starting at the given index.</p>
 2903  
      *
 2904  
      * <p>This method returns {@link #INDEX_NOT_FOUND} ({@code -1}) for a {@code null} input array.</p>
 2905  
      *
 2906  
      * <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} ({@code -1}). A startIndex larger than
 2907  
      * the array length will search from the end of the array.</p>
 2908  
      *
 2909  
      * @param array  the array to traverse for looking for the object, may be {@code null}
 2910  
      * @param valueToFind  the value to find
 2911  
      * @param startIndex  the start index to travers backwards from
 2912  
      * @return the last index of the value within the array,
 2913  
      *  {@link #INDEX_NOT_FOUND} ({@code -1}) if not found or {@code null} array input
 2914  
      */
 2915  
     public static int lastIndexOf(final boolean[] array, final boolean valueToFind, int startIndex) {
 2916  13
         if (ArrayUtils.isEmpty(array)) {
 2917  4
             return INDEX_NOT_FOUND;
 2918  
         }
 2919  9
         if (startIndex < 0) {
 2920  2
             return INDEX_NOT_FOUND;
 2921  7
         } else if (startIndex >= array.length) {
 2922  4
             startIndex = array.length - 1;
 2923  
         }
 2924  14
         for (int i = startIndex; i >= 0; i--) {
 2925  12
             if (valueToFind == array[i]) {
 2926  5
                 return i;
 2927  
             }
 2928  
         }
 2929  2
         return INDEX_NOT_FOUND;
 2930  
     }
 2931  
 
 2932  
     /**
 2933  
      * <p>Checks if the value is in the given array.</p>
 2934  
      *
 2935  
      * <p>The method returns {@code false} if a {@code null} array is passed in.</p>
 2936  
      *
 2937  
      * @param array  the array to search through
 2938  
      * @param valueToFind  the value to find
 2939  
      * @return {@code true} if the array contains the object
 2940  
      */
 2941  
     public static boolean contains(final boolean[] array, final boolean valueToFind) {
 2942  5
         return indexOf(array, valueToFind) != INDEX_NOT_FOUND;
 2943  
     }
 2944  
 
 2945  
     // Primitive/Object array converters
 2946  
     // ----------------------------------------------------------------------
 2947  
 
 2948  
     // Character array converters
 2949  
     // ----------------------------------------------------------------------
 2950  
     /**
 2951  
      * <p>Converts an array of object Characters to primitives.</p>
 2952  
      *
 2953  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 2954  
      *
 2955  
      * @param array  a {@code Character} array, may be {@code null}
 2956  
      * @return a {@code char} array, {@code null} if null array input
 2957  
      * @throws NullPointerException if array content is {@code null}
 2958  
      */
 2959  
     public static char[] toPrimitive(final Character[] array) {
 2960  4
         if (array == null) {
 2961  1
             return null;
 2962  3
         } else if (array.length == 0) {
 2963  1
             return EMPTY_CHAR_ARRAY;
 2964  
         }
 2965  2
         final char[] result = new char[array.length];
 2966  6
         for (int i = 0; i < array.length; i++) {
 2967  5
             result[i] = array[i].charValue();
 2968  
         }
 2969  1
         return result;
 2970  
     }
 2971  
 
 2972  
     /**
 2973  
      * <p>Converts an array of object Character to primitives handling {@code null}.</p>
 2974  
      *
 2975  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 2976  
      *
 2977  
      * @param array  a {@code Character} array, may be {@code null}
 2978  
      * @param valueForNull  the value to insert if {@code null} found
 2979  
      * @return a {@code char} array, {@code null} if null array input
 2980  
      */
 2981  
     public static char[] toPrimitive(final Character[] array, final char valueForNull) {
 2982  4
         if (array == null) {
 2983  1
             return null;
 2984  3
         } else if (array.length == 0) {
 2985  1
             return EMPTY_CHAR_ARRAY;
 2986  
         }
 2987  2
         final char[] result = new char[array.length];
 2988  8
         for (int i = 0; i < array.length; i++) {
 2989  6
             final Character b = array[i];
 2990  6
             result[i] = (b == null ? valueForNull : b.charValue());
 2991  
         }
 2992  2
         return result;
 2993  
     }
 2994  
 
 2995  
     /**
 2996  
      * <p>Converts an array of primitive chars to objects.</p>
 2997  
      *
 2998  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 2999  
      *
 3000  
      * @param array a {@code char} array
 3001  
      * @return a {@code Character} array, {@code null} if null array input
 3002  
      */
 3003  
     public static Character[] toObject(final char[] array) {
 3004  7
         if (array == null) {
 3005  1
             return null;
 3006  6
         } else if (array.length == 0) {
 3007  1
             return EMPTY_CHARACTER_OBJECT_ARRAY;
 3008  
         }
 3009  5
         final Character[] result = new Character[array.length];
 3010  16
         for (int i = 0; i < array.length; i++) {
 3011  11
             result[i] = Character.valueOf(array[i]);
 3012  
         }
 3013  5
         return result;
 3014  
      }
 3015  
 
 3016  
     // Long array converters
 3017  
     // ----------------------------------------------------------------------
 3018  
     /**
 3019  
      * <p>Converts an array of object Longs to primitives.</p>
 3020  
      *
 3021  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3022  
      *
 3023  
      * @param array  a {@code Long} array, may be {@code null}
 3024  
      * @return a {@code long} array, {@code null} if null array input
 3025  
      * @throws NullPointerException if array content is {@code null}
 3026  
      */
 3027  
     public static long[] toPrimitive(final Long[] array) {
 3028  4
         if (array == null) {
 3029  1
             return null;
 3030  3
         } else if (array.length == 0) {
 3031  1
             return EMPTY_LONG_ARRAY;
 3032  
         }
 3033  2
         final long[] result = new long[array.length];
 3034  6
         for (int i = 0; i < array.length; i++) {
 3035  5
             result[i] = array[i].longValue();
 3036  
         }
 3037  1
         return result;
 3038  
     }
 3039  
 
 3040  
     /**
 3041  
      * <p>Converts an array of object Long to primitives handling {@code null}.</p>
 3042  
      *
 3043  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3044  
      *
 3045  
      * @param array  a {@code Long} array, may be {@code null}
 3046  
      * @param valueForNull  the value to insert if {@code null} found
 3047  
      * @return a {@code long} array, {@code null} if null array input
 3048  
      */
 3049  
     public static long[] toPrimitive(final Long[] array, final long valueForNull) {
 3050  5
         if (array == null) {
 3051  2
             return null;
 3052  3
         } else if (array.length == 0) {
 3053  1
             return EMPTY_LONG_ARRAY;
 3054  
         }
 3055  2
         final long[] result = new long[array.length];
 3056  8
         for (int i = 0; i < array.length; i++) {
 3057  6
             final Long b = array[i];
 3058  6
             result[i] = (b == null ? valueForNull : b.longValue());
 3059  
         }
 3060  2
         return result;
 3061  
     }
 3062  
 
 3063  
     /**
 3064  
      * <p>Converts an array of primitive longs to objects.</p>
 3065  
      *
 3066  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3067  
      *
 3068  
      * @param array  a {@code long} array
 3069  
      * @return a {@code Long} array, {@code null} if null array input
 3070  
      */
 3071  
     public static Long[] toObject(final long[] array) {
 3072  7
         if (array == null) {
 3073  1
             return null;
 3074  6
         } else if (array.length == 0) {
 3075  1
             return EMPTY_LONG_OBJECT_ARRAY;
 3076  
         }
 3077  5
         final Long[] result = new Long[array.length];
 3078  16
         for (int i = 0; i < array.length; i++) {
 3079  11
             result[i] = Long.valueOf(array[i]);
 3080  
         }
 3081  5
         return result;
 3082  
     }
 3083  
 
 3084  
     // Int array converters
 3085  
     // ----------------------------------------------------------------------
 3086  
     /**
 3087  
      * <p>Converts an array of object Integers to primitives.</p>
 3088  
      *
 3089  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3090  
      *
 3091  
      * @param array  a {@code Integer} array, may be {@code null}
 3092  
      * @return an {@code int} array, {@code null} if null array input
 3093  
      * @throws NullPointerException if array content is {@code null}
 3094  
      */
 3095  
     public static int[] toPrimitive(final Integer[] array) {
 3096  4
         if (array == null) {
 3097  1
             return null;
 3098  3
         } else if (array.length == 0) {
 3099  1
             return EMPTY_INT_ARRAY;
 3100  
         }
 3101  2
         final int[] result = new int[array.length];
 3102  6
         for (int i = 0; i < array.length; i++) {
 3103  5
             result[i] = array[i].intValue();
 3104  
         }
 3105  1
         return result;
 3106  
     }
 3107  
 
 3108  
     /**
 3109  
      * <p>Converts an array of object Integer to primitives handling {@code null}.</p>
 3110  
      *
 3111  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3112  
      *
 3113  
      * @param array  a {@code Integer} array, may be {@code null}
 3114  
      * @param valueForNull  the value to insert if {@code null} found
 3115  
      * @return an {@code int} array, {@code null} if null array input
 3116  
      */
 3117  
     public static int[] toPrimitive(final Integer[] array, final int valueForNull) {
 3118  4
         if (array == null) {
 3119  1
             return null;
 3120  3
         } else if (array.length == 0) {
 3121  1
             return EMPTY_INT_ARRAY;
 3122  
         }
 3123  2
         final int[] result = new int[array.length];
 3124  8
         for (int i = 0; i < array.length; i++) {
 3125  6
             final Integer b = array[i];
 3126  6
             result[i] = (b == null ? valueForNull : b.intValue());
 3127  
         }
 3128  2
         return result;
 3129  
     }
 3130  
 
 3131  
     /**
 3132  
      * <p>Converts an array of primitive ints to objects.</p>
 3133  
      *
 3134  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3135  
      *
 3136  
      * @param array  an {@code int} array
 3137  
      * @return an {@code Integer} array, {@code null} if null array input
 3138  
      */
 3139  
     public static Integer[] toObject(final int[] array) {
 3140  7
         if (array == null) {
 3141  1
             return null;
 3142  6
         } else if (array.length == 0) {
 3143  1
             return EMPTY_INTEGER_OBJECT_ARRAY;
 3144  
         }
 3145  5
         final Integer[] result = new Integer[array.length];
 3146  16
         for (int i = 0; i < array.length; i++) {
 3147  11
             result[i] = Integer.valueOf(array[i]);
 3148  
         }
 3149  5
         return result;
 3150  
     }
 3151  
 
 3152  
     // Short array converters
 3153  
     // ----------------------------------------------------------------------
 3154  
     /**
 3155  
      * <p>Converts an array of object Shorts to primitives.</p>
 3156  
      *
 3157  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3158  
      *
 3159  
      * @param array  a {@code Short} array, may be {@code null}
 3160  
      * @return a {@code byte} array, {@code null} if null array input
 3161  
      * @throws NullPointerException if array content is {@code null}
 3162  
      */
 3163  
     public static short[] toPrimitive(final Short[] array) {
 3164  4
         if (array == null) {
 3165  1
             return null;
 3166  3
         } else if (array.length == 0) {
 3167  1
             return EMPTY_SHORT_ARRAY;
 3168  
         }
 3169  2
         final short[] result = new short[array.length];
 3170  6
         for (int i = 0; i < array.length; i++) {
 3171  5
             result[i] = array[i].shortValue();
 3172  
         }
 3173  1
         return result;
 3174  
     }
 3175  
 
 3176  
     /**
 3177  
      * <p>Converts an array of object Short to primitives handling {@code null}.</p>
 3178  
      *
 3179  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3180  
      *
 3181  
      * @param array  a {@code Short} array, may be {@code null}
 3182  
      * @param valueForNull  the value to insert if {@code null} found
 3183  
      * @return a {@code byte} array, {@code null} if null array input
 3184  
      */
 3185  
     public static short[] toPrimitive(final Short[] array, final short valueForNull) {
 3186  4
         if (array == null) {
 3187  1
             return null;
 3188  3
         } else if (array.length == 0) {
 3189  1
             return EMPTY_SHORT_ARRAY;
 3190  
         }
 3191  2
         final short[] result = new short[array.length];
 3192  8
         for (int i = 0; i < array.length; i++) {
 3193  6
             final Short b = array[i];
 3194  6
             result[i] = (b == null ? valueForNull : b.shortValue());
 3195  
         }
 3196  2
         return result;
 3197  
     }
 3198  
 
 3199  
     /**
 3200  
      * <p>Converts an array of primitive shorts to objects.</p>
 3201  
      *
 3202  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3203  
      *
 3204  
      * @param array  a {@code short} array
 3205  
      * @return a {@code Short} array, {@code null} if null array input
 3206  
      */
 3207  
     public static Short[] toObject(final short[] array) {
 3208  7
         if (array == null) {
 3209  1
             return null;
 3210  6
         } else if (array.length == 0) {
 3211  1
             return EMPTY_SHORT_OBJECT_ARRAY;
 3212  
         }
 3213  5
         final Short[] result = new Short[array.length];
 3214  16
         for (int i = 0; i < array.length; i++) {
 3215  11
             result[i] = Short.valueOf(array[i]);
 3216  
         }
 3217  5
         return result;
 3218  
     }
 3219  
 
 3220  
     // Byte array converters
 3221  
     // ----------------------------------------------------------------------
 3222  
     /**
 3223  
      * <p>Converts an array of object Bytes to primitives.</p>
 3224  
      *
 3225  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3226  
      *
 3227  
      * @param array  a {@code Byte} array, may be {@code null}
 3228  
      * @return a {@code byte} array, {@code null} if null array input
 3229  
      * @throws NullPointerException if array content is {@code null}
 3230  
      */
 3231  
     public static byte[] toPrimitive(final Byte[] array) {
 3232  4
         if (array == null) {
 3233  1
             return null;
 3234  3
         } else if (array.length == 0) {
 3235  1
             return EMPTY_BYTE_ARRAY;
 3236  
         }
 3237  2
         final byte[] result = new byte[array.length];
 3238  6
         for (int i = 0; i < array.length; i++) {
 3239  5
             result[i] = array[i].byteValue();
 3240  
         }
 3241  1
         return result;
 3242  
     }
 3243  
 
 3244  
     /**
 3245  
      * <p>Converts an array of object Bytes to primitives handling {@code null}.</p>
 3246  
      *
 3247  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3248  
      *
 3249  
      * @param array  a {@code Byte} array, may be {@code null}
 3250  
      * @param valueForNull  the value to insert if {@code null} found
 3251  
      * @return a {@code byte} array, {@code null} if null array input
 3252  
      */
 3253  
     public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) {
 3254  4
         if (array == null) {
 3255  1
             return null;
 3256  3
         } else if (array.length == 0) {
 3257  1
             return EMPTY_BYTE_ARRAY;
 3258  
         }
 3259  2
         final byte[] result = new byte[array.length];
 3260  8
         for (int i = 0; i < array.length; i++) {
 3261  6
             final Byte b = array[i];
 3262  6
             result[i] = (b == null ? valueForNull : b.byteValue());
 3263  
         }
 3264  2
         return result;
 3265  
     }
 3266  
 
 3267  
     /**
 3268  
      * <p>Converts an array of primitive bytes to objects.</p>
 3269  
      *
 3270  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3271  
      *
 3272  
      * @param array  a {@code byte} array
 3273  
      * @return a {@code Byte} array, {@code null} if null array input
 3274  
      */
 3275  
     public static Byte[] toObject(final byte[] array) {
 3276  7
         if (array == null) {
 3277  1
             return null;
 3278  6
         } else if (array.length == 0) {
 3279  1
             return EMPTY_BYTE_OBJECT_ARRAY;
 3280  
         }
 3281  5
         final Byte[] result = new Byte[array.length];
 3282  14
         for (int i = 0; i < array.length; i++) {
 3283  9
             result[i] = Byte.valueOf(array[i]);
 3284  
         }
 3285  5
         return result;
 3286  
     }
 3287  
 
 3288  
     // Double array converters
 3289  
     // ----------------------------------------------------------------------
 3290  
     /**
 3291  
      * <p>Converts an array of object Doubles to primitives.</p>
 3292  
      *
 3293  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3294  
      *
 3295  
      * @param array  a {@code Double} array, may be {@code null}
 3296  
      * @return a {@code double} array, {@code null} if null array input
 3297  
      * @throws NullPointerException if array content is {@code null}
 3298  
      */
 3299  
     public static double[] toPrimitive(final Double[] array) {
 3300  3
         if (array == null) {
 3301  1
             return null;
 3302  2
         } else if (array.length == 0) {
 3303  1
             return EMPTY_DOUBLE_ARRAY;
 3304  
         }
 3305  1
         final double[] result = new double[array.length];
 3306  4
         for (int i = 0; i < array.length; i++) {
 3307  3
             result[i] = array[i].doubleValue();
 3308  
         }
 3309  1
         return result;
 3310  
     }
 3311  
 
 3312  
     /**
 3313  
      * <p>Converts an array of object Doubles to primitives handling {@code null}.</p>
 3314  
      *
 3315  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3316  
      *
 3317  
      * @param array  a {@code Double} array, may be {@code null}
 3318  
      * @param valueForNull  the value to insert if {@code null} found
 3319  
      * @return a {@code double} array, {@code null} if null array input
 3320  
      */
 3321  
     public static double[] toPrimitive(final Double[] array, final double valueForNull) {
 3322  4
         if (array == null) {
 3323  1
             return null;
 3324  3
         } else if (array.length == 0) {
 3325  1
             return EMPTY_DOUBLE_ARRAY;
 3326  
         }
 3327  2
         final double[] result = new double[array.length];
 3328  8
         for (int i = 0; i < array.length; i++) {
 3329  6
             final Double b = array[i];
 3330  6
             result[i] = (b == null ? valueForNull : b.doubleValue());
 3331  
         }
 3332  2
         return result;
 3333  
     }
 3334  
 
 3335  
     /**
 3336  
      * <p>Converts an array of primitive doubles to objects.</p>
 3337  
      *
 3338  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3339  
      *
 3340  
      * @param array  a {@code double} array
 3341  
      * @return a {@code Double} array, {@code null} if null array input
 3342  
      */
 3343  
     public static Double[] toObject(final double[] array) {
 3344  7
         if (array == null) {
 3345  1
             return null;
 3346  6
         } else if (array.length == 0) {
 3347  1
             return EMPTY_DOUBLE_OBJECT_ARRAY;
 3348  
         }
 3349  5
         final Double[] result = new Double[array.length];
 3350  16
         for (int i = 0; i < array.length; i++) {
 3351  11
             result[i] = Double.valueOf(array[i]);
 3352  
         }
 3353  5
         return result;
 3354  
     }
 3355  
 
 3356  
     //   Float array converters
 3357  
     // ----------------------------------------------------------------------
 3358  
     /**
 3359  
      * <p>Converts an array of object Floats to primitives.</p>
 3360  
      *
 3361  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3362  
      *
 3363  
      * @param array  a {@code Float} array, may be {@code null}
 3364  
      * @return a {@code float} array, {@code null} if null array input
 3365  
      * @throws NullPointerException if array content is {@code null}
 3366  
      */
 3367  
     public static float[] toPrimitive(final Float[] array) {
 3368  5
         if (array == null) {
 3369  1
             return null;
 3370  4
         } else if (array.length == 0) {
 3371  1
             return EMPTY_FLOAT_ARRAY;
 3372  
         }
 3373  3
         final float[] result = new float[array.length];
 3374  8
         for (int i = 0; i < array.length; i++) {
 3375  7
             result[i] = array[i].floatValue();
 3376  
         }
 3377  1
         return result;
 3378  
     }
 3379  
 
 3380  
     /**
 3381  
      * <p>Converts an array of object Floats to primitives handling {@code null}.</p>
 3382  
      *
 3383  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3384  
      *
 3385  
      * @param array  a {@code Float} array, may be {@code null}
 3386  
      * @param valueForNull  the value to insert if {@code null} found
 3387  
      * @return a {@code float} array, {@code null} if null array input
 3388  
      */
 3389  
     public static float[] toPrimitive(final Float[] array, final float valueForNull) {
 3390  4
         if (array == null) {
 3391  1
             return null;
 3392  3
         } else if (array.length == 0) {
 3393  1
             return EMPTY_FLOAT_ARRAY;
 3394  
         }
 3395  2
         final float[] result = new float[array.length];
 3396  8
         for (int i = 0; i < array.length; i++) {
 3397  6
             final Float b = array[i];
 3398  6
             result[i] = (b == null ? valueForNull : b.floatValue());
 3399  
         }
 3400  2
         return result;
 3401  
     }
 3402  
 
 3403  
     /**
 3404  
      * <p>Converts an array of primitive floats to objects.</p>
 3405  
      *
 3406  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3407  
      *
 3408  
      * @param array  a {@code float} array
 3409  
      * @return a {@code Float} array, {@code null} if null array input
 3410  
      */
 3411  
     public static Float[] toObject(final float[] array) {
 3412  7
         if (array == null) {
 3413  1
             return null;
 3414  6
         } else if (array.length == 0) {
 3415  1
             return EMPTY_FLOAT_OBJECT_ARRAY;
 3416  
         }
 3417  5
         final Float[] result = new Float[array.length];
 3418  16
         for (int i = 0; i < array.length; i++) {
 3419  11
             result[i] = Float.valueOf(array[i]);
 3420  
         }
 3421  5
         return result;
 3422  
     }
 3423  
 
 3424  
     // Boolean array converters
 3425  
     // ----------------------------------------------------------------------
 3426  
     /**
 3427  
      * <p>Converts an array of object Booleans to primitives.</p>
 3428  
      *
 3429  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3430  
      *
 3431  
      * @param array  a {@code Boolean} array, may be {@code null}
 3432  
      * @return a {@code boolean} array, {@code null} if null array input
 3433  
      * @throws NullPointerException if array content is {@code null}
 3434  
      */
 3435  
     public static boolean[] toPrimitive(final Boolean[] array) {
 3436  43
         if (array == null) {
 3437  1
             return null;
 3438  42
         } else if (array.length == 0) {
 3439  1
             return EMPTY_BOOLEAN_ARRAY;
 3440  
         }
 3441  41
         final boolean[] result = new boolean[array.length];
 3442  141
         for (int i = 0; i < array.length; i++) {
 3443  104
             result[i] = array[i].booleanValue();
 3444  
         }
 3445  37
         return result;
 3446  
     }
 3447  
 
 3448  
     /**
 3449  
      * <p>Converts an array of object Booleans to primitives handling {@code null}.</p>
 3450  
      *
 3451  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3452  
      *
 3453  
      * @param array  a {@code Boolean} array, may be {@code null}
 3454  
      * @param valueForNull  the value to insert if {@code null} found
 3455  
      * @return a {@code boolean} array, {@code null} if null array input
 3456  
      */
 3457  
     public static boolean[] toPrimitive(final Boolean[] array, final boolean valueForNull) {
 3458  5
         if (array == null) {
 3459  1
             return null;
 3460  4
         } else if (array.length == 0) {
 3461  1
             return EMPTY_BOOLEAN_ARRAY;
 3462  
         }
 3463  3
         final boolean[] result = new boolean[array.length];
 3464  12
         for (int i = 0; i < array.length; i++) {
 3465  9
             final Boolean b = array[i];
 3466  9
             result[i] = (b == null ? valueForNull : b.booleanValue());
 3467  
         }
 3468  3
         return result;
 3469  
     }
 3470  
 
 3471  
     /**
 3472  
      * <p>Converts an array of primitive booleans to objects.</p>
 3473  
      *
 3474  
      * <p>This method returns {@code null} for a {@code null} input array.</p>
 3475  
      *
 3476  
      * @param array  a {@code boolean} array
 3477  
      * @return a {@code Boolean} array, {@code null} if null array input
 3478  
      */
 3479  
     public static Boolean[] toObject(final boolean[] array) {
 3480  7
         if (array == null) {
 3481  1
             return null;
 3482  6
         } else if (array.length == 0) {
 3483  1
             return EMPTY_BOOLEAN_OBJECT_ARRAY;
 3484  
         }
 3485  5
         final Boolean[] result = new Boolean[array.length];
 3486  14
         for (int i = 0; i < array.length; i++) {
 3487  9
             result[i] = (array[i] ? Boolean.TRUE : Boolean.FALSE);
 3488  
         }
 3489  5
         return result;
 3490  
     }
 3491  
 
 3492  
     // ----------------------------------------------------------------------
 3493  
     /**
 3494  
      * <p>Checks if an array of Objects is empty or {@code null}.</p>
 3495  
      *
 3496  
      * @param array  the array to test
 3497  
      * @return {@code true} if the array is empty or {@code null}
 3498  
      * @since 2.1
 3499  
      */
 3500  
     public static boolean isEmpty(final Object[] array) {
 3501  316
         return array == null || array.length == 0;
 3502  
     }
 3503  
 
 3504  
     /**
 3505  
      * <p>Checks if an array of primitive longs is empty or {@code null}.</p>
 3506  
      *
 3507  
      * @param array  the array to test
 3508  
      * @return {@code true} if the array is empty or {@code null}
 3509  
      * @since 2.1
 3510  
      */
 3511  
     public static boolean isEmpty(final long[] array) {
 3512  28
         return array == null || array.length == 0;
 3513  
     }
 3514  
 
 3515  
     /**
 3516  
      * <p>Checks if an array of primitive ints is empty or {@code null}.</p>
 3517  
      *
 3518  
      * @param array  the array to test
 3519  
      * @return {@code true} if the array is empty or {@code null}
 3520  
      * @since 2.1
 3521  
      */
 3522  
     public static boolean isEmpty(final int[] array) {
 3523  28
         return array == null || array.length == 0;
 3524  
     }
 3525  
 
 3526  
     /**
 3527  
      * <p>Checks if an array of primitive shorts is empty or {@code null}.</p>
 3528  
      *
 3529  
      * @param array  the array to test
 3530  
      * @return {@code true} if the array is empty or {@code null}
 3531  
      * @since 2.1
 3532  
      */
 3533  
     public static boolean isEmpty(final short[] array) {
 3534  28
         return array == null || array.length == 0;
 3535  
     }
 3536  
 
 3537  
     /**
 3538  
      * <p>Checks if an array of primitive chars is empty or {@code null}.</p>
 3539  
      *
 3540  
      * @param array  the array to test
 3541  
      * @return {@code true} if the array is empty or {@code null}
 3542  
      * @since 2.1
 3543  
      */
 3544  
     public static boolean isEmpty(final char[] array) {
 3545  116
         return array == null || array.length == 0;
 3546  
     }
 3547  
 
 3548  
     /**
 3549  
      * <p>Checks if an array of primitive bytes is empty or {@code null}.</p>
 3550  
      *
 3551  
      * @param array  the array to test
 3552  
      * @return {@code true} if the array is empty or {@code null}
 3553  
      * @since 2.1
 3554  
      */
 3555  
     public static boolean isEmpty(final byte[] array) {
 3556  28
         return array == null || array.length == 0;
 3557  
     }
 3558  
 
 3559  
     /**
 3560  
      * <p>Checks if an array of primitive doubles is empty or {@code null}.</p>
 3561  
      *
 3562  
      * @param array  the array to test
 3563  
      * @return {@code true} if the array is empty or {@code null}
 3564  
      * @since 2.1
 3565  
      */
 3566  
     public static boolean isEmpty(final double[] array) {
 3567  123
         return array == null || array.length == 0;
 3568  
     }
 3569  
 
 3570  
     /**
 3571  
      * <p>Checks if an array of primitive floats is empty or {@code null}.</p>
 3572  
      *
 3573  
      * @param array  the array to test
 3574  
      * @return {@code true} if the array is empty or {@code null}
 3575  
      * @since 2.1
 3576  
      */
 3577  
     public static boolean isEmpty(final float[] array) {
 3578  87
         return array == null || array.length == 0;
 3579  
     }
 3580  
 
 3581  
     /**
 3582  
      * <p>Checks if an array of primitive booleans is empty or {@code null}.</p>
 3583  
      *
 3584  
      * @param array  the array to test
 3585  
      * @return {@code true} if the array is empty or {@code null}
 3586  
      * @since 2.1
 3587  
      */
 3588  
     public static boolean isEmpty(final boolean[] array) {
 3589  80
         return array == null || array.length == 0;
 3590  
     }
 3591  
 
 3592  
     // ----------------------------------------------------------------------
 3593  
     /**
 3594  
      * <p>Checks if an array of Objects is not empty or not {@code null}.</p>
 3595  
      *
 3596  
      * @param <T> the component type of the array
 3597  
      * @param array  the array to test
 3598  
      * @return {@code true} if the array is not empty or not {@code null}
 3599  
      * @since 2.5
 3600  
      */
 3601  
      public static <T> boolean isNotEmpty(final T[] array) {
 3602  9
          return (array != null && array.length != 0);
 3603  
      }
 3604  
 
 3605  
     /**
 3606  
      * <p>Checks if an array of primitive longs is not empty or not {@code null}.</p>
 3607  
      *
 3608  
      * @param array  the array to test
 3609  
      * @return {@code true} if the array is not empty or not {@code null}
 3610  
      * @since 2.5
 3611  
      */
 3612  
     public static boolean isNotEmpty(final long[] array) {
 3613  3
         return (array != null && array.length != 0);
 3614  
     }
 3615  
 
 3616  
     /**
 3617  
      * <p>Checks if an array of primitive ints is not empty or not {@code null}.</p>
 3618  
      *
 3619  
      * @param array  the array to test
 3620  
      * @return {@code true} if the array is not empty or not {@code null}
 3621  
      * @since 2.5
 3622  
      */
 3623  
     public static boolean isNotEmpty(final int[] array) {
 3624  90155
         return (array != null && array.length != 0);
 3625  
     }
 3626  
 
 3627  
     /**
 3628  
      * <p>Checks if an array of primitive shorts is not empty or not {@code null}.</p>
 3629  
      *
 3630  
      * @param array  the array to test
 3631  
      * @return {@code true} if the array is not empty or not {@code null}
 3632  
      * @since 2.5
 3633  
      */
 3634  
     public static boolean isNotEmpty(final short[] array) {
 3635  3
         return (array != null && array.length != 0);
 3636  
     }
 3637  
 
 3638  
     /**
 3639  
      * <p>Checks if an array of primitive chars is not empty or not {@code null}.</p>
 3640  
      *
 3641  
      * @param array  the array to test
 3642  
      * @return {@code true} if the array is not empty or not {@code null}
 3643  
      * @since 2.5
 3644  
      */
 3645  
     public static boolean isNotEmpty(final char[] array) {
 3646  3
         return (array != null && array.length != 0);
 3647  
     }
 3648  
 
 3649  
     /**
 3650  
      * <p>Checks if an array of primitive bytes is not empty or not {@code null}.</p>
 3651  
      *
 3652  
      * @param array  the array to test
 3653  
      * @return {@code true} if the array is not empty or not {@code null}
 3654  
      * @since 2.5
 3655  
      */
 3656  
     public static boolean isNotEmpty(final byte[] array) {
 3657  3
         return (array != null && array.length != 0);
 3658  
     }
 3659  
 
 3660  
     /**
 3661  
      * <p>Checks if an array of primitive doubles is not empty or not {@code null}.</p>
 3662  
      *
 3663  
      * @param array  the array to test
 3664  
      * @return {@code true} if the array is not empty or not {@code null}
 3665  
      * @since 2.5
 3666  
      */
 3667  
     public static boolean isNotEmpty(final double[] array) {
 3668  3
         return (array != null && array.length != 0);
 3669  
     }
 3670  
 
 3671  
     /**
 3672  
      * <p>Checks if an array of primitive floats is not empty or not {@code null}.</p>
 3673  
      *
 3674  
      * @param array  the array to test
 3675  
      * @return {@code true} if the array is not empty or not {@code null}
 3676  
      * @since 2.5
 3677  
      */
 3678  
     public static boolean isNotEmpty(final float[] array) {
 3679  3
         return (array != null && array.length != 0);
 3680  
     }
 3681  
 
 3682  
     /**
 3683  
      * <p>Checks if an array of primitive booleans is not empty or not {@code null}.</p>
 3684  
      *
 3685  
      * @param array  the array to test
 3686  
      * @return {@code true} if the array is not empty or not {@code null}
 3687  
      * @since 2.5
 3688  
      */
 3689  
     public static boolean isNotEmpty(final boolean[] array) {
 3690  3
         return (array != null && array.length != 0);
 3691  
     }
 3692  
 
 3693  
     /**
 3694  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3695  
      * <p>The new array contains all of the element of {@code array1} followed
 3696  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3697  
      * a new array.</p>
 3698  
      *
 3699  
      * <pre>
 3700  
      * ArrayUtils.addAll(null, null)     = null
 3701  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3702  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3703  
      * ArrayUtils.addAll([], [])         = []
 3704  
      * ArrayUtils.addAll([null], [null]) = [null, null]
 3705  
      * ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
 3706  
      * </pre>
 3707  
      *
 3708  
      * @param <T> the component type of the array
 3709  
      * @param array1  the first array whose elements are added to the new array, may be {@code null}
 3710  
      * @param array2  the second array whose elements are added to the new array, may be {@code null}
 3711  
      * @return The new array, {@code null} if both arrays are {@code null}.
 3712  
      *      The type of the new array is the type of the first array,
 3713  
      *      unless the first array is null, in which case the type is the same as the second array.
 3714  
      * @since 2.1
 3715  
      * @throws IllegalArgumentException if the array types are incompatible
 3716  
      */
 3717  
     public static <T> T[] addAll(final T[] array1, final T... array2) {
 3718  13
         if (array1 == null) {
 3719  3
             return clone(array2);
 3720  10
         } else if (array2 == null) {
 3721  2
             return clone(array1);
 3722  
         }
 3723  8
         final Class<?> type1 = array1.getClass().getComponentType();
 3724  
         @SuppressWarnings("unchecked") // OK, because array is of type T
 3725  
         final
 3726  8
         T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
 3727  8
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3728  
         try {
 3729  8
             System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3730  1
         } catch (final ArrayStoreException ase) {
 3731  
             // Check if problem was due to incompatible types
 3732  
             /*
 3733  
              * We do this here, rather than before the copy because:
 3734  
              * - it would be a wasted check most of the time
 3735  
              * - safer, in case check turns out to be too strict
 3736  
              */
 3737  1
             final Class<?> type2 = array2.getClass().getComponentType();
 3738  1
             if (!type1.isAssignableFrom(type2)){
 3739  1
                 throw new IllegalArgumentException("Cannot store "+type2.getName()+" in an array of "
 3740  
                         +type1.getName(), ase);
 3741  
             }
 3742  0
             throw ase; // No, so rethrow original
 3743  7
         }
 3744  7
         return joinedArray;
 3745  
     }
 3746  
 
 3747  
     /**
 3748  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3749  
      * <p>The new array contains all of the element of {@code array1} followed
 3750  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3751  
      * a new array.</p>
 3752  
      *
 3753  
      * <pre>
 3754  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3755  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3756  
      * ArrayUtils.addAll([], [])         = []
 3757  
      * </pre>
 3758  
      *
 3759  
      * @param array1  the first array whose elements are added to the new array.
 3760  
      * @param array2  the second array whose elements are added to the new array.
 3761  
      * @return The new boolean[] array.
 3762  
      * @since 2.1
 3763  
      */
 3764  
     public static boolean[] addAll(final boolean[] array1, final boolean... array2) {
 3765  3
         if (array1 == null) {
 3766  1
             return clone(array2);
 3767  2
         } else if (array2 == null) {
 3768  1
             return clone(array1);
 3769  
         }
 3770  1
         final boolean[] joinedArray = new boolean[array1.length + array2.length];
 3771  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3772  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3773  1
         return joinedArray;
 3774  
     }
 3775  
 
 3776  
     /**
 3777  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3778  
      * <p>The new array contains all of the element of {@code array1} followed
 3779  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3780  
      * a new array.</p>
 3781  
      *
 3782  
      * <pre>
 3783  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3784  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3785  
      * ArrayUtils.addAll([], [])         = []
 3786  
      * </pre>
 3787  
      *
 3788  
      * @param array1  the first array whose elements are added to the new array.
 3789  
      * @param array2  the second array whose elements are added to the new array.
 3790  
      * @return The new char[] array.
 3791  
      * @since 2.1
 3792  
      */
 3793  
     public static char[] addAll(final char[] array1, final char... array2) {
 3794  3
         if (array1 == null) {
 3795  1
             return clone(array2);
 3796  2
         } else if (array2 == null) {
 3797  1
             return clone(array1);
 3798  
         }
 3799  1
         final char[] joinedArray = new char[array1.length + array2.length];
 3800  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3801  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3802  1
         return joinedArray;
 3803  
     }
 3804  
 
 3805  
     /**
 3806  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3807  
      * <p>The new array contains all of the element of {@code array1} followed
 3808  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3809  
      * a new array.</p>
 3810  
      *
 3811  
      * <pre>
 3812  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3813  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3814  
      * ArrayUtils.addAll([], [])         = []
 3815  
      * </pre>
 3816  
      *
 3817  
      * @param array1  the first array whose elements are added to the new array.
 3818  
      * @param array2  the second array whose elements are added to the new array.
 3819  
      * @return The new byte[] array.
 3820  
      * @since 2.1
 3821  
      */
 3822  
     public static byte[] addAll(final byte[] array1, final byte... array2) {
 3823  3
         if (array1 == null) {
 3824  1
             return clone(array2);
 3825  2
         } else if (array2 == null) {
 3826  1
             return clone(array1);
 3827  
         }
 3828  1
         final byte[] joinedArray = new byte[array1.length + array2.length];
 3829  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3830  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3831  1
         return joinedArray;
 3832  
     }
 3833  
 
 3834  
     /**
 3835  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3836  
      * <p>The new array contains all of the element of {@code array1} followed
 3837  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3838  
      * a new array.</p>
 3839  
      *
 3840  
      * <pre>
 3841  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3842  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3843  
      * ArrayUtils.addAll([], [])         = []
 3844  
      * </pre>
 3845  
      *
 3846  
      * @param array1  the first array whose elements are added to the new array.
 3847  
      * @param array2  the second array whose elements are added to the new array.
 3848  
      * @return The new short[] array.
 3849  
      * @since 2.1
 3850  
      */
 3851  
     public static short[] addAll(final short[] array1, final short... array2) {
 3852  3
         if (array1 == null) {
 3853  1
             return clone(array2);
 3854  2
         } else if (array2 == null) {
 3855  1
             return clone(array1);
 3856  
         }
 3857  1
         final short[] joinedArray = new short[array1.length + array2.length];
 3858  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3859  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3860  1
         return joinedArray;
 3861  
     }
 3862  
 
 3863  
     /**
 3864  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3865  
      * <p>The new array contains all of the element of {@code array1} followed
 3866  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3867  
      * a new array.</p>
 3868  
      *
 3869  
      * <pre>
 3870  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3871  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3872  
      * ArrayUtils.addAll([], [])         = []
 3873  
      * </pre>
 3874  
      *
 3875  
      * @param array1  the first array whose elements are added to the new array.
 3876  
      * @param array2  the second array whose elements are added to the new array.
 3877  
      * @return The new int[] array.
 3878  
      * @since 2.1
 3879  
      */
 3880  
     public static int[] addAll(final int[] array1, final int... array2) {
 3881  3
         if (array1 == null) {
 3882  1
             return clone(array2);
 3883  2
         } else if (array2 == null) {
 3884  1
             return clone(array1);
 3885  
         }
 3886  1
         final int[] joinedArray = new int[array1.length + array2.length];
 3887  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3888  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3889  1
         return joinedArray;
 3890  
     }
 3891  
 
 3892  
     /**
 3893  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3894  
      * <p>The new array contains all of the element of {@code array1} followed
 3895  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3896  
      * a new array.</p>
 3897  
      *
 3898  
      * <pre>
 3899  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3900  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3901  
      * ArrayUtils.addAll([], [])         = []
 3902  
      * </pre>
 3903  
      *
 3904  
      * @param array1  the first array whose elements are added to the new array.
 3905  
      * @param array2  the second array whose elements are added to the new array.
 3906  
      * @return The new long[] array.
 3907  
      * @since 2.1
 3908  
      */
 3909  
     public static long[] addAll(final long[] array1, final long... array2) {
 3910  3
         if (array1 == null) {
 3911  1
             return clone(array2);
 3912  2
         } else if (array2 == null) {
 3913  1
             return clone(array1);
 3914  
         }
 3915  1
         final long[] joinedArray = new long[array1.length + array2.length];
 3916  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3917  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3918  1
         return joinedArray;
 3919  
     }
 3920  
 
 3921  
     /**
 3922  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3923  
      * <p>The new array contains all of the element of {@code array1} followed
 3924  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3925  
      * a new array.</p>
 3926  
      *
 3927  
      * <pre>
 3928  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3929  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3930  
      * ArrayUtils.addAll([], [])         = []
 3931  
      * </pre>
 3932  
      *
 3933  
      * @param array1  the first array whose elements are added to the new array.
 3934  
      * @param array2  the second array whose elements are added to the new array.
 3935  
      * @return The new float[] array.
 3936  
      * @since 2.1
 3937  
      */
 3938  
     public static float[] addAll(final float[] array1, final float... array2) {
 3939  3
         if (array1 == null) {
 3940  1
             return clone(array2);
 3941  2
         } else if (array2 == null) {
 3942  1
             return clone(array1);
 3943  
         }
 3944  1
         final float[] joinedArray = new float[array1.length + array2.length];
 3945  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3946  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3947  1
         return joinedArray;
 3948  
     }
 3949  
 
 3950  
     /**
 3951  
      * <p>Adds all the elements of the given arrays into a new array.</p>
 3952  
      * <p>The new array contains all of the element of {@code array1} followed
 3953  
      * by all of the elements {@code array2}. When an array is returned, it is always
 3954  
      * a new array.</p>
 3955  
      *
 3956  
      * <pre>
 3957  
      * ArrayUtils.addAll(array1, null)   = cloned copy of array1
 3958  
      * ArrayUtils.addAll(null, array2)   = cloned copy of array2
 3959  
      * ArrayUtils.addAll([], [])         = []
 3960  
      * </pre>
 3961  
      *
 3962  
      * @param array1  the first array whose elements are added to the new array.
 3963  
      * @param array2  the second array whose elements are added to the new array.
 3964  
      * @return The new double[] array.
 3965  
      * @since 2.1
 3966  
      */
 3967  
     public static double[] addAll(final double[] array1, final double... array2) {
 3968  3
         if (array1 == null) {
 3969  1
             return clone(array2);
 3970  2
         } else if (array2 == null) {
 3971  1
             return clone(array1);
 3972  
         }
 3973  1
         final double[] joinedArray = new double[array1.length + array2.length];
 3974  1
         System.arraycopy(array1, 0, joinedArray, 0, array1.length);
 3975  1
         System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
 3976  1
         return joinedArray;
 3977  
     }
 3978  
 
 3979  
     /**
 3980  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 3981  
      *
 3982  
      * <p>The new array contains the same elements of the input
 3983  
      * array plus the given element in the last position. The component type of
 3984  
      * the new array is the same as that of the input array.</p>
 3985  
      *
 3986  
      * <p>If the input array is {@code null}, a new one element array is returned
 3987  
      *  whose component type is the same as the element, unless the element itself is null,
 3988  
      *  in which case the return type is Object[]</p>
 3989  
      *
 3990  
      * <pre>
 3991  
      * ArrayUtils.add(null, null)      = [null]
 3992  
      * ArrayUtils.add(null, "a")       = ["a"]
 3993  
      * ArrayUtils.add(["a"], null)     = ["a", null]
 3994  
      * ArrayUtils.add(["a"], "b")      = ["a", "b"]
 3995  
      * ArrayUtils.add(["a", "b"], "c") = ["a", "b", "c"]
 3996  
      * </pre>
 3997  
      *
 3998  
      * @param <T> the component type of the array
 3999  
      * @param array  the array to "add" the element to, may be {@code null}
 4000  
      * @param element  the object to add, may be {@code null}
 4001  
      * @return A new array containing the existing elements plus the new element
 4002  
      * The returned array type will be that of the input array (unless null),
 4003  
      * in which case it will have the same type as the element.
 4004  
      * If both are null, an IllegalArgumentException is thrown
 4005  
      * @since 2.1
 4006  
      * @throws IllegalArgumentException if both arguments are null
 4007  
      */
 4008  
     public static <T> T[] add(final T[] array, final T element) {
 4009  
         Class<?> type;
 4010  11
         if (array != null){
 4011  7
             type = array.getClass().getComponentType();
 4012  4
         } else if (element != null) {
 4013  3
             type = element.getClass();
 4014  
         } else {
 4015  1
             throw new IllegalArgumentException("Arguments cannot both be null");
 4016  
         }
 4017  
         @SuppressWarnings("unchecked") // type must be T
 4018  
         final
 4019  10
         T[] newArray = (T[]) copyArrayGrow1(array, type);
 4020  10
         newArray[newArray.length - 1] = element;
 4021  10
         return newArray;
 4022  
     }
 4023  
 
 4024  
     /**
 4025  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4026  
      *
 4027  
      * <p>The new array contains the same elements of the input
 4028  
      * array plus the given element in the last position. The component type of
 4029  
      * the new array is the same as that of the input array.</p>
 4030  
      *
 4031  
      * <p>If the input array is {@code null}, a new one element array is returned
 4032  
      *  whose component type is the same as the element.</p>
 4033  
      *
 4034  
      * <pre>
 4035  
      * ArrayUtils.add(null, true)          = [true]
 4036  
      * ArrayUtils.add([true], false)       = [true, false]
 4037  
      * ArrayUtils.add([true, false], true) = [true, false, true]
 4038  
      * </pre>
 4039  
      *
 4040  
      * @param array  the array to copy and add the element to, may be {@code null}
 4041  
      * @param element  the object to add at the last index of the new array
 4042  
      * @return A new array containing the existing elements plus the new element
 4043  
      * @since 2.1
 4044  
      */
 4045  
     public static boolean[] add(final boolean[] array, final boolean element) {
 4046  3
         final boolean[] newArray = (boolean[])copyArrayGrow1(array, Boolean.TYPE);
 4047  3
         newArray[newArray.length - 1] = element;
 4048  3
         return newArray;
 4049  
     }
 4050  
 
 4051  
     /**
 4052  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4053  
      *
 4054  
      * <p>The new array contains the same elements of the input
 4055  
      * array plus the given element in the last position. The component type of
 4056  
      * the new array is the same as that of the input array.</p>
 4057  
      *
 4058  
      * <p>If the input array is {@code null}, a new one element array is returned
 4059  
      *  whose component type is the same as the element.</p>
 4060  
      *
 4061  
      * <pre>
 4062  
      * ArrayUtils.add(null, 0)   = [0]
 4063  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4064  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4065  
      * </pre>
 4066  
      *
 4067  
      * @param array  the array to copy and add the element to, may be {@code null}
 4068  
      * @param element  the object to add at the last index of the new array
 4069  
      * @return A new array containing the existing elements plus the new element
 4070  
      * @since 2.1
 4071  
      */
 4072  
     public static byte[] add(final byte[] array, final byte element) {
 4073  4
         final byte[] newArray = (byte[])copyArrayGrow1(array, Byte.TYPE);
 4074  4
         newArray[newArray.length - 1] = element;
 4075  4
         return newArray;
 4076  
     }
 4077  
 
 4078  
     /**
 4079  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4080  
      *
 4081  
      * <p>The new array contains the same elements of the input
 4082  
      * array plus the given element in the last position. The component type of
 4083  
      * the new array is the same as that of the input array.</p>
 4084  
      *
 4085  
      * <p>If the input array is {@code null}, a new one element array is returned
 4086  
      *  whose component type is the same as the element.</p>
 4087  
      *
 4088  
      * <pre>
 4089  
      * ArrayUtils.add(null, '0')       = ['0']
 4090  
      * ArrayUtils.add(['1'], '0')      = ['1', '0']
 4091  
      * ArrayUtils.add(['1', '0'], '1') = ['1', '0', '1']
 4092  
      * </pre>
 4093  
      *
 4094  
      * @param array  the array to copy and add the element to, may be {@code null}
 4095  
      * @param element  the object to add at the last index of the new array
 4096  
      * @return A new array containing the existing elements plus the new element
 4097  
      * @since 2.1
 4098  
      */
 4099  
     public static char[] add(final char[] array, final char element) {
 4100  4
         final char[] newArray = (char[])copyArrayGrow1(array, Character.TYPE);
 4101  4
         newArray[newArray.length - 1] = element;
 4102  4
         return newArray;
 4103  
     }
 4104  
 
 4105  
     /**
 4106  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4107  
      *
 4108  
      * <p>The new array contains the same elements of the input
 4109  
      * array plus the given element in the last position. The component type of
 4110  
      * the new array is the same as that of the input array.</p>
 4111  
      *
 4112  
      * <p>If the input array is {@code null}, a new one element array is returned
 4113  
      *  whose component type is the same as the element.</p>
 4114  
      *
 4115  
      * <pre>
 4116  
      * ArrayUtils.add(null, 0)   = [0]
 4117  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4118  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4119  
      * </pre>
 4120  
      *
 4121  
      * @param array  the array to copy and add the element to, may be {@code null}
 4122  
      * @param element  the object to add at the last index of the new array
 4123  
      * @return A new array containing the existing elements plus the new element
 4124  
      * @since 2.1
 4125  
      */
 4126  
     public static double[] add(final double[] array, final double element) {
 4127  4
         final double[] newArray = (double[])copyArrayGrow1(array, Double.TYPE);
 4128  4
         newArray[newArray.length - 1] = element;
 4129  4
         return newArray;
 4130  
     }
 4131  
 
 4132  
     /**
 4133  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4134  
      *
 4135  
      * <p>The new array contains the same elements of the input
 4136  
      * array plus the given element in the last position. The component type of
 4137  
      * the new array is the same as that of the input array.</p>
 4138  
      *
 4139  
      * <p>If the input array is {@code null}, a new one element array is returned
 4140  
      *  whose component type is the same as the element.</p>
 4141  
      *
 4142  
      * <pre>
 4143  
      * ArrayUtils.add(null, 0)   = [0]
 4144  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4145  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4146  
      * </pre>
 4147  
      *
 4148  
      * @param array  the array to copy and add the element to, may be {@code null}
 4149  
      * @param element  the object to add at the last index of the new array
 4150  
      * @return A new array containing the existing elements plus the new element
 4151  
      * @since 2.1
 4152  
      */
 4153  
     public static float[] add(final float[] array, final float element) {
 4154  4
         final float[] newArray = (float[])copyArrayGrow1(array, Float.TYPE);
 4155  4
         newArray[newArray.length - 1] = element;
 4156  4
         return newArray;
 4157  
     }
 4158  
 
 4159  
     /**
 4160  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4161  
      *
 4162  
      * <p>The new array contains the same elements of the input
 4163  
      * array plus the given element in the last position. The component type of
 4164  
      * the new array is the same as that of the input array.</p>
 4165  
      *
 4166  
      * <p>If the input array is {@code null}, a new one element array is returned
 4167  
      *  whose component type is the same as the element.</p>
 4168  
      *
 4169  
      * <pre>
 4170  
      * ArrayUtils.add(null, 0)   = [0]
 4171  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4172  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4173  
      * </pre>
 4174  
      *
 4175  
      * @param array  the array to copy and add the element to, may be {@code null}
 4176  
      * @param element  the object to add at the last index of the new array
 4177  
      * @return A new array containing the existing elements plus the new element
 4178  
      * @since 2.1
 4179  
      */
 4180  
     public static int[] add(final int[] array, final int element) {
 4181  4
         final int[] newArray = (int[])copyArrayGrow1(array, Integer.TYPE);
 4182  4
         newArray[newArray.length - 1] = element;
 4183  4
         return newArray;
 4184  
     }
 4185  
 
 4186  
     /**
 4187  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4188  
      *
 4189  
      * <p>The new array contains the same elements of the input
 4190  
      * array plus the given element in the last position. The component type of
 4191  
      * the new array is the same as that of the input array.</p>
 4192  
      *
 4193  
      * <p>If the input array is {@code null}, a new one element array is returned
 4194  
      *  whose component type is the same as the element.</p>
 4195  
      *
 4196  
      * <pre>
 4197  
      * ArrayUtils.add(null, 0)   = [0]
 4198  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4199  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4200  
      * </pre>
 4201  
      *
 4202  
      * @param array  the array to copy and add the element to, may be {@code null}
 4203  
      * @param element  the object to add at the last index of the new array
 4204  
      * @return A new array containing the existing elements plus the new element
 4205  
      * @since 2.1
 4206  
      */
 4207  
     public static long[] add(final long[] array, final long element) {
 4208  4
         final long[] newArray = (long[])copyArrayGrow1(array, Long.TYPE);
 4209  4
         newArray[newArray.length - 1] = element;
 4210  4
         return newArray;
 4211  
     }
 4212  
 
 4213  
     /**
 4214  
      * <p>Copies the given array and adds the given element at the end of the new array.</p>
 4215  
      *
 4216  
      * <p>The new array contains the same elements of the input
 4217  
      * array plus the given element in the last position. The component type of
 4218  
      * the new array is the same as that of the input array.</p>
 4219  
      *
 4220  
      * <p>If the input array is {@code null}, a new one element array is returned
 4221  
      *  whose component type is the same as the element.</p>
 4222  
      *
 4223  
      * <pre>
 4224  
      * ArrayUtils.add(null, 0)   = [0]
 4225  
      * ArrayUtils.add([1], 0)    = [1, 0]
 4226  
      * ArrayUtils.add([1, 0], 1) = [1, 0, 1]
 4227  
      * </pre>
 4228  
      *
 4229  
      * @param array  the array to copy and add the element to, may be {@code null}
 4230  
      * @param element  the object to add at the last index of the new array
 4231  
      * @return A new array containing the existing elements plus the new element
 4232  
      * @since 2.1
 4233  
      */
 4234  
     public static short[] add(final short[] array, final short element) {
 4235  4
         final short[] newArray = (short[])copyArrayGrow1(array, Short.TYPE);
 4236  4
         newArray[newArray.length - 1] = element;
 4237  4
         return newArray;
 4238  
     }
 4239  
 
 4240  
     /**
 4241  
      * Returns a copy of the given array of size 1 greater than the argument.
 4242  
      * The last value of the array is left to the default value.
 4243  
      *
 4244  
      * @param array The array to copy, must not be {@code null}.
 4245  
      * @param newArrayComponentType If {@code array} is {@code null}, create a
 4246  
      * size 1 array of this type.
 4247  
      * @return A new copy of the array of size 1 greater than the input.
 4248  
      */
 4249  
     private static Object copyArrayGrow1(final Object array, final Class<?> newArrayComponentType) {
 4250  41
         if (array != null) {
 4251  22
             final int arrayLength = Array.getLength(array);
 4252  22
             final Object newArray = Array.newInstance(array.getClass().getComponentType(), arrayLength + 1);
 4253  22
             System.arraycopy(array, 0, newArray, 0, arrayLength);
 4254  22
             return newArray;
 4255  
         }
 4256  19
         return Array.newInstance(newArrayComponentType, 1);
 4257  
     }
 4258  
 
 4259  
     /**
 4260  
      * <p>Inserts the specified element at the specified position in the array.
 4261  
      * Shifts the element currently at that position (if any) and any subsequent
 4262  
      * elements to the right (adds one to their indices).</p>
 4263  
      *
 4264  
      * <p>This method returns a new array with the same elements of the input
 4265  
      * array plus the given element on the specified position. The component
 4266  
      * type of the returned array is always the same as that of the input
 4267  
      * array.</p>
 4268  
      *
 4269  
      * <p>If the input array is {@code null}, a new one element array is returned
 4270  
      *  whose component type is the same as the element.</p>
 4271  
      *
 4272  
      * <pre>
 4273  
      * ArrayUtils.add(null, 0, null)      = [null]
 4274  
      * ArrayUtils.add(null, 0, "a")       = ["a"]
 4275  
      * ArrayUtils.add(["a"], 1, null)     = ["a", null]
 4276  
      * ArrayUtils.add(["a"], 1, "b")      = ["a", "b"]
 4277  
      * ArrayUtils.add(["a", "b"], 3, "c") = ["a", "b", "c"]
 4278  
      * </pre>
 4279  
      *
 4280  
      * @param <T> the component type of the array
 4281  
      * @param array  the array to add the element to, may be {@code null}
 4282  
      * @param index  the position of the new object
 4283  
      * @param element  the object to add
 4284  
      * @return A new array containing the existing elements and the new element
 4285  
      * @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt; array.length).
 4286  
      * @throws IllegalArgumentException if both array and element are null
 4287  
      */
 4288  
     public static <T> T[] add(final T[] array, final int index, final T element) {
 4289  8
         Class<?> clss = null;
 4290  8
         if (array != null) {
 4291  6
             clss = array.getClass().getComponentType();
 4292  2
         } else if (element != null) {
 4293  1
             clss = element.getClass();
 4294  
         } else {
 4295  1
             throw new IllegalArgumentException("Array and element cannot both be null");
 4296  
         }
 4297  
         @SuppressWarnings("unchecked") // the add method creates an array of type clss, which is type T
 4298  7
         final T[] newArray = (T[]) add(array, index, element, clss);
 4299  7
         return newArray;
 4300  
     }
 4301  
 
 4302  
     /**
 4303  
      * <p>Inserts the specified element at the specified position in the array.
 4304  
      * Shifts the element currently at that position (if any) and any subsequent
 4305  
      * elements to the right (adds one to their indices).</p>
 4306  
      *
 4307  
      * <p>This method returns a new array with the same elements of the input
 4308  
      * array plus the given element on the specified position. The component
 4309  
      * type of the returned array is always the same as that of the input
 4310  
      * array.</p>
 4311  
      *
 4312  
      * <p>If the input array is {@code null}, a new one element array is returned
 4313  
      *  whose component type is the same as the element.</p>
 4314  
      *
 4315  
      * <pre>
 4316  
      * ArrayUtils.add(null, 0, true)          = [true]
 4317  
      * ArrayUtils.add([true], 0, false)       = [false, true]
 4318  
      * ArrayUtils.add([false], 1, true)       = [false, true]
 4319  
      * ArrayUtils.add([true, false], 1, true) = [true, true, false]
 4320  
      * </pre>
 4321  
      *
 4322  
      * @param array  the array to add the element to, may be {@code null}
 4323  
      * @param index  the position of the new object
 4324  
      * @param element  the object to add
 4325  
      * @return A new array containing the existing elements and the new element
 4326  
      * @throws IndexOutOfBoundsException if the index is out of range (index &lt; 0 || index &gt; array.length).
 4327  
      */
 4328  
     public static boolean[] add(final boolean[] array, final int index, final boolean element) {
 4329  7
         return (boolean[]) add(array, index, Boolean.valueOf(element), Boolean.TYPE);
 4330  
     }
 4331  
 
 4332  
     /**
 4333  
      * <p>Inserts the specified element at the specified position in the array.
 4334  
      * Shifts the element currently at that position (if any) and any subsequent
 4335  
      * elements to the right (adds one to their indices).</p>
 4336  
      *
 4337  
      * <p>This method returns a new array with the same elements of the input
 4338  
      * array plus the given element on the specified position. The component
 4339  
      * type of the returned array is always the same as that of the input
 4340  
      * array.</p>
 4341  
      *
 4342  
      * <p>If the input array is {@code null}, a new one element array is returned
 4343  
      *  whose component type is the same as the element.</p>
 4344  
      *
 4345  
      * <pre>
 4346  
      * ArrayUtils.add(null, 0, 'a')            = ['a']
 4347  
      * ArrayUtils.add(['a'], 0, 'b')           = ['b', 'a']
 4348  
      * ArrayUtils.add(['a', 'b'], 0, 'c')      = ['c', 'a', 'b']
 4349  
      * ArrayUtils.add(['a', 'b'], 1, 'k')      = ['a', 'k', 'b']
 4350  
      * ArrayUtils.add(['a', 'b', 'c'], 1, 't') = ['a', 't', 'b', 'c']
 4351  
      * </pre>
 4352  
      *
 4353  
      * @param array  the array to add the element to, may be {@code null}
 4354  
      * @param index  the position of the new object
 4355  
      * @param element  the object to add
 4356  
      * @return A new array containing the existing elements and the new element
 4357  
      * @throws IndexOutOfBoundsException if the index is out of range
 4358  
      * (index &lt; 0 || index &gt; array.length).
 4359  
      */
 4360  
     public static char[] add(final char[] array, final int index, final char element) {
 4361  8
         return (char[]) add(array, index, Character.valueOf(element), Character.TYPE);
 4362  
     }
 4363  
 
 4364  
     /**
 4365  
      * <p>Inserts the specified element at the specified position in the array.
 4366  
      * Shifts the element currently at that position (if any) and any subsequent
 4367  
      * elements to the right (adds one to their indices).</p>
 4368  
      *
 4369  
      * <p>This method returns a new array with the same elements of the input
 4370  
      * array plus the given element on the specified position. The component
 4371  
      * type of the returned array is always the same as that of the input
 4372  
      * array.</p>
 4373  
      *
 4374  
      * <p>If the input array is {@code null}, a new one element array is returned
 4375  
      *  whose component type is the same as the element.</p>
 4376  
      *
 4377  
      * <pre>
 4378  
      * ArrayUtils.add([1], 0, 2)         = [2, 1]
 4379  
      * ArrayUtils.add([2, 6], 2, 3)      = [2, 6, 3]
 4380  
      * ArrayUtils.add([2, 6], 0, 1)      = [1, 2, 6]
 4381  
      * ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
 4382  
      * </pre>
 4383  
      *
 4384  
      * @param array  the array to add the element to, may be {@code null}
 4385  
      * @param index  the position of the new object
 4386  
      * @param element  the object to add
 4387  
      * @return A new array containing the existing elements and the new element
 4388  
      * @throws IndexOutOfBoundsException if the index is out of range
 4389  
      * (index &lt; 0 || index &gt; array.length).
 4390  
      */
 4391  
     public static byte[] add(final byte[] array, final int index, final byte element) {
 4392  7
         return (byte[]) add(array, index, Byte.valueOf(element), Byte.TYPE);
 4393  
     }
 4394  
 
 4395  
     /**
 4396  
      * <p>Inserts the specified element at the specified position in the array.
 4397  
      * Shifts the element currently at that position (if any) and any subsequent
 4398  
      * elements to the right (adds one to their indices).</p>
 4399  
      *
 4400  
      * <p>This method returns a new array with the same elements of the input
 4401  
      * array plus the given element on the specified position. The component
 4402  
      * type of the returned array is always the same as that of the input
 4403  
      * array.</p>
 4404  
      *
 4405  
      * <p>If the input array is {@code null}, a new one element array is returned
 4406  
      *  whose component type is the same as the element.</p>
 4407  
      *
 4408  
      * <pre>
 4409  
      * ArrayUtils.add([1], 0, 2)         = [2, 1]
 4410  
      * ArrayUtils.add([2, 6], 2, 10)     = [2, 6, 10]
 4411  
      * ArrayUtils.add([2, 6], 0, -4)     = [-4, 2, 6]
 4412  
      * ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
 4413  
      * </pre>
 4414  
      *
 4415  
      * @param array  the array to add the element to, may be {@code null}
 4416  
      * @param index  the position of the new object
 4417  
      * @param element  the object to add
 4418  
      * @return A new array containing the existing elements and the new element
 4419  
      * @throws IndexOutOfBoundsException if the index is out of range
 4420  
      * (index &lt; 0 || index &gt; array.length).
 4421  
      */
 4422  
     public static short[] add(final short[] array, final int index, final short element) {
 4423  7
         return (short[]) add(array, index, Short.valueOf(element), Short.TYPE);
 4424  
     }
 4425  
 
 4426  
     /**
 4427  
      * <p>Inserts the specified element at the specified position in the array.
 4428  
      * Shifts the element currently at that position (if any) and any subsequent
 4429  
      * elements to the right (adds one to their indices).</p>
 4430  
      *
 4431  
      * <p>This method returns a new array with the same elements of the input
 4432  
      * array plus the given element on the specified position. The component
 4433  
      * type of the returned array is always the same as that of the input
 4434  
      * array.</p>
 4435  
      *
 4436  
      * <p>If the input array is {@code null}, a new one element array is returned
 4437  
      *  whose component type is the same as the element.</p>
 4438  
      *
 4439  
      * <pre>
 4440  
      * ArrayUtils.add([1], 0, 2)         = [2, 1]
 4441  
      * ArrayUtils.add([2, 6], 2, 10)     = [2, 6, 10]
 4442  
      * ArrayUtils.add([2, 6], 0, -4)     = [-4, 2, 6]
 4443  
      * ArrayUtils.add([2, 6, 3], 2, 1)   = [2, 6, 1, 3]
 4444  
      * </pre>
 4445  
      *
 4446  
      * @param array  the array to add the element to, may be {@code null}
 4447  
      * @param index  the position of the new object
 4448  
      * @param element  the object to add
 4449  
      * @return A new array containing the existing elements and the new element
 4450  
      * @throws IndexOutOfBoundsException if the index is out of range
 4451  
      * (index &lt; 0 || index &gt; array.length).
 4452  
      */
 4453  
     public static int[] add(final int[] array, final int index, final int element) {
 4454  7
         return (int[]) add(array, index, Integer.valueOf(element), Integer.TYPE);
 4455  
     }
 4456  
 
 4457  
     /**
 4458  
      * <p>Inserts the specified element at the specified position in the array.
 4459  
      * Shifts the element currently at that position (if any) and any subsequent
 4460  
      * elements to the right (adds one to their indices).</p>
 4461  
      *
 4462  
      * <p>This method returns a new array with the same elements of the input
 4463  
      * array plus the given element on the specified position. The component
 4464  
      * type of the returned array is always the same as that of the input
 4465  
      * array.</p>
 4466  
      *
 4467  
      * <p>If the input array is {@code null}, a new one element array is returned
 4468  
      *  whose component type is the same as the element.</p>
 4469  
      *
 4470  
      * <pre>
 4471  
      * ArrayUtils.add([1L], 0, 2L)           = [2L, 1L]
 4472  
      * ArrayUtils.add([2L, 6L], 2, 10L)      = [2L, 6L, 10L]
 4473  
      * ArrayUtils.add([2L, 6L], 0, -4L)      = [-4L, 2L, 6L]
 4474  
      * ArrayUtils.add([2L, 6L, 3L], 2, 1L)   = [2L, 6L, 1L, 3L]
 4475  
      * </pre>
 4476  
      *
 4477  
      * @param array  the array to add the element to, may be {@code null}
 4478  
      * @param index  the position of the new object
 4479  
      * @param element  the object to add
 4480  
      * @return A new array containing the existing elements and the new element
 4481  
      * @throws IndexOutOfBoundsException if the index is out of range
 4482  
      * (index &lt; 0 || index &gt; array.length).
 4483  
      */
 4484  
     public static long[] add(final long[] array, final int index, final long element) {
 4485  7
         return (long[]) add(array, index, Long.valueOf(element), Long.TYPE);
 4486  
     }
 4487  
 
 4488  
     /**
 4489  
      * <p>Inserts the specified element at the specified position in the array.
 4490  
      * Shifts the element currently at that position (if any) and any subsequent
 4491  
      * elements to the right (adds one to their indices).</p>
 4492  
      *
 4493  
      * <p>This method returns a new array with the same elements of the input
 4494  
      * array plus the given element on the specified position. The component
 4495  
      * type of the returned array is always the same as that of the input
 4496  
      * array.</p>
 4497  
      *
 4498  
      * <p>If the input array is {@code null}, a new one element array is returned
 4499  
      *  whose component type is the same as the element.</p>
 4500  
      *
 4501  
      * <pre>
 4502  
      * ArrayUtils.add([1.1f], 0, 2.2f)               = [2.2f, 1.1f]
 4503  
      * ArrayUtils.add([2.3f, 6.4f], 2, 10.5f)        = [2.3f, 6.4f, 10.5f]
 4504  
      * ArrayUtils.add([2.6f, 6.7f], 0, -4.8f)        = [-4.8f, 2.6f, 6.7f]
 4505  
      * ArrayUtils.add([2.9f, 6.0f, 0.3f], 2, 1.0f)   = [2.9f, 6.0f, 1.0f, 0.3f]
 4506  
      * </pre>
 4507  
      *
 4508  
      * @param array  the array to add the element to, may be {@code null}
 4509  
      * @param index  the position of the new object
 4510  
      * @param element  the object to add
 4511  
      * @return A new array containing the existing elements and the new element
 4512  
      * @throws IndexOutOfBoundsException if the index is out of range
 4513  
      * (index &lt; 0 || index &gt; array.length).
 4514  
      */
 4515  
     public static float[] add(final float[] array, final int index, final float element) {
 4516  7
         return (float[]) add(array, index, Float.valueOf(element), Float.TYPE);
 4517  
     }
 4518  
 
 4519  
     /**
 4520  
      * <p>Inserts the specified element at the specified position in the array.
 4521  
      * Shifts the element currently at that position (if any) and any subsequent
 4522  
      * elements to the right (adds one to their indices).</p>
 4523  
      *
 4524  
      * <p>This method returns a new array with the same elements of the input
 4525  
      * array plus the given element on the specified position. The component
 4526  
      * type of the returned array is always the same as that of the input
 4527  
      * array.</p>
 4528  
      *
 4529  
      * <p>If the input array is {@code null}, a new one element array is returned
 4530  
      *  whose component type is the same as the element.</p>
 4531  
      *
 4532  
      * <pre>
 4533  
      * ArrayUtils.add([1.1], 0, 2.2)              = [2.2, 1.1]
 4534  
      * ArrayUtils.add([2.3, 6.4], 2, 10.5)        = [2.3, 6.4, 10.5]
 4535  
      * ArrayUtils.add([2.6, 6.7], 0, -4.8)        = [-4.8, 2.6, 6.7]
 4536  
      * ArrayUtils.add([2.9, 6.0, 0.3], 2, 1.0)    = [2.9, 6.0, 1.0, 0.3]
 4537  
      * </pre>
 4538  
      *
 4539  
      * @param array  the array to add the element to, may be {@code null}
 4540  
      * @param index  the position of the new object
 4541  
      * @param element  the object to add
 4542  
      * @return A new array containing the existing elements and the new element
 4543  
      * @throws IndexOutOfBoundsException if the index is out of range
 4544  
      * (index &lt; 0 || index &gt; array.length).
 4545  
      */
 4546  
     public static double[] add(final double[] array, final int index, final double element) {
 4547  7
         return (double[]) add(array, index, Double.valueOf(element), Double.TYPE);
 4548  
     }
 4549  
 
 4550  
     /**
 4551  
      * Underlying implementation of add(array, index, element) methods.
 4552  
      * The last parameter is the class, which may not equal element.getClass
 4553  
      * for primitives.
 4554  
      *
 4555  
      * @param array  the array to add the element to, may be {@code null}
 4556  
      * @param index  the position of the new object
 4557  
      * @param element  the object to add
 4558  
      * @param clss the type of the element being added
 4559  
      * @return A new array containing the existing elements and the new element
 4560  
      */
 4561  
     private static Object add(final Object array, final int index, final Object element, final Class<?> clss) {
 4562  64
         if (array == null) {
 4563  11
             if (index != 0) {
 4564  8
                 throw new IndexOutOfBoundsException("Index: " + index + ", Length: 0");
 4565  
             }
 4566  3
             final Object joinedArray = Array.newInstance(clss, 1);
 4567  3
             Array.set(joinedArray, 0, element);
 4568  3
             return joinedArray;
 4569  
         }
 4570  53
         final int length = Array.getLength(array);
 4571  53
         if (index > length || index < 0) {
 4572  16
             throw new IndexOutOfBoundsException("Index: " + index + ", Length: " + length);
 4573  
         }
 4574  37
         final Object result = Array.newInstance(clss, length + 1);
 4575  37
         System.arraycopy(array, 0, result, 0, index);
 4576  37
         Array.set(result, index, element);
 4577  37
         if (index < length) {
 4578  27
             System.arraycopy(array, index, result, index + 1, length - index);
 4579  
         }
 4580  37
         return result;
 4581  
     }
 4582  
 
 4583  
     /**
 4584  
      * <p>Removes the element at the specified position from the specified array.
 4585  
      * All subsequent elements are shifted to the left (subtracts one from
 4586  
      * their indices).</p>
 4587  
      *
 4588  
      * <p>This method returns a new array with the same elements of the input
 4589  
      * array except the element on the specified position. The component
 4590  
      * type of the returned array is always the same as that of the input
 4591  
      * array.</p>
 4592  
      *
 4593  
      * <p>If the input array is {@code null}, an IndexOutOfBoundsException
 4594  
      * will be thrown, because in that case no valid index can be specified.</p>
 4595  
      *
 4596  
      * <pre>
 4597  
      * ArrayUtils.remove(["a"], 0)           = []
 4598  
      * ArrayUtils.remove(["a", "b"], 0)      = ["b"]
 4599  
      * ArrayUtils.remove(["a", "b"], 1)      = ["a"]
 4600  
      * ArrayUtils.remove(["a", "b", "c"], 1) = ["a", "c"]
 4601  
      * </pre>
 4602  
      *
 4603  
      * @param <T> the component type of the array
 4604  
      * @param array  the array to remove the element from, may not be {@code null}
 4605  
      * @param index  the position of the element to be removed
 4606  
      * @return A new array containing the existing elements except the element
 4607  
      *         at the specified position.
 4608  
      * @throws IndexOutOfBoundsException if the index is out of range
 4609  
      * (index &lt; 0 || index &gt;= array.length), or if the array is {@code null}.
 4610  
      * @since 2.1
 4611  
      */
 4612  
     @SuppressWarnings("unchecked") // remove() always creates an array of the same type as its input
 4613  
     public static <T> T[] remove(final T[] array, final int index) {
 4614  14
         return (T[]) remove((Object) array, index);
 4615  
     }
 4616  
 
 4617  
     /**
 4618  
      * <p>Removes the first occurrence of the specified element from the
 4619  
      * specified array. All subsequent elements are shifted to the left
 4620  
      * (subtracts one from their indices). If the array doesn't contains
 4621  
      * such an element, no elements are removed from the array.</p>
 4622  
      *
 4623  
      * <p>This method returns a new array with the same elements of the input
 4624  
      * array except the first occurrence of the specified element. The component
 4625  
      * type of the returned array is always the same as that of the input
 4626  
      * array.</p>
 4627  
      *
 4628  
      * <pre>
 4629  
      * ArrayUtils.removeElement(null, "a")            = null
 4630  
      * ArrayUtils.removeElement([], "a")              = []
 4631  
      * ArrayUtils.removeElement(["a"], "b")           = ["a"]
 4632  
      * ArrayUtils.removeElement(["a", "b"], "a")      = ["b"]
 4633  
      * ArrayUtils.removeElement(["a", "b", "a"], "a") = ["b", "a"]
 4634  
      * </pre>
 4635  
      *
 4636  
      * @param <T> the component type of the array
 4637  
      * @param array  the array to remove the element from, may be {@code null}
 4638  
      * @param element  the element to be removed
 4639  
      * @return A new array containing the existing elements except the first
 4640  
      *         occurrence of the specified element.
 4641  
      * @since 2.1
 4642  
      */
 4643  
     public static <T> T[] removeElement(final T[] array, final Object element) {
 4644  5
         final int index = indexOf(array, element);
 4645  5
         if (index == INDEX_NOT_FOUND) {
 4646  2
             return clone(array);
 4647  
         }
 4648  3
         return remove(array, index);
 4649  
     }
 4650  
 
 4651  
     /**
 4652  
      * <p>Removes the element at the specified position from the specified array.
 4653  
      * All subsequent elements are shifted to the left (subtracts one from
 4654  
      * their indices).</p>
 4655  
      *
 4656  
      * <p>This method returns a new array with the same elements of the input
 4657  
      * array except the element on the specified position. The component
 4658  
      * type of the returned array is always the same as that of the input
 4659  
      * array.</p>
 4660  
      *
 4661  
      * <p>If the input array is {@code null}, an IndexOutOfBoundsException
 4662  
      * will be thrown, because in that case no valid index can be specified.</p>
 4663  
      *
 4664  
      * <pre>
 4665  
      * ArrayUtils.remove([true], 0)              = []
 4666  
      * ArrayUtils.remove([true, false], 0)       = [false]
 4667  
      * ArrayUtils.remove([true, false], 1)       = [true]
 4668  
      * ArrayUtils.remove([true, true, false], 1) = [true, false]
 4669  
      * </pre>
 4670  
      *
 4671  
      * @param array  the array to remove the element from, may not be {@code null}
 4672  
      * @param index  the position of the element to be removed
 4673  
      * @return A new array containing the existing elements except the element
 4674  
      *         at the specified position.
 4675  
      * @throws IndexOutOfBoundsException if the index is out of range
 4676  
      * (index &lt; 0 || index &gt;= array.length), or if the array is {@code null}.
 4677  
      * @since 2.1
 4678  
      */
 4679  
     public static boolean[] remove(final boolean[] array, final int index) {
 4680  10
         return (boolean[]) remove((Object) array, index);
 4681  
     }
 4682  
 
 4683  
     /**
 4684  
      * <p>Removes the first occurrence of the specified element from the
 4685  
      * specified array. All subsequent elements are shifted to the left
 4686  
      * (subtracts one from their indices). If the array doesn't contains
 4687  
      * such an element, no elements are removed from the array.</p>
 4688  
      *
 4689  
      * <p>This method returns a new array with the same elements of the input
 4690  
      * array except the first occurrence of the specified element. The component
 4691  
      * type of the returned array is always the same as that of the input
 4692  
      * array.</p>
 4693  
      *
 4694  
      * <pre>
 4695  
      * ArrayUtils.removeElement(null, true)                = null
 4696  
      * ArrayUtils.removeElement([], true)                  = []
 4697  
      * ArrayUtils.removeElement([true], false)             = [true]
 4698  
      * ArrayUtils.removeElement([true, false], false)      = [true]
 4699  
      * ArrayUtils.removeElement([true, false, true], true) = [false, true]
 4700  
      * </pre>
 4701  
      *
 4702  
      * @param array  the array to remove the element from, may be {@code null}
 4703  
      * @param element  the element to be removed
 4704  
      * @return A new array containing the existing elements except the first
 4705  
      *         occurrence of the specified element.
 4706  
      * @since 2.1
 4707  
      */
 4708  
     public static boolean[] removeElement(final boolean[] array, final boolean element) {
 4709  5
         final int index = indexOf(array, element);
 4710  5
         if (index == INDEX_NOT_FOUND) {
 4711  2
             return clone(array);
 4712  
         }
 4713  3
         return remove(array, index);
 4714  
     }
 4715  
 
 4716  
     /**
 4717  
      * <p>Removes the element at the specified position from the specified array.
 4718  
      * All subsequent elements are shifted to the left (subtracts one from
 4719  
      * their indices).</p>
 4720  
      *
 4721  
      * <p>This method returns a new array with the same elements of the input
 4722  
      * array except the element on the specified position. The component
 4723  
      * type of the returned array is always the same as that of the input
 4724  
      * array.</p>
 4725  
      *
 4726  
      * <p>If the input array is {@code null}, an IndexOutOfBoundsException
 4727  
      * will be thrown, because in that case no valid index can be specified.</p>
 4728  
      *
 4729  
      * <pre>
 4730  
      * ArrayUtils.remove([1], 0)          = []
 4731  
      * ArrayUtils.remove([1, 0], 0)       = [0]
 4732  
      * ArrayUtils.remove([1, 0], 1)       = [1]
 4733  
      * ArrayUtils.remove([1, 0, 1], 1)    = [1, 1]
 4734  
      * </pre>
 4735  
      *
 4736  
      * @param array  the array to remove the element from, may not be {@code null}
 4737  
      * @param index  the position of the element to be removed
 4738  
      * @return A new array containing the existing elements except the element
 4739  
      *         at the specified position.
 4740  
      * @throws IndexOutOfBoundsException if the index is out of range
 4741  
      * (index &lt; 0 || index &gt;= array.length), or if the array is {@code null}.
 4742  
      * @since 2.1
 4743  
      */
 4744  
     public static byte[] remove(final byte[] array, final int index) {
 4745  10
         return (byte[]) remove((Object) array, index);
 4746  
     }
 4747  
 
 4748  
     /**
 4749  
      * <p>Removes the first occurrence of the specified element from the
 4750  
      * specified array. All subsequent elements are shifted to the left
 4751  
      * (subtracts one from their indices). If the array doesn't contains
 4752  
      * such an element, no elements are removed from the array.</p>
 4753  
      *
 4754  
      * <p>This method returns a new array with the same elements of the input
 4755  
      * array except the first occurrence of the specified element. The component
 4756  
      * type of the returned array is always the same as that of the input
 4757  
      * array.</p>
 4758  
      *
 4759  
      * <pre>
 4760  
      * ArrayUtils.removeElement(null, 1)        = null
 4761  
      * ArrayUtils.removeElement([], 1)          = []
 4762  
      * ArrayUtils.removeElement([1], 0)         = [1]
 4763  
      * ArrayUtils.removeElement([1, 0], 0)      = [1]
 4764  
      * ArrayUtils.removeElement([1, 0, 1], 1)   = [0, 1]
 4765  
      * </pre>
 4766  
      *
 4767  
      * @param array  the array to remove the element from, may be {@code null}
 4768  
      * @param element  the element to be removed
 4769  
      * @return A new array containing the existing elements except the first
 4770  
      *         occurrence of the specified element.
 4771  
      * @since 2.1
 4772  
      */
 4773  
     public static byte[] removeElement(final byte[] array, final byte element) {
 4774  5
         final int index = indexOf(array, element);
 4775  5
         if (index == INDEX_NOT_FOUND) {
 4776  2
             return clone(array);
 4777  
         }
 4778  3
         return remove(array, index);
 4779  
     }
 4780  
 
 4781  
     /**
 4782  
      * <p>Removes the element at the specified position from the specified array.
 4783  
      * All subsequent elements are shifted to the left (subtracts one from
 4784  
      * their indices).</p>
 4785  
      *
 4786  
      * <p>This method returns a new array with the same elements of the input
 4787  
      * array except the element on the specified position. The component
 4788  
      * type of the returned array is always the same as that of the input
 4789  
      * array.</p>
 4790  
      *
 4791  
      * <p>If the input array is {@code null}, an IndexOutOfBoundsException
 4792  
      * will be thrown, because in that case no valid index can be specified.</p>
 4793  
      *
 4794  
      * <pre>
 4795  
      * ArrayUtils.remove(['a'], 0)           = []
 4796  
      * ArrayUtils.remove(['a', 'b'], 0)      = ['b']
 4797  
      * ArrayUtils.remove(['a', 'b'], 1)      = ['a']
 4798  
      * ArrayUtils.remove(['a', 'b', 'c'], 1) = ['a', 'c']
 4799  
      * </pre>
 4800  
      *
 4801  
      * @param array  the array to remove the element from, may not be {@code null}
 4802  
      * @param index  the position of the element to be removed
 4803  
      * @return A new array containing the existing elements except the element
 4804  
      *         at the specified position.
 4805  
      * @throws IndexOutOfBoundsException if the index is out of range
 4806  
      * (index &lt; 0 || index &gt;= array.length), or if the array is {@code null}.
 4807  
      * @since 2.1
 4808  
      */
 4809  
     public static char[] remove(final char[] array, final int index) {
 4810  10
         return (char[]) remove((Object) array, index);
 4811  
     }
 4812  
 
 4813  
     /**
 4814  
      * <p>Removes the first occurrence of the specified element from the
 4815  
      * specified array. All subsequent elements are shifted to the left
 4816  
      * (subtracts one from their indices). If the array doesn't contains
 4817  
      * such an element, no elements are removed from the array.</p>
 4818  
      *
 4819