1. /* ====================================================================
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowledgement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgement may appear in the software itself,
  24. * if and wherever such third-party acknowledgements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.commons.lang;
  55. import java.util.HashMap;
  56. import java.util.Map;
  57. import org.apache.commons.lang.builder.EqualsBuilder;
  58. import org.apache.commons.lang.builder.HashCodeBuilder;
  59. import org.apache.commons.lang.builder.ToStringBuilder;
  60. import org.apache.commons.lang.builder.ToStringStyle;
  61. /**
  62. * <p>Operations on arrays, primitive arrays (like <code>int[]</code>) and primitive wrapper arrays
  63. * (like <code>Integer[]</code>).</p>
  64. *
  65. * <p>This class tries to handle <code>null</code> input gracefully.
  66. * An exception will not be thrown for a <code>null</code>
  67. * array input. However, an Object array that contains a <code>null</code>
  68. * element may throw an exception. Each method documents its behaviour.</p>
  69. *
  70. * @author Stephen Colebourne
  71. * @author Moritz Petersen
  72. * @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
  73. * @author Nikolay Metchev
  74. * @author Matthew Hawthorne
  75. * @author Tim O'Brien
  76. * @author Pete Gieser
  77. * @author Gary Gregory
  78. * @since 2.0
  79. * @version $Id: ArrayUtils.java,v 1.25 2003/08/22 17:25:33 ggregory Exp $
  80. */
  81. public class ArrayUtils {
  82. /**
  83. * An empty immutable <code>Object</code> array.
  84. */
  85. public static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
  86. /**
  87. * An empty immutable <code>Class</code> array.
  88. */
  89. public static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
  90. /**
  91. * An empty immutable <code>String</code> array.
  92. */
  93. public static final String[] EMPTY_STRING_ARRAY = new String[0];
  94. /**
  95. * An empty immutable <code>long</code> array.
  96. */
  97. public static final long[] EMPTY_LONG_ARRAY = new long[0];
  98. /**
  99. * An empty immutable <code>Long</code> array.
  100. */
  101. public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0];
  102. /**
  103. * An empty immutable <code>int</code> array.
  104. */
  105. public static final int[] EMPTY_INT_ARRAY = new int[0];
  106. /**
  107. * An empty immutable <code>Integer</code> array.
  108. */
  109. public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0];
  110. /**
  111. * An empty immutable <code>short</code> array.
  112. */
  113. public static final short[] EMPTY_SHORT_ARRAY = new short[0];
  114. /**
  115. * An empty immutable <code>Short</code> array.
  116. */
  117. public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0];
  118. /**
  119. * An empty immutable <code>byte</code> array.
  120. */
  121. public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
  122. /**
  123. * An empty immutable <code>Byte</code> array.
  124. */
  125. public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0];
  126. /**
  127. * An empty immutable <code>double</code> array.
  128. */
  129. public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
  130. /**
  131. * An empty immutable <code>Double</code> array.
  132. */
  133. public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0];
  134. /**
  135. * An empty immutable <code>float</code> array.
  136. */
  137. public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
  138. /**
  139. * An empty immutable <code>Float</code> array.
  140. */
  141. public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0];
  142. /**
  143. * An empty immutable <code>boolean</code> array.
  144. */
  145. public static final boolean[] EMPTY_BOOLEAN_ARRAY = new boolean[0];
  146. /**
  147. * An empty immutable <code>Boolean</code> array.
  148. */
  149. public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0];
  150. /**
  151. * An empty immutable <code>char</code> array.
  152. */
  153. public static final char[] EMPTY_CHAR_ARRAY = new char[0];
  154. /**
  155. * An empty immutable <code>Character</code> array.
  156. */
  157. public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0];
  158. /**
  159. * <p>ArrayUtils instances should NOT be constructed in standard programming.
  160. * Instead, the class should be used as <code>ArrayUtils.clone(new int[] {2})</code>.</p>
  161. *
  162. * <p>This constructor is public to permit tools that require a JavaBean instance
  163. * to operate.</p>
  164. */
  165. public ArrayUtils() {
  166. }
  167. // Basic methods handling multi-dimensional arrays
  168. //-----------------------------------------------------------------------
  169. /**
  170. * <p>Outputs an array as a String, treating <code>null</code> as an empty array.</p>
  171. *
  172. * <p>Multi-dimensional arrays are handled correctly, including
  173. * multi-dimensional primitive arrays.</p>
  174. *
  175. * <p>The format is that of Java source code, for example <code>{a,b}</code>.</p>
  176. *
  177. * @param array the array to get a toString for, may be <code>null</code>
  178. * @return a String representation of the array, '{}' if null array input
  179. */
  180. public static String toString(final Object array) {
  181. return toString(array, "{}");
  182. }
  183. /**
  184. * <p>Outputs an array as a String handling <code>null</code>s.</p>
  185. *
  186. * <p>Multi-dimensional arrays are handled correctly, including
  187. * multi-dimensional primitive arrays.</p>
  188. *
  189. * <p>The format is that of Java source code, for example <code>{a,b}</code>.</p>
  190. *
  191. * @param array the array to get a toString for, may be <code>null</code>
  192. * @param stringIfNull the String to return if the array is <code>null</code>
  193. * @return a String representation of the array
  194. */
  195. public static String toString(final Object array, final String stringIfNull) {
  196. if (array == null) {
  197. return stringIfNull;
  198. }
  199. return new ToStringBuilder(array, ToStringStyle.SIMPLE_STYLE).append(array).toString();
  200. }
  201. /**
  202. * <p>Get a hashCode for an array handling multi-dimensional arrays correctly.</p>
  203. *
  204. * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
  205. *
  206. * @param array the array to get a hashCode for, may be <code>null</code>
  207. * @return a hashCode for the array, zero if null array input
  208. */
  209. public static int hashCode(final Object array) {
  210. return new HashCodeBuilder().append(array).toHashCode();
  211. }
  212. /**
  213. * <p>Compares two arrays, using equals(), handling multi-dimensional arrays
  214. * correctly.</p>
  215. *
  216. * <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
  217. *
  218. * @param array1 the array to get a hashCode for, may be <code>null</code>
  219. * @param array2 the array to get a hashCode for, may be <code>null</code>
  220. * @return <code>true</code> if the arrays are equal
  221. */
  222. public static boolean isEquals(final Object array1, final Object array2) {
  223. return new EqualsBuilder().append(array1, array2).isEquals();
  224. }
  225. // To map
  226. //-----------------------------------------------------------------------
  227. /**
  228. * <p>Converts the given array into a {@link java.util.Map}. Each element of the array
  229. * must be either a {@link java.util.Map.Entry} or an Array, containing at least two
  230. * elements, where the first element is used as key and the second as
  231. * value.</p>
  232. *
  233. * <p>This method can be used to initialize:</p>
  234. * <pre>
  235. * // Create a Map mapping colors.
  236. * Map colorMap = MapUtils.toMap(new String[][] {{
  237. * {"RED", "#FF0000"},
  238. * {"GREEN", "#00FF00"},
  239. * {"BLUE", "#0000FF"}});
  240. * </pre>
  241. *
  242. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  243. *
  244. * @param array an array whose elements are either a {@link java.util.Map.Entry} or
  245. * an Array containing at least two elements, may be <code>null</code>
  246. * @return a <code>Map</code> that was created from the array
  247. * @throws IllegalArgumentException if one element of this Array is
  248. * itself an Array containing less then two elements
  249. * @throws IllegalArgumentException if the array contains elements other
  250. * than {@link java.util.Map.Entry} and an Array
  251. */
  252. public static Map toMap(final Object[] array) {
  253. if (array == null) {
  254. return null;
  255. }
  256. final Map map = new HashMap((int) (array.length * 1.5));
  257. for (int i = 0; i < array.length; i++) {
  258. Object object = array[i];
  259. if (object instanceof Map.Entry) {
  260. Map.Entry entry = (Map.Entry) object;
  261. map.put(entry.getKey(), entry.getValue());
  262. } else if (object instanceof Object[]) {
  263. Object[] entry = (Object[]) object;
  264. if (entry.length < 2) {
  265. throw new IllegalArgumentException("Array element " + i + ", '"
  266. + object
  267. + "', has a length less than 2");
  268. }
  269. map.put(entry[0], entry[1]);
  270. } else {
  271. throw new IllegalArgumentException("Array element " + i + ", '"
  272. + object
  273. + "', is neither of type Map.Entry nor an Array");
  274. }
  275. }
  276. return map;
  277. }
  278. // Clone
  279. //-----------------------------------------------------------------------
  280. /**
  281. * <p>Shallow clones an array returning a typecast result and handling
  282. * <code>null</code>.</p>
  283. *
  284. * <p>The objecs in the array are not cloned, thus there is no special
  285. * handling for multi-dimensional arrays.</p>
  286. *
  287. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  288. *
  289. * @param array the array to shallow clone, may be <code>null</code>
  290. * @return the cloned array, <code>null</code> if <code>null</code> input
  291. */
  292. public static Object[] clone(final Object[] array) {
  293. if (array == null) {
  294. return null;
  295. }
  296. return (Object[]) array.clone();
  297. }
  298. /**
  299. * <p>Clones an array returning a typecast result and handling
  300. * <code>null</code>.</p>
  301. *
  302. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  303. *
  304. * @param array the array to clone, may be <code>null</code>
  305. * @return the cloned array, <code>null</code> if <code>null</code> input
  306. */
  307. public static long[] clone(final long[] array) {
  308. if (array == null) {
  309. return null;
  310. }
  311. return (long[]) array.clone();
  312. }
  313. /**
  314. * <p>Clones an array returning a typecast result and handling
  315. * <code>null</code>.</p>
  316. *
  317. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  318. *
  319. * @param array the array to clone, may be <code>null</code>
  320. * @return the cloned array, <code>null</code> if <code>null</code> input
  321. */
  322. public static int[] clone(int[] array) {
  323. if (array == null) {
  324. return null;
  325. }
  326. return (int[]) array.clone();
  327. }
  328. /**
  329. * <p>Clones an array returning a typecast result and handling
  330. * <code>null</code>.</p>
  331. *
  332. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  333. *
  334. * @param array the array to clone, may be <code>null</code>
  335. * @return the cloned array, <code>null</code> if <code>null</code> input
  336. */
  337. public static short[] clone(final short[] array) {
  338. if (array == null) {
  339. return null;
  340. }
  341. return (short[]) array.clone();
  342. }
  343. /**
  344. * <p>Clones an array returning a typecast result and handling
  345. * <code>null</code>.</p>
  346. *
  347. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  348. *
  349. * @param array the array to clone, may be <code>null</code>
  350. * @return the cloned array, <code>null</code> if <code>null</code> input
  351. */
  352. public static char[] clone(final char[] array) {
  353. if (array == null) {
  354. return null;
  355. }
  356. return (char[]) array.clone();
  357. }
  358. /**
  359. * <p>Clones an array returning a typecast result and handling
  360. * <code>null</code>.</p>
  361. *
  362. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  363. *
  364. * @param array the array to clone, may be <code>null</code>
  365. * @return the cloned array, <code>null</code> if <code>null</code> input
  366. */
  367. public static byte[] clone(final byte[] array) {
  368. if (array == null) {
  369. return null;
  370. }
  371. return (byte[]) array.clone();
  372. }
  373. /**
  374. * <p>Clones an array returning a typecast result and handling
  375. * <code>null</code>.</p>
  376. *
  377. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  378. *
  379. * @param array the array to clone, may be <code>null</code>
  380. * @return the cloned array, <code>null</code> if <code>null</code> input
  381. */
  382. public static double[] clone(final double[] array) {
  383. if (array == null) {
  384. return null;
  385. }
  386. return (double[]) array.clone();
  387. }
  388. /**
  389. * <p>Clones an array returning a typecast result and handling
  390. * <code>null</code>.</p>
  391. *
  392. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  393. *
  394. * @param array the array to clone, may be <code>null</code>
  395. * @return the cloned array, <code>null</code> if <code>null</code> input
  396. */
  397. public static float[] clone(final float[] array) {
  398. if (array == null) {
  399. return null;
  400. }
  401. return (float[]) array.clone();
  402. }
  403. /**
  404. * <p>Clones an array returning a typecast result and handling
  405. * <code>null</code>.</p>
  406. *
  407. * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
  408. *
  409. * @param array the array to clone, may be <code>null</code>
  410. * @return the cloned array, <code>null</code> if <code>null</code> input
  411. */
  412. public static boolean[] clone(final boolean[] array) {
  413. if (array == null) {
  414. return null;
  415. }
  416. return (boolean[]) array.clone();
  417. }
  418. // Is same length
  419. //-----------------------------------------------------------------------
  420. /**
  421. * <p>Checks whether two arrays are the same length, treating
  422. * <code>null</code> arrays as length <code>0</code>.
  423. *
  424. * <p>Any multi-dimensional aspects of the arrays are ignored.</p>
  425. *
  426. * @param array1 the first array, may be <code>null</code>
  427. * @param array2 the second array, may be <code>null</code>
  428. * @return <code>true</code> if length of arrays matches, treating
  429. * <code>null</code> as an empty array
  430. */
  431. public static boolean isSameLength(final Object[] array1, final Object[] array2) {
  432. if ((array1 == null && array2 != null && array2.length > 0) ||
  433. (array2 == null && array1 != null && array1.length > 0) ||
  434. (array1 != null && array2 != null && array1.length != array2.length)) {
  435. return false;
  436. }
  437. return true;
  438. }
  439. /**
  440. * <p>Checks whether two arrays are the same length, treating
  441. * <code>null</code> arrays as length <code>0</code>.</p>
  442. *
  443. * @param array1 the first array, may be <code>null</code>
  444. * @param array2 the second array, may be <code>null</code>
  445. * @return <code>true</code> if length of arrays matches, treating
  446. * <code>null</code> as an empty array
  447. */
  448. public static boolean isSameLength(final long[] array1, final long[] array2) {
  449. if ((array1 == null && array2 != null && array2.length > 0) ||
  450. (array2 == null && array1 != null && array1.length > 0) ||
  451. (array1 != null && array2 != null && array1.length != array2.length)) {
  452. return false;
  453. }
  454. return true;
  455. }
  456. /**
  457. * <p>Checks whether two arrays are the same length, treating
  458. * <code>null</code> arrays as length <code>0</code>.</p>
  459. *
  460. * @param array1 the first array, may be <code>null</code>
  461. * @param array2 the second array, may be <code>null</code>
  462. * @return <code>true</code> if length of arrays matches, treating
  463. * <code>null</code> as an empty array
  464. */
  465. public static boolean isSameLength(final int[] array1, final int[] array2) {
  466. if ((array1 == null && array2 != null && array2.length > 0) ||
  467. (array2 == null && array1 != null && array1.length > 0) ||
  468. (array1 != null && array2 != null && array1.length != array2.length)) {
  469. return false;
  470. }
  471. return true;
  472. }
  473. /**
  474. * <p>Checks whether two arrays are the same length, treating
  475. * <code>null</code> arrays as length <code>0</code>.</p>
  476. *
  477. * @param array1 the first array, may be <code>null</code>
  478. * @param array2 the second array, may be <code>null</code>
  479. * @return <code>true</code> if length of arrays matches, treating
  480. * <code>null</code> as an empty array
  481. */
  482. public static boolean isSameLength(final short[] array1, final short[] array2) {
  483. if ((array1 == null && array2 != null && array2.length > 0) ||
  484. (array2 == null && array1 != null && array1.length > 0) ||
  485. (array1 != null && array2 != null && array1.length != array2.length)) {
  486. return false;
  487. }
  488. return true;
  489. }
  490. /**
  491. * <p>Checks whether two arrays are the same length, treating
  492. * <code>null</code> arrays as length <code>0</code>.</p>
  493. *
  494. * @param array1 the first array, may be <code>null</code>
  495. * @param array2 the second array, may be <code>null</code>
  496. * @return <code>true</code> if length of arrays matches, treating
  497. * <code>null</code> as an empty array
  498. */
  499. public static boolean isSameLength(final char[] array1, final char[] array2) {
  500. if ((array1 == null && array2 != null && array2.length > 0) ||
  501. (array2 == null && array1 != null && array1.length > 0) ||
  502. (array1 != null && array2 != null && array1.length != array2.length)) {
  503. return false;
  504. }
  505. return true;
  506. }
  507. /**
  508. * <p>Checks whether two arrays are the same length, treating
  509. * <code>null</code> arrays as length <code>0</code>.</p>
  510. *
  511. * @param array1 the first array, may be <code>null</code>
  512. * @param array2 the second array, may be <code>null</code>
  513. * @return <code>true</code> if length of arrays matches, treating
  514. * <code>null</code> as an empty array
  515. */
  516. public static boolean isSameLength(final byte[] array1, final byte[] array2) {
  517. if ((array1 == null && array2 != null && array2.length > 0) ||
  518. (array2 == null && array1 != null && array1.length > 0) ||
  519. (array1 != null && array2 != null && array1.length != array2.length)) {
  520. return false;
  521. }
  522. return true;
  523. }
  524. /**
  525. * <p>Checks whether two arrays are the same length, treating
  526. * <code>null</code> arrays as length <code>0</code>.</p>
  527. *
  528. * @param array1 the first array, may be <code>null</code>
  529. * @param array2 the second array, may be <code>null</code>
  530. * @return <code>true</code> if length of arrays matches, treating
  531. * <code>null</code> as an empty array
  532. */
  533. public static boolean isSameLength(final double[] array1, final double[] array2) {
  534. if ((array1 == null && array2 != null && array2.length > 0) ||
  535. (array2 == null && array1 != null && array1.length > 0) ||
  536. (array1 != null && array2 != null && array1.length != array2.length)) {
  537. return false;
  538. }
  539. return true;
  540. }
  541. /**
  542. * <p>Checks whether two arrays are the same length, treating
  543. * <code>null</code> arrays as length <code>0</code>.</p>
  544. *
  545. * @param array1 the first array, may be <code>null</code>
  546. * @param array2 the second array, may be <code>null</code>
  547. * @return <code>true</code> if length of arrays matches, treating
  548. * <code>null</code> as an empty array
  549. */
  550. public static boolean isSameLength(final float[] array1, final float[] array2) {
  551. if ((array1 == null && array2 != null && array2.length > 0) ||
  552. (array2 == null && array1 != null && array1.length > 0) ||
  553. (array1 != null && array2 != null && array1.length != array2.length)) {
  554. return false;
  555. }
  556. return true;
  557. }
  558. /**
  559. * <p>Checks whether two arrays are the same length, treating
  560. * <code>null</code> arrays as length <code>0</code>.</p>
  561. *
  562. * @param array1 the first array, may be <code>null</code>
  563. * @param array2 the second array, may be <code>null</code>
  564. * @return <code>true</code> if length of arrays matches, treating
  565. * <code>null</code> as an empty array
  566. */
  567. public static boolean isSameLength(final boolean[] array1, final boolean[] array2) {
  568. if ((array1 == null && array2 != null && array2.length > 0) ||
  569. (array2 == null && array1 != null && array1.length > 0) ||
  570. (array1 != null && array2 != null && array1.length != array2.length)) {
  571. return false;
  572. }
  573. return true;
  574. }
  575. /**
  576. * <p>Checks whether two arrays are the same type taking into account
  577. * multi-dimensional arrays.</p>
  578. *
  579. * @param array1 the first array, must not be <code>null</code>
  580. * @param array2 the second array, must not be <code>null</code>
  581. * @return <code>true</code> if type of arrays matches
  582. * @throws IllegalArgumentException if either array is <code>null</code>
  583. */
  584. public static boolean isSameType(final Object array1, final Object array2) {
  585. if (array1 == null || array2 == null) {
  586. throw new IllegalArgumentException("The Array must not be null");
  587. }
  588. return array1.getClass().getName().equals(array2.getClass().getName());
  589. }
  590. // Reverse
  591. //-----------------------------------------------------------------------
  592. /**
  593. * <p>Reverses the order of the given array.</p>
  594. *
  595. * <p>There is no special handling for multi-dimensional arrays.</p>
  596. *
  597. * <p>This method does nothing if <code>null</code> array input.</p>
  598. *
  599. * @param array the array to reverse, may be <code>null</code>
  600. */
  601. public static void reverse(final Object[] array) {
  602. if (array == null) {
  603. return;
  604. }
  605. int i = 0;
  606. int j = array.length - 1;
  607. Object tmp;
  608. while (j > i) {
  609. tmp = array[j];
  610. array[j] = array[i];
  611. array[i] = tmp;
  612. j--;
  613. i++;
  614. }
  615. }
  616. /**
  617. * <p>Reverses the order of the given array.</p>
  618. *
  619. * <p>This method does nothing if <code>null</code> array input.</p>
  620. *
  621. * @param array the array to reverse, may be <code>null</code>
  622. */
  623. public static void reverse(final long[] array) {
  624. if (array == null) {
  625. return;
  626. }
  627. int i = 0;
  628. int j = array.length - 1;
  629. long tmp;
  630. while (j > i) {
  631. tmp = array[j];
  632. array[j] = array[i];
  633. array[i] = tmp;
  634. j--;
  635. i++;
  636. }
  637. }
  638. /**
  639. * <p>Reverses the order of the given array.</p>
  640. *
  641. * <p>This method does nothing if <code>null</code> array input.</p>
  642. *
  643. * @param array the array to reverse, may be <code>null</code>
  644. */
  645. public static void reverse(final int[] array) {
  646. if (array == null) {
  647. return;
  648. }
  649. int i = 0;
  650. int j = array.length - 1;
  651. int tmp;
  652. while (j > i) {
  653. tmp = array[j];
  654. array[j] = array[i];
  655. array[i] = tmp;
  656. j--;
  657. i++;
  658. }
  659. }
  660. /**
  661. * <p>Reverses the order of the given array.</p>
  662. *
  663. * <p>This method does nothing if <code>null</code> array input.</p>
  664. *
  665. * @param array the array to reverse, may be <code>null</code>
  666. */
  667. public static void reverse(final short[] array) {
  668. if (array == null) {
  669. return;
  670. }
  671. int i = 0;
  672. int j = array.length - 1;
  673. short tmp;
  674. while (j > i) {
  675. tmp = array[j];
  676. array[j] = array[i];
  677. array[i] = tmp;
  678. j--;
  679. i++;
  680. }
  681. }
  682. /**
  683. * <p>Reverses the order of the given array.</p>
  684. *
  685. * <p>This method does nothing if <code>null</code> array input.</p>
  686. *
  687. * @param array the array to reverse, may be <code>null</code>
  688. */
  689. public static void reverse(final char[] array) {
  690. if (array == null) {
  691. return;
  692. }
  693. int i = 0;
  694. int j = array.length - 1;
  695. char tmp;
  696. while (j > i) {
  697. tmp = array[j];
  698. array[j] = array[i];
  699. array[i] = tmp;
  700. j--;
  701. i++;
  702. }
  703. }
  704. /**
  705. * <p>Reverses the order of the given array.</p>
  706. *
  707. * <p>This method does nothing if <code>null</code> array input.</p>
  708. *
  709. * @param array the array to reverse, may be <code>null</code>
  710. */
  711. public static void reverse(final byte[] array) {
  712. if (array == null) {
  713. return;
  714. }
  715. int i = 0;
  716. int j = array.length - 1;
  717. byte tmp;
  718. while (j > i) {
  719. tmp = array[j];
  720. array[j] = array[i];
  721. array[i] = tmp;
  722. j--;
  723. i++;
  724. }
  725. }
  726. /**
  727. * <p>Reverses the order of the given array.</p>
  728. *
  729. * <p>This method does nothing if <code>null</code> array input.</p>
  730. *
  731. * @param array the array to reverse, may be <code>null</code>
  732. */
  733. public static void reverse(final double[] array) {
  734. if (array == null) {
  735. return;
  736. }
  737. int i = 0;
  738. int j = array.length - 1;
  739. double tmp;
  740. while (j > i) {
  741. tmp = array[j];
  742. array[j] = array[i];
  743. array[i] = tmp;
  744. j--;
  745. i++;
  746. }
  747. }
  748. /**
  749. * <p>Reverses the order of the given array.</p>
  750. *
  751. * <p>This method does nothing if <code>null</code> array input.</p>
  752. *
  753. * @param array the array to reverse, may be <code>null</code>
  754. */
  755. public static void reverse(final float[] array) {
  756. if (array == null) {
  757. return;
  758. }
  759. int i = 0;
  760. int j = array.length - 1;
  761. float tmp;
  762. while (j > i) {
  763. tmp = array[j];
  764. array[j] = array[i];
  765. array[i] = tmp;
  766. j--;
  767. i++;
  768. }
  769. }
  770. /**
  771. * <p>Reverses the order of the given array.</p>
  772. *
  773. * <p>This method does nothing if <code>null</code> array input.</p>
  774. *
  775. * @param array the array to reverse, may be <code>null</code>
  776. */
  777. public static void reverse(final boolean[] array) {
  778. if (array == null) {
  779. return;
  780. }
  781. int i = 0;
  782. int j = array.length - 1;
  783. boolean tmp;
  784. while (j > i) {
  785. tmp = array[j];
  786. array[j] = array[i];
  787. array[i] = tmp;
  788. j--;
  789. i++;
  790. }
  791. }
  792. // IndexOf search
  793. // ----------------------------------------------------------------------
  794. // Object IndexOf
  795. //-----------------------------------------------------------------------
  796. /**
  797. * <p>Find the index of the given object in the array.</p>
  798. *
  799. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  800. *
  801. * @param array the array to search through for the object, may be <code>null</code>
  802. * @param objectToFind the object to find, may be <code>null</code>
  803. * @return the index of the object within the array,
  804. * <code>-1</code> if not found or <code>null</code> array input
  805. */
  806. public static int indexOf(final Object[] array, final Object objectToFind) {
  807. return indexOf(array, objectToFind, 0);
  808. }
  809. /**
  810. * <p>Find the index of the given object in the array starting at the given index.</p>
  811. *
  812. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  813. *
  814. * <p>A negative startIndex is treated as zero. A startIndex larger than the array
  815. * length will return <code>-1</code>.</p>
  816. *
  817. * @param array the array to search through for the object, may be <code>null</code>
  818. * @param objectToFind the object to find, may be <code>null</code>
  819. * @param startIndex the index to start searching at
  820. * @return the index of the object within the array starting at the index,
  821. * <code>-1</code> if not found or <code>null</code> array input
  822. */
  823. public static int indexOf(final Object[] array, final Object objectToFind, int startIndex) {
  824. if (array == null) {
  825. return -1;
  826. }
  827. if (startIndex < 0) {
  828. startIndex = 0;
  829. }
  830. if (objectToFind == null) {
  831. for (int i = startIndex; i < array.length; i++) {
  832. if (array[i] == null) {
  833. return i;
  834. }
  835. }
  836. } else {
  837. for (int i = startIndex; i < array.length; i++) {
  838. if (objectToFind.equals(array[i])) {
  839. return i;
  840. }
  841. }
  842. }
  843. return -1;
  844. }
  845. /**
  846. * <p>Find the last index of the given object within the array.</p>
  847. *
  848. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  849. *
  850. * @param array the array to travers backwords looking for the object, may be <code>null</code>
  851. * @param objectToFind the object to find, may be <code>null</code>
  852. * @return the last index of the object within the array,
  853. * <code>-1</code> if not found or <code>null</code> array input
  854. */
  855. public static int lastIndexOf(final Object[] array, final Object objectToFind) {
  856. return lastIndexOf(array, objectToFind, Integer.MAX_VALUE);
  857. }
  858. /**
  859. * <p>Find the last index of the given object in the array starting at the given index.</p>
  860. *
  861. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  862. *
  863. * <p>A negative startIndex will return <code>-1</code>. A startIndex larger than
  864. * the array length will search from the end of the array.</p>
  865. *
  866. * @param array the array to traverse for looking for the object, may be <code>null</code>
  867. * @param objectToFind the object to find, may be <code>null</code>
  868. * @param startIndex the start index to travers backwards from
  869. * @return the last index of the object within the array,
  870. * <code>-1</code> if not found or <code>null</code> array input
  871. */
  872. public static int lastIndexOf(final Object[] array, final Object objectToFind, int startIndex) {
  873. if (array == null) {
  874. return -1;
  875. }
  876. if (startIndex < 0) {
  877. return -1;
  878. } else if (startIndex >= array.length) {
  879. startIndex = array.length - 1;
  880. }
  881. if (objectToFind == null) {
  882. for (int i = startIndex; i >= 0; i--) {
  883. if (array[i] == null) {
  884. return i;
  885. }
  886. }
  887. } else {
  888. for (int i = startIndex; i >= 0; i--) {
  889. if (objectToFind.equals(array[i])) {
  890. return i;
  891. }
  892. }
  893. }
  894. return -1;
  895. }
  896. /**
  897. * <p>Checks if the object is in the given array.</p>
  898. *
  899. * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
  900. *
  901. * @param array the array to search through
  902. * @param objectToFind the object to find
  903. * @return <code>true</code> if the array contains the object
  904. */
  905. public static boolean contains(final Object[] array, final Object objectToFind) {
  906. return (indexOf(array, objectToFind) != -1);
  907. }
  908. // long IndexOf
  909. //-----------------------------------------------------------------------
  910. /**
  911. * <p>Find the index of the given value in the array.</p>
  912. *
  913. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  914. *
  915. * @param array the array to search through for the object, may be <code>null</code>
  916. * @param valueToFind the value to find
  917. * @return the index of the value within the array,
  918. * <code>-1</code> if not found or <code>null</code> array input
  919. */
  920. public static int indexOf(final long[] array, final long valueToFind) {
  921. return indexOf(array, valueToFind, 0);
  922. }
  923. /**
  924. * <p>Find the index of the given value in the array starting at the given index.</p>
  925. *
  926. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  927. *
  928. * <p>A negative startIndex is treated as zero. A startIndex larger than the array
  929. * length will return -1.</p>
  930. *
  931. * @param array the array to search through for the object, may be <code>null</code>
  932. * @param valueToFind the value to find
  933. * @param startIndex the index to start searching at
  934. * @return the index of the value within the array,
  935. * <code>-1</code> if not found or <code>null</code> array input
  936. */
  937. public static int indexOf(final long[] array, final long valueToFind, int startIndex) {
  938. if (array == null) {
  939. return -1;
  940. }
  941. if (startIndex < 0) {
  942. startIndex = 0;
  943. }
  944. for (int i = startIndex; i < array.length; i++) {
  945. if (valueToFind == array[i]) {
  946. return i;
  947. }
  948. }
  949. return -1;
  950. }
  951. /**
  952. * <p>Find the last index of the given value within the array.</p>
  953. *
  954. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  955. *
  956. * @param array the array to travers backwords looking for the object, may be <code>null</code>
  957. * @param valueToFind the object to find
  958. * @return the last index of the value within the array,
  959. * <code>-1</code> if not found or <code>null</code> array input
  960. */
  961. public static int lastIndexOf(final long[] array, final long valueToFind) {
  962. return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  963. }
  964. /**
  965. * <p>Find the last index of the given value in the array starting at the given index.</p>
  966. *
  967. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  968. *
  969. * <p>A negative startIndex will return -1. A startIndex larger than the array
  970. * length will search from the end of the array.</p>
  971. *
  972. * @param array the array to traverse for looking for the object, may be <code>null</code>
  973. * @param valueToFind the value to find
  974. * @param startIndex the start index to travers backwards from
  975. * @return the last index of the value within the array,
  976. * <code>-1</code> if not found or <code>null</code> array input
  977. */
  978. public static int lastIndexOf(final long[] array, final long valueToFind, int startIndex) {
  979. if (array == null) {
  980. return -1;
  981. }
  982. if (startIndex < 0) {
  983. return -1;
  984. } else if (startIndex >= array.length) {
  985. startIndex = array.length - 1;
  986. }
  987. for (int i = startIndex; i >= 0; i--) {
  988. if (valueToFind == array[i]) {
  989. return i;
  990. }
  991. }
  992. return -1;
  993. }
  994. /**
  995. * <p>Checks if the value is in the given array.</p>
  996. *
  997. * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
  998. *
  999. * @param array the array to search through
  1000. * @param valueToFind the value to find
  1001. * @return <code>true</code> if the array contains the object
  1002. */
  1003. public static boolean contains(final long[] array, final long valueToFind) {
  1004. return (indexOf(array, valueToFind) != -1);
  1005. }
  1006. // int IndexOf
  1007. //-----------------------------------------------------------------------
  1008. /**
  1009. * <p>Find the index of the given value in the array.</p>
  1010. *
  1011. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1012. *
  1013. * @param array the array to search through for the object, may be <code>null</code>
  1014. * @param valueToFind the value to find
  1015. * @return the index of the value within the array,
  1016. * <code>-1</code> if not found or <code>null</code> array input
  1017. */
  1018. public static int indexOf(final int[] array, final int valueToFind) {
  1019. return indexOf(array, valueToFind, 0);
  1020. }
  1021. /**
  1022. * <p>Find the index of the given value in the array starting at the given index.</p>
  1023. *
  1024. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1025. *
  1026. * <p>A negative startIndex is treated as zero. A startIndex larger than the array
  1027. * length will return -1.</p>
  1028. *
  1029. * @param array the array to search through for the object, may be <code>null</code>
  1030. * @param valueToFind the value to find
  1031. * @param startIndex the index to start searching at
  1032. * @return the index of the value within the array,
  1033. * <code>-1</code> if not found or <code>null</code> array input
  1034. */
  1035. public static int indexOf(final int[] array, final int valueToFind, int startIndex) {
  1036. if (array == null) {
  1037. return -1;
  1038. }
  1039. if (startIndex < 0) {
  1040. startIndex = 0;
  1041. }
  1042. for (int i = startIndex; i < array.length; i++) {
  1043. if (valueToFind == array[i]) {
  1044. return i;
  1045. }
  1046. }
  1047. return -1;
  1048. }
  1049. /**
  1050. * <p>Find the last index of the given value within the array.</p>
  1051. *
  1052. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1053. *
  1054. * @param array the array to travers backwords looking for the object, may be <code>null</code>
  1055. * @param valueToFind the object to find
  1056. * @return the last index of the value within the array,
  1057. * <code>-1</code> if not found or <code>null</code> array input
  1058. */
  1059. public static int lastIndexOf(final int[] array, final int valueToFind) {
  1060. return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  1061. }
  1062. /**
  1063. * <p>Find the last index of the given value in the array starting at the given index.</p>
  1064. *
  1065. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1066. *
  1067. * <p>A negative startIndex will return -1. A startIndex larger than the array
  1068. * length will search from the end of the array.</p>
  1069. *
  1070. * @param array the array to traverse for looking for the object, may be <code>null</code>
  1071. * @param valueToFind the value to find
  1072. * @param startIndex the start index to travers backwards from
  1073. * @return the last index of the value within the array,
  1074. * <code>-1</code> if not found or <code>null</code> array input
  1075. */
  1076. public static int lastIndexOf(final int[] array, final int valueToFind, int startIndex) {
  1077. if (array == null) {
  1078. return -1;
  1079. }
  1080. if (startIndex < 0) {
  1081. return -1;
  1082. } else if (startIndex >= array.length) {
  1083. startIndex = array.length - 1;
  1084. }
  1085. for (int i = startIndex; i >= 0; i--) {
  1086. if (valueToFind == array[i]) {
  1087. return i;
  1088. }
  1089. }
  1090. return -1;
  1091. }
  1092. /**
  1093. * <p>Checks if the value is in the given array.</p>
  1094. *
  1095. * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
  1096. *
  1097. * @param array the array to search through
  1098. * @param valueToFind the value to find
  1099. * @return <code>true</code> if the array contains the object
  1100. */
  1101. public static boolean contains(final int[] array, final int valueToFind) {
  1102. return (indexOf(array, valueToFind) != -1);
  1103. }
  1104. // short IndexOf
  1105. //-----------------------------------------------------------------------
  1106. /**
  1107. * <p>Find the index of the given value in the array.</p>
  1108. *
  1109. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1110. *
  1111. * @param array the array to search through for the object, may be <code>null</code>
  1112. * @param valueToFind the value to find
  1113. * @return the index of the value within the array,
  1114. * <code>-1</code> if not found or <code>null</code> array input
  1115. */
  1116. public static int indexOf(final short[] array, final short valueToFind) {
  1117. return indexOf(array, valueToFind, 0);
  1118. }
  1119. /**
  1120. * <p>Find the index of the given value in the array starting at the given index.</p>
  1121. *
  1122. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1123. *
  1124. * <p>A negative startIndex is treated as zero. A startIndex larger than the array
  1125. * length will return -1.</p>
  1126. *
  1127. * @param array the array to search through for the object, may be <code>null</code>
  1128. * @param valueToFind the value to find
  1129. * @param startIndex the index to start searching at
  1130. * @return the index of the value within the array,
  1131. * <code>-1</code> if not found or <code>null</code> array input
  1132. */
  1133. public static int indexOf(final short[] array, final short valueToFind, int startIndex) {
  1134. if (array == null) {
  1135. return -1;
  1136. }
  1137. if (startIndex < 0) {
  1138. startIndex = 0;
  1139. }
  1140. for (int i = startIndex; i < array.length; i++) {
  1141. if (valueToFind == array[i]) {
  1142. return i;
  1143. }
  1144. }
  1145. return -1;
  1146. }
  1147. /**
  1148. * <p>Find the last index of the given value within the array.</p>
  1149. *
  1150. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1151. *
  1152. * @param array the array to travers backwords looking for the object, may be <code>null</code>
  1153. * @param valueToFind the object to find
  1154. * @return the last index of the value within the array,
  1155. * <code>-1</code> if not found or <code>null</code> array input
  1156. */
  1157. public static int lastIndexOf(final short[] array, final short valueToFind) {
  1158. return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  1159. }
  1160. /**
  1161. * <p>Find the last index of the given value in the array starting at the given index.</p>
  1162. *
  1163. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1164. *
  1165. * <p>A negative startIndex will return -1. A startIndex larger than the array
  1166. * length will search from the end of the array.</p>
  1167. *
  1168. * @param array the array to traverse for looking for the object, may be <code>null</code>
  1169. * @param valueToFind the value to find
  1170. * @param startIndex the start index to travers backwards from
  1171. * @return the last index of the value within the array,
  1172. * <code>-1</code> if not found or <code>null</code> array input
  1173. */
  1174. public static int lastIndexOf(final short[] array, final short valueToFind, int startIndex) {
  1175. if (array == null) {
  1176. return -1;
  1177. }
  1178. if (startIndex < 0) {
  1179. return -1;
  1180. } else if (startIndex >= array.length) {
  1181. startIndex = array.length - 1;
  1182. }
  1183. for (int i = startIndex; i >= 0; i--) {
  1184. if (valueToFind == array[i]) {
  1185. return i;
  1186. }
  1187. }
  1188. return -1;
  1189. }
  1190. /**
  1191. * <p>Checks if the value is in the given array.</p>
  1192. *
  1193. * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
  1194. *
  1195. * @param array the array to search through
  1196. * @param valueToFind the value to find
  1197. * @return <code>true</code> if the array contains the object
  1198. */
  1199. public static boolean contains(final short[] array, final short valueToFind) {
  1200. return (indexOf(array, valueToFind) != -1);
  1201. }
  1202. // byte IndexOf
  1203. //-----------------------------------------------------------------------
  1204. /**
  1205. * <p>Find the index of the given value in the array.</p>
  1206. *
  1207. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1208. *
  1209. * @param array the array to search through for the object, may be <code>null</code>
  1210. * @param valueToFind the value to find
  1211. * @return the index of the value within the array,
  1212. * <code>-1</code> if not found or <code>null</code> array input
  1213. */
  1214. public static int indexOf(final byte[] array, final byte valueToFind) {
  1215. return indexOf(array, valueToFind, 0);
  1216. }
  1217. /**
  1218. * <p>Find the index of the given value in the array starting at the given index.</p>
  1219. *
  1220. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1221. *
  1222. * <p>A negative startIndex is treated as zero. A startIndex larger than the array
  1223. * length will return -1.</p>
  1224. *
  1225. * @param array the array to search through for the object, may be <code>null</code>
  1226. * @param valueToFind the value to find
  1227. * @param startIndex the index to start searching at
  1228. * @return the index of the value within the array,
  1229. * <code>-1</code> if not found or <code>null</code> array input
  1230. */
  1231. public static int indexOf(final byte[] array, final byte valueToFind, int startIndex) {
  1232. if (array == null) {
  1233. return -1;
  1234. }
  1235. if (startIndex < 0) {
  1236. startIndex = 0;
  1237. }
  1238. for (int i = startIndex; i < array.length; i++) {
  1239. if (valueToFind == array[i]) {
  1240. return i;
  1241. }
  1242. }
  1243. return -1;
  1244. }
  1245. /**
  1246. * <p>Find the last index of the given value within the array.</p>
  1247. *
  1248. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1249. *
  1250. * @param array the array to travers backwords looking for the object, may be <code>null</code>
  1251. * @param valueToFind the object to find
  1252. * @return the last index of the value within the array,
  1253. * <code>-1</code> if not found or <code>null</code> array input
  1254. */
  1255. public static int lastIndexOf(final byte[] array, final byte valueToFind) {
  1256. return lastIndexOf(array, valueToFind, Integer.MAX_VALUE);
  1257. }
  1258. /**
  1259. * <p>Find the last index of the given value in the array starting at the given index.</p>
  1260. *
  1261. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1262. *
  1263. * <p>A negative startIndex will return -1. A startIndex larger than the array
  1264. * length will search from the end of the array.</p>
  1265. *
  1266. * @param array the array to traverse for looking for the object, may be <code>null</code>
  1267. * @param valueToFind the value to find
  1268. * @param startIndex the start index to travers backwards from
  1269. * @return the last index of the value within the array,
  1270. * <code>-1</code> if not found or <code>null</code> array input
  1271. */
  1272. public static int lastIndexOf(final byte[] array, final byte valueToFind, int startIndex) {
  1273. if (array == null) {
  1274. return -1;
  1275. }
  1276. if (startIndex < 0) {
  1277. return -1;
  1278. } else if (startIndex >= array.length) {
  1279. startIndex = array.length - 1;
  1280. }
  1281. for (int i = startIndex; i >= 0; i--) {
  1282. if (valueToFind == array[i]) {
  1283. return i;
  1284. }
  1285. }
  1286. return -1;
  1287. }
  1288. /**
  1289. * <p>Checks if the value is in the given array.</p>
  1290. *
  1291. * <p>The method returns <code>false</code> if a <code>null</code> array is passed in.</p>
  1292. *
  1293. * @param array the array to search through
  1294. * @param valueToFind the value to find
  1295. * @return <code>true</code> if the array contains the object
  1296. */
  1297. public static boolean contains(final byte[] array, final byte valueToFind) {
  1298. return (indexOf(array, valueToFind) != -1);
  1299. }
  1300. // double IndexOf
  1301. //-----------------------------------------------------------------------
  1302. /**
  1303. * <p>Find the index of the given value in the array.</p>
  1304. *
  1305. * <p>This method returns <code>-1</code> if <code>null</code> array input.</p>
  1306. *
  1307. * @param array the array to search through for the object, may be <code>null</code>
  1308. * @param valueToFind the value to find