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