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