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