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