KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > ArrayUtilsTest


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang;
17
18 import java.lang.reflect.Constructor JavaDoc;
19 import java.lang.reflect.Modifier JavaDoc;
20 import java.util.Arrays JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import junit.framework.Test;
25 import junit.framework.TestCase;
26 import junit.framework.TestSuite;
27 import junit.textui.TestRunner;
28
29 /**
30  * Unit tests {@link org.apache.commons.lang.ArrayUtils}.
31  *
32  * @author Stephen Colebourne
33  * @author Moritz Petersen
34  * @author Nikolay Metchev
35  * @author Matthew Hawthorne
36  * @author Tim O'Brien
37  * @author <a HREF="mailto:equinus100@hotmail.com">Ashwin S</a>
38  * @author Fredrik Westermarck
39  * @author Gary Gregory
40  * @author Maarten Coene
41  * @version $Id: ArrayUtilsTest.java 161244 2005-04-14 06:16:36Z ggregory $
42  */

43 public class ArrayUtilsTest extends TestCase {
44
45     public ArrayUtilsTest(String JavaDoc name) {
46         super(name);
47     }
48
49     public static void main(String JavaDoc[] args) {
50         TestRunner.run(suite());
51     }
52
53     public static Test suite() {
54         TestSuite suite = new TestSuite(ArrayUtilsTest.class);
55         suite.setName("ArrayUtils Tests");
56         return suite;
57     }
58
59     protected void setUp() throws Exception JavaDoc {
60         super.setUp();
61     }
62
63     protected void tearDown() throws Exception JavaDoc {
64         super.tearDown();
65     }
66
67     //-----------------------------------------------------------------------
68
public void testConstructor() {
69         assertNotNull(new ArrayUtils());
70         Constructor JavaDoc[] cons = ArrayUtils.class.getDeclaredConstructors();
71         assertEquals(1, cons.length);
72         assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
73         assertEquals(true, Modifier.isPublic(ArrayUtils.class.getModifiers()));
74         assertEquals(false, Modifier.isFinal(ArrayUtils.class.getModifiers()));
75     }
76     
77     //-----------------------------------------------------------------------
78
public void testToString() {
79         assertEquals("{}", ArrayUtils.toString(null));
80         assertEquals("{}", ArrayUtils.toString(new Object JavaDoc[0]));
81         assertEquals("{}", ArrayUtils.toString(new String JavaDoc[0]));
82         assertEquals("{<null>}", ArrayUtils.toString(new String JavaDoc[] {null}));
83         assertEquals("{pink,blue}", ArrayUtils.toString(new String JavaDoc[] {"pink","blue"}));
84         
85         assertEquals("<empty>", ArrayUtils.toString(null, "<empty>"));
86         assertEquals("{}", ArrayUtils.toString(new Object JavaDoc[0], "<empty>"));
87         assertEquals("{}", ArrayUtils.toString(new String JavaDoc[0], "<empty>"));
88         assertEquals("{<null>}", ArrayUtils.toString(new String JavaDoc[] {null}, "<empty>"));
89         assertEquals("{pink,blue}", ArrayUtils.toString(new String JavaDoc[] {"pink","blue"}, "<empty>"));
90     }
91
92     //-----------------------------------------------------------------------
93
public void testHashCode() {
94         long[][] array1 = new long[][] {{2,5}, {4,5}};
95         long[][] array2 = new long[][] {{2,5}, {4,6}};
96         assertEquals(true, ArrayUtils.hashCode(array1) == ArrayUtils.hashCode(array1));
97         assertEquals(false, ArrayUtils.hashCode(array1) == ArrayUtils.hashCode(array2));
98         
99         Object JavaDoc[] array3 = new Object JavaDoc[] {new String JavaDoc(new char[] {'A', 'B'})};
100         Object JavaDoc[] array4 = new Object JavaDoc[] {"AB"};
101         assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array3));
102         assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array4));
103     }
104
105     //-----------------------------------------------------------------------
106
private void assertIsEquals(Object JavaDoc array1, Object JavaDoc array2, Object JavaDoc array3) {
107         assertEquals(true, ArrayUtils.isEquals(array1, array1));
108         assertEquals(true, ArrayUtils.isEquals(array2, array2));
109         assertEquals(true, ArrayUtils.isEquals(array3, array3));
110         assertEquals(false, ArrayUtils.isEquals(array1, array2));
111         assertEquals(false, ArrayUtils.isEquals(array2, array1));
112         assertEquals(false, ArrayUtils.isEquals(array1, array3));
113         assertEquals(false, ArrayUtils.isEquals(array3, array1));
114         assertEquals(false, ArrayUtils.isEquals(array1, array2));
115         assertEquals(false, ArrayUtils.isEquals(array2, array1));
116     }
117
118     public void testIsEquals() {
119         long[][] larray1 = new long[][]{{2, 5}, {4, 5}};
120         long[][] larray2 = new long[][]{{2, 5}, {4, 6}};
121         long[] larray3 = new long[]{2, 5};
122         this.assertIsEquals(larray1, larray2, larray3);
123
124         int[][] iarray1 = new int[][]{{2, 5}, {4, 5}};
125         int[][] iarray2 = new int[][]{{2, 5}, {4, 6}};
126         int[] iarray3 = new int[]{2, 5};
127         this.assertIsEquals(iarray1, iarray2, iarray3);
128
129         short[][] sarray1 = new short[][]{{2, 5}, {4, 5}};
130         short[][] sarray2 = new short[][]{{2, 5}, {4, 6}};
131         short[] sarray3 = new short[]{2, 5};
132         this.assertIsEquals(sarray1, sarray2, sarray3);
133
134         float[][] farray1 = new float[][]{{2, 5}, {4, 5}};
135         float[][] farray2 = new float[][]{{2, 5}, {4, 6}};
136         float[] farray3 = new float[]{2, 5};
137         this.assertIsEquals(farray1, farray2, farray3);
138
139         double[][] darray1 = new double[][]{{2, 5}, {4, 5}};
140         double[][] darray2 = new double[][]{{2, 5}, {4, 6}};
141         double[] darray3 = new double[]{2, 5};
142         this.assertIsEquals(darray1, darray2, darray3);
143
144         byte[][] byteArray1 = new byte[][]{{2, 5}, {4, 5}};
145         byte[][] byteArray2 = new byte[][]{{2, 5}, {4, 6}};
146         byte[] byteArray3 = new byte[]{2, 5};
147         this.assertIsEquals(byteArray1, byteArray2, byteArray3);
148
149         char[][] charArray1 = new char[][]{{2, 5}, {4, 5}};
150         char[][] charArray2 = new char[][]{{2, 5}, {4, 6}};
151         char[] charArray3 = new char[]{2, 5};
152         this.assertIsEquals(charArray1, charArray2, charArray3);
153
154         boolean[][] barray1 = new boolean[][]{{true, false}, {true, true}};
155         boolean[][] barray2 = new boolean[][]{{true, false}, {true, false}};
156         boolean[] barray3 = new boolean[]{false, true};
157         this.assertIsEquals(barray1, barray2, barray3);
158
159         Object JavaDoc[] array3 = new Object JavaDoc[]{new String JavaDoc(new char[]{'A', 'B'})};
160         Object JavaDoc[] array4 = new Object JavaDoc[]{"AB"};
161         assertEquals(true, ArrayUtils.isEquals(array3, array3));
162         assertEquals(true, ArrayUtils.isEquals(array3, array4));
163
164         assertEquals(true, ArrayUtils.isEquals(null, null));
165         assertEquals(false, ArrayUtils.isEquals(null, array4));
166     }
167     
168     //-----------------------------------------------------------------------
169
public void testToMap() {
170         Map JavaDoc map = ArrayUtils.toMap(new String JavaDoc[][] {{"foo", "bar"}, {"hello", "world"}});
171         
172         assertEquals("bar", map.get("foo"));
173         assertEquals("world", map.get("hello"));
174         
175         assertEquals(null, ArrayUtils.toMap(null));
176         try {
177             ArrayUtils.toMap(new String JavaDoc[][] {{"foo", "bar"}, {"short"}});
178             fail("exception expected");
179         } catch (IllegalArgumentException JavaDoc ex) {}
180         try {
181             ArrayUtils.toMap(new Object JavaDoc[] {new Object JavaDoc[] {"foo", "bar"}, "illegal type"});
182             fail("exception expected");
183         } catch (IllegalArgumentException JavaDoc ex) {}
184         try {
185             ArrayUtils.toMap(new Object JavaDoc[] {new Object JavaDoc[] {"foo", "bar"}, null});
186             fail("exception expected");
187         } catch (IllegalArgumentException JavaDoc ex) {}
188         
189         map = ArrayUtils.toMap(new Object JavaDoc[] {new Map.Entry JavaDoc() {
190             public Object JavaDoc getKey() {
191                 return "foo";
192             }
193             public Object JavaDoc getValue() {
194                 return "bar";
195             }
196             public Object JavaDoc setValue(Object JavaDoc value) {
197                 throw new UnsupportedOperationException JavaDoc();
198             }
199             public boolean equals(Object JavaDoc o) {
200                 throw new UnsupportedOperationException JavaDoc();
201             }
202             public int hashCode() {
203                 throw new UnsupportedOperationException JavaDoc();
204             }
205         }});
206         assertEquals("bar", map.get("foo"));
207     }
208
209     //-----------------------------------------------------------------------
210
public void testClone() {
211         assertEquals(null, ArrayUtils.clone((Object JavaDoc[]) null));
212         Object JavaDoc[] original1 = new Object JavaDoc[0];
213         Object JavaDoc[] cloned1 = ArrayUtils.clone(original1);
214         assertTrue(Arrays.equals(original1, cloned1));
215         assertTrue(original1 != cloned1);
216         
217         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("pick");
218         original1 = new Object JavaDoc[] {buf, "a", new String JavaDoc[] {"stick"}};
219         cloned1 = ArrayUtils.clone(original1);
220         assertTrue(Arrays.equals(original1, cloned1));
221         assertTrue(original1 != cloned1);
222         assertSame(original1[0], cloned1[0]);
223         assertSame(original1[1], cloned1[1]);
224         assertSame(original1[2], cloned1[2]);
225     }
226
227     public void testCloneBoolean() {
228         assertEquals(null, ArrayUtils.clone((boolean[]) null));
229         boolean[] original = new boolean[] {true, false};
230         boolean[] cloned = ArrayUtils.clone(original);
231         assertTrue(Arrays.equals(original, cloned));
232         assertTrue(original != cloned);
233     }
234     
235     public void testCloneLong() {
236         assertEquals(null, ArrayUtils.clone((long[]) null));
237         long[] original = new long[] {0L, 1L};
238         long[] cloned = ArrayUtils.clone(original);
239         assertTrue(Arrays.equals(original, cloned));
240         assertTrue(original != cloned);
241     }
242     
243     public void testCloneInt() {
244         assertEquals(null, ArrayUtils.clone((int[]) null));
245         int[] original = new int[] {5, 8};
246         int[] cloned = ArrayUtils.clone(original);
247         assertTrue(Arrays.equals(original, cloned));
248         assertTrue(original != cloned);
249     }
250     
251     public void testCloneShort() {
252         assertEquals(null, ArrayUtils.clone((short[]) null));
253         short[] original = new short[] {1, 4};
254         short[] cloned = ArrayUtils.clone(original);
255         assertTrue(Arrays.equals(original, cloned));
256         assertTrue(original != cloned);
257     }
258     
259     public void testCloneChar() {
260         assertEquals(null, ArrayUtils.clone((char[]) null));
261         char[] original = new char[] {'a', '4'};
262         char[] cloned = ArrayUtils.clone(original);
263         assertTrue(Arrays.equals(original, cloned));
264         assertTrue(original != cloned);
265     }
266     
267     public void testCloneByte() {
268         assertEquals(null, ArrayUtils.clone((byte[]) null));
269         byte[] original = new byte[] {1, 6};
270         byte[] cloned = ArrayUtils.clone(original);
271         assertTrue(Arrays.equals(original, cloned));
272         assertTrue(original != cloned);
273     }
274     
275     public void testCloneDouble() {
276         assertEquals(null, ArrayUtils.clone((double[]) null));
277         double[] original = new double[] {2.4d, 5.7d};
278         double[] cloned = ArrayUtils.clone(original);
279         assertTrue(Arrays.equals(original, cloned));
280         assertTrue(original != cloned);
281     }
282     
283     public void testCloneFloat() {
284         assertEquals(null, ArrayUtils.clone((float[]) null));
285         float[] original = new float[] {2.6f, 6.4f};
286         float[] cloned = ArrayUtils.clone(original);
287         assertTrue(Arrays.equals(original, cloned));
288         assertTrue(original != cloned);
289     }
290
291     //-----------------------------------------------------------------------
292

293     public void testSubarrayObject() {
294         Object JavaDoc[] nullArray = null;
295         Object JavaDoc[] objectArray = { "a", "b", "c", "d", "e", "f"};
296
297         assertEquals("0 start, mid end", "abcd",
298             StringUtils.join(ArrayUtils.subarray(objectArray, 0, 4)));
299         assertEquals("0 start, length end", "abcdef",
300             StringUtils.join(ArrayUtils.subarray(objectArray, 0, objectArray.length)));
301         assertEquals("mid start, mid end", "bcd",
302             StringUtils.join(ArrayUtils.subarray(objectArray, 1, 4)));
303         assertEquals("mid start, length end", "bcdef",
304             StringUtils.join(ArrayUtils.subarray(objectArray, 1, objectArray.length)));
305
306         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
307         assertEquals("empty array", "",
308             StringUtils.join(ArrayUtils.subarray(ArrayUtils.EMPTY_OBJECT_ARRAY, 1, 2)));
309         assertEquals("start > end", "",
310             StringUtils.join(ArrayUtils.subarray(objectArray, 4, 2)));
311         assertEquals("start == end", "",
312             StringUtils.join(ArrayUtils.subarray(objectArray, 3, 3)));
313         assertEquals("start undershoot, normal end", "abcd",
314             StringUtils.join(ArrayUtils.subarray(objectArray, -2, 4)));
315         assertEquals("start overshoot, any end", "",
316             StringUtils.join(ArrayUtils.subarray(objectArray, 33, 4)));
317         assertEquals("normal start, end overshoot", "cdef",
318             StringUtils.join(ArrayUtils.subarray(objectArray, 2, 33)));
319         assertEquals("start undershoot, end overshoot", "abcdef",
320             StringUtils.join(ArrayUtils.subarray(objectArray, -2, 12)));
321             
322         // array type tests
323
Date JavaDoc[] dateArray = { new java.sql.Date JavaDoc(new Date JavaDoc().getTime()),
324             new Date JavaDoc(), new Date JavaDoc(), new Date JavaDoc(), new Date JavaDoc() };
325
326         assertSame("Object type", Object JavaDoc.class,
327             ArrayUtils.subarray(objectArray, 2, 4).getClass().getComponentType());
328         assertSame("java.util.Date type", java.util.Date JavaDoc.class,
329             ArrayUtils.subarray(dateArray, 1, 4).getClass().getComponentType());
330         assertNotSame("java.sql.Date type", java.sql.Date JavaDoc.class,
331             ArrayUtils.subarray(dateArray, 1, 4).getClass().getComponentType());
332         try {
333             Object JavaDoc dummy = (java.sql.Date JavaDoc[])ArrayUtils.subarray(dateArray, 1,3);
334             fail("Invalid downcast");
335         } catch (ClassCastException JavaDoc e) {}
336     }
337
338     public void testSubarrayLong() {
339         long[] nullArray = null;
340         long[] array = { 999910, 999911, 999912, 999913, 999914, 999915 };
341         long[] leftSubarray = { 999910, 999911, 999912, 999913 };
342         long[] midSubarray = { 999911, 999912, 999913, 999914 };
343         long[] rightSubarray = { 999912, 999913, 999914, 999915 };
344
345         assertTrue("0 start, mid end",
346             ArrayUtils.isEquals(leftSubarray,
347                 ArrayUtils.subarray(array, 0, 4)));
348
349         assertTrue("0 start, length end",
350             ArrayUtils.isEquals(array,
351                 ArrayUtils.subarray(array, 0, array.length)));
352
353         assertTrue("mid start, mid end",
354             ArrayUtils.isEquals(midSubarray,
355                 ArrayUtils.subarray(array, 1, 5)));
356
357         assertTrue("mid start, length end",
358             ArrayUtils.isEquals(rightSubarray,
359                 ArrayUtils.subarray(array, 2, array.length)));
360
361
362         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
363
364         assertEquals("empty array", ArrayUtils.EMPTY_LONG_ARRAY,
365             ArrayUtils.subarray(ArrayUtils.EMPTY_LONG_ARRAY, 1, 2));
366
367         assertEquals("start > end", ArrayUtils.EMPTY_LONG_ARRAY,
368             ArrayUtils.subarray(array, 4, 2));
369
370         assertEquals("start == end", ArrayUtils.EMPTY_LONG_ARRAY,
371             ArrayUtils.subarray(array, 3, 3));
372
373         assertTrue("start undershoot, normal end",
374             ArrayUtils.isEquals(leftSubarray,
375                 ArrayUtils.subarray(array, -2, 4)));
376
377         assertEquals("start overshoot, any end",
378             ArrayUtils.EMPTY_LONG_ARRAY,
379                 ArrayUtils.subarray(array, 33, 4));
380
381         assertTrue("normal start, end overshoot",
382             ArrayUtils.isEquals(rightSubarray,
383                 ArrayUtils.subarray(array, 2, 33)));
384
385         assertTrue("start undershoot, end overshoot",
386             ArrayUtils.isEquals(array,
387                 ArrayUtils.subarray(array, -2, 12)));
388
389         // empty-return tests
390

391         assertSame("empty array, object test",
392             ArrayUtils.EMPTY_LONG_ARRAY,
393                 ArrayUtils.subarray(ArrayUtils.EMPTY_LONG_ARRAY, 1, 2));
394
395         assertSame("start > end, object test",
396             ArrayUtils.EMPTY_LONG_ARRAY,
397                 ArrayUtils.subarray(array, 4, 1));
398
399         assertSame("start == end, object test",
400             ArrayUtils.EMPTY_LONG_ARRAY,
401                 ArrayUtils.subarray(array, 3, 3));
402
403         assertSame("start overshoot, any end, object test",
404             ArrayUtils.EMPTY_LONG_ARRAY,
405                 ArrayUtils.subarray(array, 8733, 4));
406
407         // array type tests
408

409         assertSame("long type", long.class,
410             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
411
412     }
413
414     public void testSubarrayInt() {
415         int[] nullArray = null;
416         int[] array = { 10, 11, 12, 13, 14, 15 };
417         int[] leftSubarray = { 10, 11, 12, 13 };
418         int[] midSubarray = { 11, 12, 13, 14 };
419         int[] rightSubarray = { 12, 13, 14, 15 };
420
421
422         assertTrue("0 start, mid end",
423             ArrayUtils.isEquals(leftSubarray,
424                 ArrayUtils.subarray(array, 0, 4)));
425
426         assertTrue("0 start, length end",
427             ArrayUtils.isEquals(array,
428                 ArrayUtils.subarray(array, 0, array.length)));
429
430         assertTrue("mid start, mid end",
431             ArrayUtils.isEquals(midSubarray,
432                 ArrayUtils.subarray(array, 1, 5)));
433
434         assertTrue("mid start, length end",
435             ArrayUtils.isEquals(rightSubarray,
436                 ArrayUtils.subarray(array, 2, array.length)));
437
438
439         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
440
441         assertEquals("empty array", ArrayUtils.EMPTY_INT_ARRAY,
442             ArrayUtils.subarray(ArrayUtils.EMPTY_INT_ARRAY, 1, 2));
443
444         assertEquals("start > end", ArrayUtils.EMPTY_INT_ARRAY,
445             ArrayUtils.subarray(array, 4, 2));
446
447         assertEquals("start == end", ArrayUtils.EMPTY_INT_ARRAY,
448             ArrayUtils.subarray(array, 3, 3));
449
450         assertTrue("start undershoot, normal end",
451             ArrayUtils.isEquals(leftSubarray,
452                 ArrayUtils.subarray(array, -2, 4)));
453
454         assertEquals("start overshoot, any end",
455             ArrayUtils.EMPTY_INT_ARRAY,
456                 ArrayUtils.subarray(array, 33, 4));
457
458         assertTrue("normal start, end overshoot",
459             ArrayUtils.isEquals(rightSubarray,
460                 ArrayUtils.subarray(array, 2, 33)));
461
462         assertTrue("start undershoot, end overshoot",
463             ArrayUtils.isEquals(array,
464                 ArrayUtils.subarray(array, -2, 12)));
465
466         // empty-return tests
467

468         assertSame("empty array, object test",
469             ArrayUtils.EMPTY_INT_ARRAY,
470                 ArrayUtils.subarray(ArrayUtils.EMPTY_INT_ARRAY, 1, 2));
471
472         assertSame("start > end, object test",
473             ArrayUtils.EMPTY_INT_ARRAY,
474                 ArrayUtils.subarray(array, 4, 1));
475
476         assertSame("start == end, object test",
477             ArrayUtils.EMPTY_INT_ARRAY,
478                 ArrayUtils.subarray(array, 3, 3));
479
480         assertSame("start overshoot, any end, object test",
481             ArrayUtils.EMPTY_INT_ARRAY,
482                 ArrayUtils.subarray(array, 8733, 4));
483
484         // array type tests
485

486         assertSame("int type", int.class,
487             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
488
489     }
490
491     public void testSubarrayShort() {
492         short[] nullArray = null;
493         short[] array = { 10, 11, 12, 13, 14, 15 };
494         short[] leftSubarray = { 10, 11, 12, 13 };
495         short[] midSubarray = { 11, 12, 13, 14 };
496         short[] rightSubarray = { 12, 13, 14, 15 };
497
498
499         assertTrue("0 start, mid end",
500             ArrayUtils.isEquals(leftSubarray,
501                 ArrayUtils.subarray(array, 0, 4)));
502
503         assertTrue("0 start, length end",
504             ArrayUtils.isEquals(array,
505                 ArrayUtils.subarray(array, 0, array.length)));
506
507         assertTrue("mid start, mid end",
508             ArrayUtils.isEquals(midSubarray,
509                 ArrayUtils.subarray(array, 1, 5)));
510
511         assertTrue("mid start, length end",
512             ArrayUtils.isEquals(rightSubarray,
513                 ArrayUtils.subarray(array, 2, array.length)));
514
515
516         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
517
518         assertEquals("empty array", ArrayUtils.EMPTY_SHORT_ARRAY,
519             ArrayUtils.subarray(ArrayUtils.EMPTY_SHORT_ARRAY, 1, 2));
520
521         assertEquals("start > end", ArrayUtils.EMPTY_SHORT_ARRAY,
522             ArrayUtils.subarray(array, 4, 2));
523
524         assertEquals("start == end", ArrayUtils.EMPTY_SHORT_ARRAY,
525             ArrayUtils.subarray(array, 3, 3));
526
527         assertTrue("start undershoot, normal end",
528             ArrayUtils.isEquals(leftSubarray,
529                 ArrayUtils.subarray(array, -2, 4)));
530
531         assertEquals("start overshoot, any end",
532             ArrayUtils.EMPTY_SHORT_ARRAY,
533                 ArrayUtils.subarray(array, 33, 4));
534
535         assertTrue("normal start, end overshoot",
536             ArrayUtils.isEquals(rightSubarray,
537                 ArrayUtils.subarray(array, 2, 33)));
538
539         assertTrue("start undershoot, end overshoot",
540             ArrayUtils.isEquals(array,
541                 ArrayUtils.subarray(array, -2, 12)));
542
543         // empty-return tests
544

545         assertSame("empty array, object test",
546             ArrayUtils.EMPTY_SHORT_ARRAY,
547                 ArrayUtils.subarray(ArrayUtils.EMPTY_SHORT_ARRAY, 1, 2));
548
549         assertSame("start > end, object test",
550             ArrayUtils.EMPTY_SHORT_ARRAY,
551                 ArrayUtils.subarray(array, 4, 1));
552
553         assertSame("start == end, object test",
554             ArrayUtils.EMPTY_SHORT_ARRAY,
555                 ArrayUtils.subarray(array, 3, 3));
556
557         assertSame("start overshoot, any end, object test",
558             ArrayUtils.EMPTY_SHORT_ARRAY,
559                 ArrayUtils.subarray(array, 8733, 4));
560
561         // array type tests
562

563         assertSame("short type", short.class,
564             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
565
566     }
567
568     public void testSubarrChar() {
569         char[] nullArray = null;
570         char[] array = { 'a', 'b', 'c', 'd', 'e', 'f' };
571         char[] leftSubarray = { 'a', 'b', 'c', 'd', };
572         char[] midSubarray = { 'b', 'c', 'd', 'e', };
573         char[] rightSubarray = { 'c', 'd', 'e', 'f', };
574
575
576         assertTrue("0 start, mid end",
577             ArrayUtils.isEquals(leftSubarray,
578                 ArrayUtils.subarray(array, 0, 4)));
579
580         assertTrue("0 start, length end",
581             ArrayUtils.isEquals(array,
582                 ArrayUtils.subarray(array, 0, array.length)));
583
584         assertTrue("mid start, mid end",
585             ArrayUtils.isEquals(midSubarray,
586                 ArrayUtils.subarray(array, 1, 5)));
587
588         assertTrue("mid start, length end",
589             ArrayUtils.isEquals(rightSubarray,
590                 ArrayUtils.subarray(array, 2, array.length)));
591
592
593         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
594
595         assertEquals("empty array", ArrayUtils.EMPTY_CHAR_ARRAY,
596             ArrayUtils.subarray(ArrayUtils.EMPTY_CHAR_ARRAY, 1, 2));
597
598         assertEquals("start > end", ArrayUtils.EMPTY_CHAR_ARRAY,
599             ArrayUtils.subarray(array, 4, 2));
600
601         assertEquals("start == end", ArrayUtils.EMPTY_CHAR_ARRAY,
602             ArrayUtils.subarray(array, 3, 3));
603
604         assertTrue("start undershoot, normal end",
605             ArrayUtils.isEquals(leftSubarray,
606                 ArrayUtils.subarray(array, -2, 4)));
607
608         assertEquals("start overshoot, any end",
609             ArrayUtils.EMPTY_CHAR_ARRAY,
610                 ArrayUtils.subarray(array, 33, 4));
611
612         assertTrue("normal start, end overshoot",
613             ArrayUtils.isEquals(rightSubarray,
614                 ArrayUtils.subarray(array, 2, 33)));
615
616         assertTrue("start undershoot, end overshoot",
617             ArrayUtils.isEquals(array,
618                 ArrayUtils.subarray(array, -2, 12)));
619
620         // empty-return tests
621

622         assertSame("empty array, object test",
623             ArrayUtils.EMPTY_CHAR_ARRAY,
624                 ArrayUtils.subarray(ArrayUtils.EMPTY_CHAR_ARRAY, 1, 2));
625
626         assertSame("start > end, object test",
627             ArrayUtils.EMPTY_CHAR_ARRAY,
628                 ArrayUtils.subarray(array, 4, 1));
629
630         assertSame("start == end, object test",
631             ArrayUtils.EMPTY_CHAR_ARRAY,
632                 ArrayUtils.subarray(array, 3, 3));
633
634         assertSame("start overshoot, any end, object test",
635             ArrayUtils.EMPTY_CHAR_ARRAY,
636                 ArrayUtils.subarray(array, 8733, 4));
637
638         // array type tests
639

640         assertSame("char type", char.class,
641             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
642
643     }
644
645     public void testSubarrayByte() {
646         byte[] nullArray = null;
647         byte[] array = { 10, 11, 12, 13, 14, 15 };
648         byte[] leftSubarray = { 10, 11, 12, 13 };
649         byte[] midSubarray = { 11, 12, 13, 14 };
650         byte[] rightSubarray = { 12, 13, 14, 15 };
651
652
653         assertTrue("0 start, mid end",
654             ArrayUtils.isEquals(leftSubarray,
655                 ArrayUtils.subarray(array, 0, 4)));
656
657         assertTrue("0 start, length end",
658             ArrayUtils.isEquals(array,
659                 ArrayUtils.subarray(array, 0, array.length)));
660
661         assertTrue("mid start, mid end",
662             ArrayUtils.isEquals(midSubarray,
663                 ArrayUtils.subarray(array, 1, 5)));
664
665         assertTrue("mid start, length end",
666             ArrayUtils.isEquals(rightSubarray,
667                 ArrayUtils.subarray(array, 2, array.length)));
668
669
670         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
671
672         assertEquals("empty array", ArrayUtils.EMPTY_BYTE_ARRAY,
673             ArrayUtils.subarray(ArrayUtils.EMPTY_BYTE_ARRAY, 1, 2));
674
675         assertEquals("start > end", ArrayUtils.EMPTY_BYTE_ARRAY,
676             ArrayUtils.subarray(array, 4, 2));
677
678         assertEquals("start == end", ArrayUtils.EMPTY_BYTE_ARRAY,
679             ArrayUtils.subarray(array, 3, 3));
680
681         assertTrue("start undershoot, normal end",
682             ArrayUtils.isEquals(leftSubarray,
683                 ArrayUtils.subarray(array, -2, 4)));
684
685         assertEquals("start overshoot, any end",
686             ArrayUtils.EMPTY_BYTE_ARRAY,
687                 ArrayUtils.subarray(array, 33, 4));
688
689         assertTrue("normal start, end overshoot",
690             ArrayUtils.isEquals(rightSubarray,
691                 ArrayUtils.subarray(array, 2, 33)));
692
693         assertTrue("start undershoot, end overshoot",
694             ArrayUtils.isEquals(array,
695                 ArrayUtils.subarray(array, -2, 12)));
696
697         // empty-return tests
698

699         assertSame("empty array, object test",
700             ArrayUtils.EMPTY_BYTE_ARRAY,
701                 ArrayUtils.subarray(ArrayUtils.EMPTY_BYTE_ARRAY, 1, 2));
702
703         assertSame("start > end, object test",
704             ArrayUtils.EMPTY_BYTE_ARRAY,
705                 ArrayUtils.subarray(array, 4, 1));
706
707         assertSame("start == end, object test",
708             ArrayUtils.EMPTY_BYTE_ARRAY,
709                 ArrayUtils.subarray(array, 3, 3));
710
711         assertSame("start overshoot, any end, object test",
712             ArrayUtils.EMPTY_BYTE_ARRAY,
713                 ArrayUtils.subarray(array, 8733, 4));
714
715         // array type tests
716

717         assertSame("byte type", byte.class,
718             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
719
720     }
721
722     public void testSubarrayDouble() {
723         double[] nullArray = null;
724         double[] array = { 10.123, 11.234, 12.345, 13.456, 14.567, 15.678 };
725         double[] leftSubarray = { 10.123, 11.234, 12.345, 13.456, };
726         double[] midSubarray = { 11.234, 12.345, 13.456, 14.567, };
727         double[] rightSubarray = { 12.345, 13.456, 14.567, 15.678 };
728
729
730         assertTrue("0 start, mid end",
731             ArrayUtils.isEquals(leftSubarray,
732                 ArrayUtils.subarray(array, 0, 4)));
733
734         assertTrue("0 start, length end",
735             ArrayUtils.isEquals(array,
736                 ArrayUtils.subarray(array, 0, array.length)));
737
738         assertTrue("mid start, mid end",
739             ArrayUtils.isEquals(midSubarray,
740                 ArrayUtils.subarray(array, 1, 5)));
741
742         assertTrue("mid start, length end",
743             ArrayUtils.isEquals(rightSubarray,
744                 ArrayUtils.subarray(array, 2, array.length)));
745
746
747         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
748
749         assertEquals("empty array", ArrayUtils.EMPTY_DOUBLE_ARRAY,
750             ArrayUtils.subarray(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2));
751
752         assertEquals("start > end", ArrayUtils.EMPTY_DOUBLE_ARRAY,
753             ArrayUtils.subarray(array, 4, 2));
754
755         assertEquals("start == end", ArrayUtils.EMPTY_DOUBLE_ARRAY,
756             ArrayUtils.subarray(array, 3, 3));
757
758         assertTrue("start undershoot, normal end",
759             ArrayUtils.isEquals(leftSubarray,
760                 ArrayUtils.subarray(array, -2, 4)));
761
762         assertEquals("start overshoot, any end",
763             ArrayUtils.EMPTY_DOUBLE_ARRAY,
764                 ArrayUtils.subarray(array, 33, 4));
765
766         assertTrue("normal start, end overshoot",
767             ArrayUtils.isEquals(rightSubarray,
768                 ArrayUtils.subarray(array, 2, 33)));
769
770         assertTrue("start undershoot, end overshoot",
771             ArrayUtils.isEquals(array,
772                 ArrayUtils.subarray(array, -2, 12)));
773
774         // empty-return tests
775

776         assertSame("empty array, object test",
777             ArrayUtils.EMPTY_DOUBLE_ARRAY,
778                 ArrayUtils.subarray(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2));
779
780         assertSame("start > end, object test",
781             ArrayUtils.EMPTY_DOUBLE_ARRAY,
782                 ArrayUtils.subarray(array, 4, 1));
783
784         assertSame("start == end, object test",
785             ArrayUtils.EMPTY_DOUBLE_ARRAY,
786                 ArrayUtils.subarray(array, 3, 3));
787
788         assertSame("start overshoot, any end, object test",
789             ArrayUtils.EMPTY_DOUBLE_ARRAY,
790                 ArrayUtils.subarray(array, 8733, 4));
791
792         // array type tests
793

794         assertSame("double type", double.class,
795             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
796
797     }
798
799     public void testSubarrayFloat() {
800         float[] nullArray = null;
801         float[] array = { 10, 11, 12, 13, 14, 15 };
802         float[] leftSubarray = { 10, 11, 12, 13 };
803         float[] midSubarray = { 11, 12, 13, 14 };
804         float[] rightSubarray = { 12, 13, 14, 15 };
805
806
807         assertTrue("0 start, mid end",
808             ArrayUtils.isEquals(leftSubarray,
809                 ArrayUtils.subarray(array, 0, 4)));
810
811         assertTrue("0 start, length end",
812             ArrayUtils.isEquals(array,
813                 ArrayUtils.subarray(array, 0, array.length)));
814
815         assertTrue("mid start, mid end",
816             ArrayUtils.isEquals(midSubarray,
817                 ArrayUtils.subarray(array, 1, 5)));
818
819         assertTrue("mid start, length end",
820             ArrayUtils.isEquals(rightSubarray,
821                 ArrayUtils.subarray(array, 2, array.length)));
822
823
824         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
825
826         assertEquals("empty array", ArrayUtils.EMPTY_FLOAT_ARRAY,
827             ArrayUtils.subarray(ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 2));
828
829         assertEquals("start > end", ArrayUtils.EMPTY_FLOAT_ARRAY,
830             ArrayUtils.subarray(array, 4, 2));
831
832         assertEquals("start == end", ArrayUtils.EMPTY_FLOAT_ARRAY,
833             ArrayUtils.subarray(array, 3, 3));
834
835         assertTrue("start undershoot, normal end",
836             ArrayUtils.isEquals(leftSubarray,
837                 ArrayUtils.subarray(array, -2, 4)));
838
839         assertEquals("start overshoot, any end",
840             ArrayUtils.EMPTY_FLOAT_ARRAY,
841                 ArrayUtils.subarray(array, 33, 4));
842
843         assertTrue("normal start, end overshoot",
844             ArrayUtils.isEquals(rightSubarray,
845                 ArrayUtils.subarray(array, 2, 33)));
846
847         assertTrue("start undershoot, end overshoot",
848             ArrayUtils.isEquals(array,
849                 ArrayUtils.subarray(array, -2, 12)));
850
851         // empty-return tests
852

853         assertSame("empty array, object test",
854             ArrayUtils.EMPTY_FLOAT_ARRAY,
855                 ArrayUtils.subarray(ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 2));
856
857         assertSame("start > end, object test",
858             ArrayUtils.EMPTY_FLOAT_ARRAY,
859                 ArrayUtils.subarray(array, 4, 1));
860
861         assertSame("start == end, object test",
862             ArrayUtils.EMPTY_FLOAT_ARRAY,
863                 ArrayUtils.subarray(array, 3, 3));
864
865         assertSame("start overshoot, any end, object test",
866             ArrayUtils.EMPTY_FLOAT_ARRAY,
867                 ArrayUtils.subarray(array, 8733, 4));
868
869         // array type tests
870

871         assertSame("float type", float.class,
872             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
873
874     }
875
876     public void testSubarrayBoolean() {
877         boolean[] nullArray = null;
878         boolean[] array = { true, true, false, true, false, true };
879         boolean[] leftSubarray = { true, true, false, true };
880         boolean[] midSubarray = { true, false, true, false };
881         boolean[] rightSubarray = { false, true, false, true };
882
883
884         assertTrue("0 start, mid end",
885             ArrayUtils.isEquals(leftSubarray,
886                 ArrayUtils.subarray(array, 0, 4)));
887
888         assertTrue("0 start, length end",
889             ArrayUtils.isEquals(array,
890                 ArrayUtils.subarray(array, 0, array.length)));
891
892         assertTrue("mid start, mid end",
893             ArrayUtils.isEquals(midSubarray,
894                 ArrayUtils.subarray(array, 1, 5)));
895
896         assertTrue("mid start, length end",
897             ArrayUtils.isEquals(rightSubarray,
898                 ArrayUtils.subarray(array, 2, array.length)));
899
900
901         assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
902
903         assertEquals("empty array", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
904             ArrayUtils.subarray(ArrayUtils.EMPTY_BOOLEAN_ARRAY, 1, 2));
905
906         assertEquals("start > end", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
907             ArrayUtils.subarray(array, 4, 2));
908
909         assertEquals("start == end", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
910             ArrayUtils.subarray(array, 3, 3));
911
912         assertTrue("start undershoot, normal end",
913             ArrayUtils.isEquals(leftSubarray,
914                 ArrayUtils.subarray(array, -2, 4)));
915
916         assertEquals("start overshoot, any end",
917             ArrayUtils.EMPTY_BOOLEAN_ARRAY,
918                 ArrayUtils.subarray(array, 33, 4));
919
920         assertTrue("normal start, end overshoot",
921             ArrayUtils.isEquals(rightSubarray,
922                 ArrayUtils.subarray(array, 2, 33)));
923
924         assertTrue("start undershoot, end overshoot",
925             ArrayUtils.isEquals(array,
926                 ArrayUtils.subarray(array, -2, 12)));
927
928         // empty-return tests
929

930         assertSame("empty array, object test",
931             ArrayUtils.EMPTY_BOOLEAN_ARRAY,
932                 ArrayUtils.subarray(ArrayUtils.EMPTY_BOOLEAN_ARRAY, 1, 2));
933
934         assertSame("start > end, object test",
935             ArrayUtils.EMPTY_BOOLEAN_ARRAY,
936                 ArrayUtils.subarray(array, 4, 1));
937
938         assertSame("start == end, object test",
939             ArrayUtils.EMPTY_BOOLEAN_ARRAY,
940                 ArrayUtils.subarray(array, 3, 3));
941
942         assertSame("start overshoot, any end, object test",
943             ArrayUtils.EMPTY_BOOLEAN_ARRAY,
944                 ArrayUtils.subarray(array, 8733, 4));
945
946         // array type tests
947

948         assertSame("boolean type", boolean.class,
949             ArrayUtils.subarray(array, 2, 4).getClass().getComponentType());
950
951     }
952     
953     //-----------------------------------------------------------------------
954
public void testSameLength() {
955         Object JavaDoc[] nullArray = null;
956         Object JavaDoc[] emptyArray = new Object JavaDoc[0];
957         Object JavaDoc[] oneArray = new Object JavaDoc[] {"pick"};
958         Object JavaDoc[] twoArray = new Object JavaDoc[] {"pick", "stick"};
959         
960         assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
961         assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
962         assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
963         assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
964         
965         assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
966         assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
967         assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
968         assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
969         
970         assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
971         assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
972         assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
973         assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
974         
975         assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
976         assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
977         assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
978         assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
979     }
980
981     public void testSameLengthBoolean() {
982         boolean[] nullArray = null;
983         boolean[] emptyArray = new boolean[0];
984         boolean[] oneArray = new boolean[] {true};
985         boolean[] twoArray = new boolean[] {true, false};
986         
987         assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
988         assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
989         assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
990         assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
991         
992         assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
993         assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
994         assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
995         assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
996         
997         assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
998         assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
999         assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1000        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1001        
1002        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1003        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1004        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1005        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1006    }
1007    
1008    public void testSameLengthLong() {
1009        long[] nullArray = null;
1010        long[] emptyArray = new long[0];
1011        long[] oneArray = new long[] {0L};
1012        long[] twoArray = new long[] {0L, 76L};
1013        
1014        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1015        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1016        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1017        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1018        
1019        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1020        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1021        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1022        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1023        
1024        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1025        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1026        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1027        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1028        
1029        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1030        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1031        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1032        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1033    }
1034    
1035    public void testSameLengthInt() {
1036        int[] nullArray = null;
1037        int[] emptyArray = new int[0];
1038        int[] oneArray = new int[] {4};
1039        int[] twoArray = new int[] {5, 7};
1040        
1041        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1042        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1043        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1044        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1045        
1046        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1047        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1048        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1049        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1050        
1051        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1052        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1053        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1054        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1055        
1056        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1057        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1058        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1059        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1060    }
1061    
1062    public void testSameLengthShort() {
1063        short[] nullArray = null;
1064        short[] emptyArray = new short[0];
1065        short[] oneArray = new short[] {4};
1066        short[] twoArray = new short[] {6, 8};
1067        
1068        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1069        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1070        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1071        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1072        
1073        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1074        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1075        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1076        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1077        
1078        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1079        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1080        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1081        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1082        
1083        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1084        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1085        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1086        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1087    }
1088    
1089    public void testSameLengthChar() {
1090        char[] nullArray = null;
1091        char[] emptyArray = new char[0];
1092        char[] oneArray = new char[] {'f'};
1093        char[] twoArray = new char[] {'d', 't'};
1094        
1095        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1096        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1097        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1098        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1099        
1100        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1101        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1102        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1103        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1104        
1105        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1106        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1107        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1108        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1109        
1110        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1111        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1112        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1113        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1114    }
1115    
1116    public void testSameLengthByte() {
1117        byte[] nullArray = null;
1118        byte[] emptyArray = new byte[0];
1119        byte[] oneArray = new byte[] {3};
1120        byte[] twoArray = new byte[] {4, 6};
1121        
1122        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1123        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1124        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1125        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1126        
1127        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1128        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1129        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1130        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1131        
1132        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1133        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1134        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1135        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1136        
1137        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1138        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1139        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1140        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1141    }
1142    
1143    public void testSameLengthDouble() {
1144        double[] nullArray = null;
1145        double[] emptyArray = new double[0];
1146        double[] oneArray = new double[] {1.3d};
1147        double[] twoArray = new double[] {4.5d, 6.3d};
1148        
1149        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1150        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1151        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1152        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1153        
1154        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1155        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1156        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1157        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1158        
1159        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1160        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1161        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1162        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1163        
1164        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1165        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1166        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1167        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1168    }
1169    
1170    public void testSameLengthFloat() {
1171        float[] nullArray = null;
1172        float[] emptyArray = new float[0];
1173        float[] oneArray = new float[] {2.5f};
1174        float[] twoArray = new float[] {6.4f, 5.8f};
1175        
1176        assertEquals(true, ArrayUtils.isSameLength(nullArray, nullArray));
1177        assertEquals(true, ArrayUtils.isSameLength(nullArray, emptyArray));
1178        assertEquals(false, ArrayUtils.isSameLength(nullArray, oneArray));
1179        assertEquals(false, ArrayUtils.isSameLength(nullArray, twoArray));
1180        
1181        assertEquals(true, ArrayUtils.isSameLength(emptyArray, nullArray));
1182        assertEquals(true, ArrayUtils.isSameLength(emptyArray, emptyArray));
1183        assertEquals(false, ArrayUtils.isSameLength(emptyArray, oneArray));
1184        assertEquals(false, ArrayUtils.isSameLength(emptyArray, twoArray));
1185        
1186        assertEquals(false, ArrayUtils.isSameLength(oneArray, nullArray));
1187        assertEquals(false, ArrayUtils.isSameLength(oneArray, emptyArray));
1188        assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1189        assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1190        
1191        assertEquals(false, ArrayUtils.isSameLength(twoArray, nullArray));
1192        assertEquals(false, ArrayUtils.isSameLength(twoArray, emptyArray));
1193        assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1194        assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1195    }
1196    
1197    //-----------------------------------------------------------------------
1198
public void testSameType() {
1199        try {
1200            ArrayUtils.isSameType(null, null);
1201            fail();
1202        } catch (IllegalArgumentException JavaDoc ex) {}
1203        try {
1204            ArrayUtils.isSameType(null, new Object JavaDoc[0]);
1205            fail();
1206        } catch (IllegalArgumentException JavaDoc ex) {}
1207        try {
1208            ArrayUtils.isSameType(new Object JavaDoc[0], null);
1209            fail();
1210        } catch (IllegalArgumentException JavaDoc ex) {}
1211        
1212        assertEquals(true, ArrayUtils.isSameType(new Object JavaDoc[0], new Object JavaDoc[0]));
1213        assertEquals(false, ArrayUtils.isSameType(new String JavaDoc[0], new Object JavaDoc[0]));
1214        assertEquals(true, ArrayUtils.isSameType(new String JavaDoc[0][0], new String JavaDoc[0][0]));
1215        assertEquals(false, ArrayUtils.isSameType(new String JavaDoc[0], new String JavaDoc[0][0]));
1216        assertEquals(false, ArrayUtils.isSameType(new String JavaDoc[0][0], new String JavaDoc[0]));
1217    }
1218    
1219    //-----------------------------------------------------------------------
1220
public void testReverse() {
1221        StringBuffer JavaDoc str1 = new StringBuffer JavaDoc("pick");
1222        String JavaDoc str2 = "a";
1223        String JavaDoc[] str3 = new String JavaDoc[] {"stick"};
1224        String JavaDoc str4 = "up";
1225        
1226        Object JavaDoc[] array = new Object JavaDoc[] {str1, str2, str3};
1227        ArrayUtils.reverse(array);
1228        assertEquals(array[0], str3);
1229        assertEquals(array[1], str2);
1230        assertEquals(array[2], str1);
1231        
1232        array = new Object JavaDoc[] {str1, str2, str3, str4};
1233        ArrayUtils.reverse(array);
1234        assertEquals(array[0], str4);
1235        assertEquals(array[1], str3);
1236        assertEquals(array[2], str2);
1237        assertEquals(array[3], str1);
1238
1239        array = null;
1240        ArrayUtils.reverse(array);
1241        assertEquals(null, array);
1242    }
1243
1244    public void testReverseLong() {
1245        long[] array = new long[] {1L, 2L, 3L};
1246        ArrayUtils.reverse(array);
1247        assertEquals(array[0], 3L);
1248        assertEquals(array[1], 2L);
1249        assertEquals(array[2], 1L);
1250
1251        array = null;
1252        ArrayUtils.reverse(array);
1253        assertEquals(null, array);
1254    }
1255    
1256    public void testReverseInt() {
1257        int[] array = new int[] {1, 2, 3};
1258        ArrayUtils.reverse(array);
1259        assertEquals(array[0], 3);
1260        assertEquals(array[1], 2);
1261        assertEquals(array[2], 1);
1262
1263        array = null;
1264        ArrayUtils.reverse(array);
1265        assertEquals(null, array);
1266    }
1267    
1268    public void testReverseShort() {
1269        short[] array = new short[] {1, 2, 3};
1270        ArrayUtils.reverse(array);
1271        assertEquals(array[0], 3);
1272        assertEquals(array[1], 2);
1273        assertEquals(array[2], 1);
1274
1275        array = null;
1276        ArrayUtils.reverse(array);
1277        assertEquals(null, array);
1278    }
1279    
1280    public void testReverseChar() {
1281        char[] array = new char[] {'a', 'f', 'C'};
1282        ArrayUtils.reverse(array);
1283        assertEquals(array[0], 'C');
1284        assertEquals(array[1], 'f');
1285        assertEquals(array[2], 'a');
1286
1287        array = null;
1288        ArrayUtils.reverse(array);
1289        assertEquals(null, array);
1290    }
1291    
1292    public void testReverseByte() {
1293        byte[] array = new byte[] {2, 3, 4};
1294        ArrayUtils.reverse(array);
1295        assertEquals(array[0], 4);
1296        assertEquals(array[1], 3);
1297        assertEquals(array[2], 2);
1298
1299        array = null;
1300        ArrayUtils.reverse(array);
1301        assertEquals(null, array);
1302    }
1303    
1304    public void testReverseDouble() {
1305        double[] array = new double[] {0.3d, 0.4d, 0.5d};
1306        ArrayUtils.reverse(array);
1307        assertEquals(array[0], 0.5d, 0.0d);
1308        assertEquals(array[1], 0.4d, 0.0d);
1309        assertEquals(array[2], 0.3d, 0.0d);
1310
1311        array = null;
1312        ArrayUtils.reverse(array);
1313        assertEquals(null, array);
1314    }
1315    
1316    public void testReverseFloat() {
1317        float[] array = new float[] {0.3f, 0.4f, 0.5f};
1318        ArrayUtils.reverse(array);
1319        assertEquals(array[0], 0.5f, 0.0f);
1320        assertEquals(array[1], 0.4f, 0.0f);
1321        assertEquals(array[2], 0.3f, 0.0f);
1322
1323        array = null;
1324        ArrayUtils.reverse(array);
1325        assertEquals(null, array);
1326    }
1327    
1328    public void testReverseBoolean() {
1329        boolean[] array = new boolean[] {false, false, true};
1330        ArrayUtils.reverse(array);
1331        assertEquals(array[0], true);
1332        assertEquals(array[1], false);
1333        assertEquals(array[2], false);
1334
1335        array = null;
1336        ArrayUtils.reverse(array);
1337        assertEquals(null, array);
1338    }
1339    
1340    //-----------------------------------------------------------------------
1341
public void testIndexOf() {
1342        Object JavaDoc[] array = new Object JavaDoc[] { "0", "1", "2", "3", null, "0" };
1343        assertEquals(-1, ArrayUtils.indexOf(null, null));
1344        assertEquals(-1, ArrayUtils.indexOf(null, "0"));
1345        assertEquals(-1, ArrayUtils.indexOf(new Object JavaDoc[0], "0"));
1346        assertEquals(0, ArrayUtils.indexOf(array, "0"));
1347        assertEquals(1, ArrayUtils.indexOf(array, "1"));
1348        assertEquals(2, ArrayUtils.indexOf(array, "2"));
1349        assertEquals(3, ArrayUtils.indexOf(array, "3"));
1350        assertEquals(4, ArrayUtils.indexOf(array, null));
1351        assertEquals(-1, ArrayUtils.indexOf(array, "notInArray"));
1352    }
1353
1354    public void testIndexOfWithStartIndex() {
1355        Object JavaDoc[] array = new Object JavaDoc[] { "0", "1", "2", "3", null, "0" };
1356        assertEquals(-1, ArrayUtils.indexOf(null, null, 2));
1357        assertEquals(-1, ArrayUtils.indexOf(new Object JavaDoc[0], "0", 0));
1358        assertEquals(-1, ArrayUtils.indexOf(null, "0", 2));
1359        assertEquals(5, ArrayUtils.indexOf(array, "0", 2));
1360        assertEquals(-1, ArrayUtils.indexOf(array, "1", 2));
1361        assertEquals(2, ArrayUtils.indexOf(array, "2", 2));
1362        assertEquals(3, ArrayUtils.indexOf(array, "3", 2));
1363        assertEquals(4, ArrayUtils.indexOf(array, null, 2));
1364        assertEquals(-1, ArrayUtils.indexOf(array, "notInArray", 2));
1365        
1366        assertEquals(4, ArrayUtils.indexOf(array, null, -1));
1367        assertEquals(-1, ArrayUtils.indexOf(array, null, 8));
1368        assertEquals(-1, ArrayUtils.indexOf(array, "0", 8));
1369    }
1370
1371    public void testLastIndexOf() {
1372        Object JavaDoc[] array = new Object JavaDoc[] { "0", "1", "2", "3", null, "0" };
1373        assertEquals(-1, ArrayUtils.lastIndexOf(null, null));
1374        assertEquals(-1, ArrayUtils.lastIndexOf(null, "0"));
1375        assertEquals(5, ArrayUtils.lastIndexOf(array, "0"));
1376        assertEquals(1, ArrayUtils.lastIndexOf(array, "1"));
1377        assertEquals(2, ArrayUtils.lastIndexOf(array, "2"));
1378        assertEquals(3, ArrayUtils.lastIndexOf(array, "3"));
1379        assertEquals(4, ArrayUtils.lastIndexOf(array, null));
1380        assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray"));
1381    }
1382
1383    public void testLastIndexOfWithStartIndex() {
1384        Object JavaDoc[] array = new Object JavaDoc[] { "0", "1", "2", "3", null, "0" };
1385        assertEquals(-1, ArrayUtils.lastIndexOf(null, null, 2));
1386        assertEquals(-1, ArrayUtils.lastIndexOf(null, "0", 2));
1387        assertEquals(0, ArrayUtils.lastIndexOf(array, "0", 2));
1388        assertEquals(1, ArrayUtils.lastIndexOf(array, "1", 2));
1389        assertEquals(2, ArrayUtils.lastIndexOf(array, "2", 2));
1390        assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", 2));
1391        assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", -1));
1392        assertEquals(4, ArrayUtils.lastIndexOf(array, null, 5));
1393        assertEquals(-1, ArrayUtils.lastIndexOf(array, null, 2));
1394        assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray", 5));
1395        
1396        assertEquals(-1, ArrayUtils.lastIndexOf(array, null, -1));
1397        assertEquals(5, ArrayUtils.lastIndexOf(array, "0", 88));
1398    }
1399
1400    public void testContains() {
1401        Object JavaDoc[] array = new Object JavaDoc[] { "0", "1", "2", "3", null, "0" };
1402        assertEquals(false, ArrayUtils.contains(null, null));
1403        assertEquals(false, ArrayUtils.contains(null, "1"));
1404        assertEquals(true, ArrayUtils.contains(array, "0"));
1405        assertEquals(true, ArrayUtils.contains(array, "1"));
1406        assertEquals(true, ArrayUtils.contains(array, "2"));
1407        assertEquals(true, ArrayUtils.contains(array, "3"));
1408        assertEquals(true, ArrayUtils.contains(array, null));
1409        assertEquals(false, ArrayUtils.contains(array, "notInArray"));
1410    }
1411    
1412    //-----------------------------------------------------------------------
1413
public void testIndexOfLong() {
1414        long[] array = null;
1415        assertEquals(-1, ArrayUtils.indexOf(array, 0));
1416        array = new long[] { 0, 1, 2, 3, 0 };
1417        assertEquals(0, ArrayUtils.indexOf(array, 0));
1418        assertEquals(1, ArrayUtils.indexOf(array, 1));
1419        assertEquals(2, ArrayUtils.indexOf(array, 2));
1420        assertEquals(3, ArrayUtils.indexOf(array, 3));
1421        assertEquals(-1, ArrayUtils.indexOf(array, 99));
1422    }
1423
1424    public void testIndexOfLongWithStartIndex() {
1425        long[] array = null;
1426        assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
1427        array = new long[] { 0, 1, 2, 3, 0 };
1428        assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
1429        assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
1430        assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
1431        assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
1432        assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
1433        assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
1434        assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
1435    }
1436
1437    public void testLastIndexOfLong() {
1438        long[] array = null;
1439        assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
1440        array = new long[] { 0, 1, 2, 3, 0 };
1441        assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
1442        assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
1443        assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
1444        assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
1445        assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1446    }
1447
1448    public void testLastIndexOfLongWithStartIndex() {
1449        long[] array = null;
1450        assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
1451        array = new long[] { 0, 1, 2, 3, 0 };
1452        assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
1453        assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
1454        assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
1455        assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
1456        assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
1457        assertEquals(-1, ArrayUtils.lastIndexOf(array, 99, 4));
1458        assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
1459    }
1460
1461    public void testContainsLong() {
1462        long[] array = null;
1463        assertEquals(false, ArrayUtils.contains(array, 1));
1464        array = new long[] { 0, 1, 2, 3, 0 };
1465        assertEquals(true, ArrayUtils.contains(array, 0));
1466        assertEquals(true, ArrayUtils.contains(array, 1));
1467        assertEquals(true, ArrayUtils.contains(array, 2));
1468        assertEquals(true, ArrayUtils.contains(array, 3));
1469        assertEquals(false, ArrayUtils.contains(array, 99));
1470    }
1471    
1472    //-----------------------------------------------------------------------
1473
public void testIndexOfInt() {
1474        int[] array = null;
1475        assertEquals(-1, ArrayUtils.indexOf(array, 0));
1476        array = new int[] { 0, 1, 2, 3, 0 };
1477        assertEquals(0, ArrayUtils.indexOf(array, 0));
1478        assertEquals(1, ArrayUtils.indexOf(array, 1));
1479        assertEquals(2, ArrayUtils.indexOf(array, 2));
1480        assertEquals(3, ArrayUtils.indexOf(array, 3));
1481        assertEquals(-1, ArrayUtils.indexOf(array, 99));
1482    }
1483
1484    public void testIndexOfIntWithStartIndex() {
1485        int[] array = null;
1486        assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
1487        array = new int[] { 0, 1, 2, 3, 0 };
1488        assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
1489        assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
1490        assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
1491        assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
1492        assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
1493        assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
1494        assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
1495    }
1496
1497    public void testLastIndexOfInt() {
1498        int[] array = null;
1499        assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
1500        array = new int[] { 0, 1, 2, 3, 0 };
1501        assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
1502        assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
1503        assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
1504        assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
1505        assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1506    }
1507
1508    public void testLastIndexOfIntWithStartIndex() {
1509        int[] array = null;
1510        assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
1511        array = new int[] { 0, 1, 2, 3, 0 };
1512        assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
1513        assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
1514        assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
1515        assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
1516        assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
1517        assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1518        assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
1519    }
1520
1521    public void testContainsInt() {
1522        int[] array = null;
1523        assertEquals(false, ArrayUtils.contains(array, 1));
1524        array = new int[] { 0, 1, 2, 3, 0 };
1525        assertEquals(true, ArrayUtils.contains(array, 0));
1526        assertEquals(true, ArrayUtils.contains(array, 1));
1527        assertEquals(true, ArrayUtils.contains(array, 2));
1528        assertEquals(true, ArrayUtils.contains(array, 3));
1529        assertEquals(false, ArrayUtils.contains(array, 99));
1530    }
1531    
1532    //-----------------------------------------------------------------------
1533
public void testIndexOfShort() {
1534        short[] array = null;
1535        assertEquals(-1, ArrayUtils.indexOf(array, (short) 0));
1536        array = new short[] { 0, 1, 2, 3, 0 };
1537        assertEquals(0, ArrayUtils.indexOf(array, (short) 0));
1538        assertEquals(1, ArrayUtils.indexOf(array, (short) 1));
1539        assertEquals(2, ArrayUtils.indexOf(array, (short) 2));
1540        assertEquals(3, ArrayUtils.indexOf(array, (short) 3));
1541        assertEquals(-1, ArrayUtils.indexOf(array, (short) 99));
1542    }
1543
1544    public void testIndexOfShortWithStartIndex() {
1545        short[] array = null;
1546        assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 2));
1547        array = new short[] { 0, 1, 2, 3, 0 };
1548        assertEquals(4, ArrayUtils.indexOf(array, (short) 0, 2));
1549        assertEquals(-1, ArrayUtils.indexOf(array, (short) 1, 2));
1550        assertEquals(2, ArrayUtils.indexOf(array, (short) 2, 2));
1551        assertEquals(3, ArrayUtils.indexOf(array, (short) 3, 2));
1552        assertEquals(3, ArrayUtils.indexOf(array, (short) 3, -1));
1553        assertEquals(-1, ArrayUtils.indexOf(array, (short) 99, 0));
1554        assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 6));
1555    }
1556
1557    public void testLastIndexOfShort() {
1558        short[] array = null;
1559        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0));
1560        array = new short[] { 0, 1, 2, 3, 0 };
1561        assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0));
1562        assertEquals(1, ArrayUtils.lastIndexOf(array, (short) 1));
1563        assertEquals(2, ArrayUtils.lastIndexOf(array, (short) 2));
1564        assertEquals(3, ArrayUtils.lastIndexOf(array, (short) 3));
1565        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
1566    }
1567
1568    public void testLastIndexOfShortWithStartIndex() {
1569        short[] array = null;
1570        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0, 2));
1571        array = new short[] { 0, 1, 2, 3, 0 };
1572        assertEquals(0, ArrayUtils.lastIndexOf(array, (short) 0, 2));
1573        assertEquals(1, ArrayUtils.lastIndexOf(array, (short) 1, 2));
1574        assertEquals(2, ArrayUtils.lastIndexOf(array, (short) 2, 2));
1575        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, 2));
1576        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, -1));
1577        assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
1578        assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0, 88));
1579    }
1580
1581    public void testContainsShort() {
1582        short[] array = null;
1583        assertEquals(false, ArrayUtils.contains(array, (short) 1));
1584        array = new short[] { 0, 1, 2, 3, 0 };
1585        assertEquals(true, ArrayUtils.contains(array, (short) 0));
1586        assertEquals(true, ArrayUtils.contains(array, (short) 1));
1587        assertEquals(true, ArrayUtils.contains(array, (short) 2));
1588        assertEquals(true, ArrayUtils.contains(array, (short) 3));
1589        assertEquals(false, ArrayUtils.contains(array, (short) 99));
1590    }
1591    
1592    //-----------------------------------------------------------------------
1593
public void testIndexOfChar() {
1594        char[] array = null;
1595        assertEquals(-1, ArrayUtils.indexOf(array, 'a'));
1596        array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1597        assertEquals(0, ArrayUtils.indexOf(array, 'a'));
1598        assertEquals(1, ArrayUtils.indexOf(array, 'b'));
1599        assertEquals(2, ArrayUtils.indexOf(array, 'c'));
1600        assertEquals(3, ArrayUtils.indexOf(array, 'd'));
1601        assertEquals(-1, ArrayUtils.indexOf(array, 'e'));
1602    }
1603
1604    public void testIndexOfCharWithStartIndex() {
1605        char[] array = null;
1606        assertEquals(-1, ArrayUtils.indexOf(array, 'a', 2));
1607        array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1608        assertEquals(4, ArrayUtils.indexOf(array, 'a', 2));
1609        assertEquals(-1, ArrayUtils.indexOf(array, 'b', 2));
1610        assertEquals(2, ArrayUtils.indexOf(array, 'c', 2));
1611        assertEquals(3, ArrayUtils.indexOf(array, 'd', 2));
1612        assertEquals(3, ArrayUtils.indexOf(array, 'd', -1));
1613        assertEquals(-1, ArrayUtils.indexOf(array, 'e', 0));
1614        assertEquals(-1, ArrayUtils.indexOf(array, 'a', 6));
1615    }
1616
1617    public void testLastIndexOfChar() {
1618        char[] array = null;
1619        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a'));
1620        array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1621        assertEquals(4, ArrayUtils.lastIndexOf(array, 'a'));
1622        assertEquals(1, ArrayUtils.lastIndexOf(array, 'b'));
1623        assertEquals(2, ArrayUtils.lastIndexOf(array, 'c'));
1624        assertEquals(3, ArrayUtils.lastIndexOf(array, 'd'));
1625        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'e'));
1626    }
1627
1628    public void testLastIndexOfCharWithStartIndex() {
1629        char[] array = null;
1630        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a', 2));
1631        array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1632        assertEquals(0, ArrayUtils.lastIndexOf(array, 'a', 2));
1633        assertEquals(1, ArrayUtils.lastIndexOf(array, 'b', 2));
1634        assertEquals(2, ArrayUtils.lastIndexOf(array, 'c', 2));
1635        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'd', 2));
1636        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'd', -1));
1637        assertEquals(-1, ArrayUtils.lastIndexOf(array, 'e'));
1638        assertEquals(4, ArrayUtils.lastIndexOf(array, 'a', 88));
1639    }
1640
1641    public void testContainsChar() {
1642        char[] array = null;
1643        assertEquals(false, ArrayUtils.contains(array, 'b'));
1644        array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1645        assertEquals(true, ArrayUtils.contains(array, 'a'));
1646        assertEquals(true, ArrayUtils.contains(array, 'b'));
1647        assertEquals(true, ArrayUtils.contains(array, 'c'));
1648        assertEquals(true, ArrayUtils.contains(array, 'd'));
1649        assertEquals(false, ArrayUtils.contains(array, 'e'));
1650    }
1651    
1652    //-----------------------------------------------------------------------
1653
public void testIndexOfByte() {
1654        byte[] array = null;
1655        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0));
1656        array = new byte[] { 0, 1, 2, 3, 0 };
1657        assertEquals(0, ArrayUtils.indexOf(array, (byte) 0));
1658        assertEquals(1, ArrayUtils.indexOf(array, (byte) 1));
1659        assertEquals(2, ArrayUtils.indexOf(array, (byte) 2));
1660        assertEquals(3, ArrayUtils.indexOf(array, (byte) 3));
1661        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99));
1662    }
1663
1664    public void testIndexOfByteWithStartIndex() {
1665        byte[] array = null;
1666        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 2));
1667        array = new byte[] { 0, 1, 2, 3, 0 };
1668        assertEquals(4, ArrayUtils.indexOf(array, (byte) 0, 2));
1669        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 1, 2));
1670        assertEquals(2, ArrayUtils.indexOf(array, (byte) 2, 2));
1671        assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, 2));
1672        assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, -1));
1673        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99, 0));
1674        assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 6));
1675    }
1676
1677    public void testLastIndexOfByte() {
1678        byte[] array = null;
1679        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0));
1680        array = new byte[] { 0, 1, 2, 3, 0 };
1681        assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0));
1682        assertEquals(1, ArrayUtils.lastIndexOf(array, (byte) 1));
1683        assertEquals(2, ArrayUtils.lastIndexOf(array, (byte) 2));
1684        assertEquals(3, ArrayUtils.lastIndexOf(array, (byte) 3));
1685        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
1686    }
1687
1688    public void testLastIndexOfByteWithStartIndex() {
1689        byte[] array = null;
1690        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0, 2));
1691        array = new byte[] { 0, 1, 2, 3, 0 };
1692        assertEquals(0, ArrayUtils.lastIndexOf(array, (byte) 0, 2));
1693        assertEquals(1, ArrayUtils.lastIndexOf(array, (byte) 1, 2));
1694        assertEquals(2, ArrayUtils.lastIndexOf(array, (byte) 2, 2));
1695        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, 2));
1696        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, -1));
1697        assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
1698        assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0, 88));
1699    }
1700
1701    public void testContainsByte() {
1702        byte[] array = null;
1703        assertEquals(false, ArrayUtils.contains(array, (byte) 1));
1704        array = new byte[] { 0, 1, 2, 3, 0 };
1705        assertEquals(true, ArrayUtils.contains(array, (byte) 0));
1706        assertEquals(true, ArrayUtils.contains(array, (byte) 1));
1707        assertEquals(true, ArrayUtils.contains(array, (byte) 2));
1708        assertEquals(true, ArrayUtils.contains(array, (byte) 3));
1709        assertEquals(false, ArrayUtils.contains(array, (byte) 99));
1710    }
1711    
1712    //-----------------------------------------------------------------------
1713
public void testIndexOfDouble() {
1714        double[] array = null;
1715        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0));
1716        array = new double[0];
1717        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0));
1718        array = new double[] { 0, 1, 2, 3, 0 };
1719        assertEquals(0, ArrayUtils.indexOf(array, (double) 0));
1720        assertEquals(1, ArrayUtils.indexOf(array, (double) 1));
1721        assertEquals(2, ArrayUtils.indexOf(array, (double) 2));
1722        assertEquals(3, ArrayUtils.indexOf(array, (double) 3));
1723        assertEquals(3, ArrayUtils.indexOf(array, (double) 3, -1));
1724        assertEquals(-1, ArrayUtils.indexOf(array, (double) 99));
1725    }
1726
1727    public void testIndexOfDoubleTolerance() {
1728        double[] array = null;
1729        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, (double) 0));
1730        array = new double[0];
1731        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, (double) 0));
1732        array = new double[] { 0, 1, 2, 3, 0 };
1733        assertEquals(0, ArrayUtils.indexOf(array, (double) 0, (double) 0.3));
1734        assertEquals(2, ArrayUtils.indexOf(array, (double) 2.2, (double) 0.35));
1735        assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15, (double) 2.0));
1736        assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324, (double) 0.0001));
1737    }
1738
1739    public void testIndexOfDoubleWithStartIndex() {
1740        double[] array = null;
1741        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2));
1742        array = new double[0];
1743        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2));
1744        array = new double[] { 0, 1, 2, 3, 0 };
1745        assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 2));
1746        assertEquals(-1, ArrayUtils.indexOf(array, (double) 1, 2));
1747        assertEquals(2, ArrayUtils.indexOf(array, (double) 2, 2));
1748        assertEquals(3, ArrayUtils.indexOf(array, (double) 3, 2));
1749        assertEquals(-1, ArrayUtils.indexOf(array, (double) 99, 0));
1750        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 6));
1751    }
1752    
1753    public void testIndexOfDoubleWithStartIndexTolerance() {
1754        double[] array = null;
1755        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2, (double) 0));
1756        array = new double[0];
1757        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2, (double) 0));
1758        array = new double[] { 0, 1, 2, 3, 0 };
1759        assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 99, (double) 0.3));
1760        assertEquals(0, ArrayUtils.indexOf(array, (double) 0, 0, (double) 0.3));
1761        assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 3, (double) 0.3));
1762        assertEquals(2, ArrayUtils.indexOf(array, (double) 2.2, 0, (double) 0.35));
1763        assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15, 0, (double) 2.0));
1764        assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324, 0, (double) 0.0001));
1765        assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15, -1, (double) 2.0));
1766        assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324, -300, (double) 0.0001));
1767    }
1768
1769    public void testLastIndexOfDouble() {
1770        double[] array = null;
1771        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
1772        array = new double[0];
1773        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
1774        array = new double[] { 0, 1, 2, 3, 0 };
1775        assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0));
1776        assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1));
1777        assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2));
1778        assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 3));
1779        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99));
1780    }
1781
1782    public void testLastIndexOfDoubleTolerance() {
1783        double[] array = null;
1784        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0));
1785        array = new double[0];
1786        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0));
1787        array = new double[] { 0, 1, 2, 3, 0 };
1788        assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, (double) 0.3));
1789        assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2.2, (double) 0.35));
1790        assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 4.15, (double) 2.0));
1791        assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1.00001324, (double) 0.0001));
1792    }
1793
1794    public void testLastIndexOfDoubleWithStartIndex() {
1795        double[] array = null;
1796        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1797        array = new double[0];
1798        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1799        array = new double[] { 0, 1, 2, 3, 0 };
1800        assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1801        assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1, 2));
1802        assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2, 2));
1803        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, 2));
1804        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, -1));
1805        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99));
1806        assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 88));
1807    }
1808
1809    public void testLastIndexOfDoubleWithStartIndexTolerance() {
1810        double[] array = null;
1811        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0));
1812        array = new double[0];
1813        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2, (double) 0));
1814        array = new double[] { 0, 1, 2, 3, 0 };
1815        assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 99, (double) 0.3));
1816        assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 3, (double) 0.3));
1817        assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2.2, 3, (double) 0.35));
1818        assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 4.15, array.length, (double) 2.0));
1819        assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1.00001324, array.length, (double) 0.0001));
1820        assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 4.15, -200, (double) 2.0));
1821    }
1822
1823    public void testContainsDouble() {
1824        double[] array = null;
1825        assertEquals(false, ArrayUtils.contains(array, (double) 1));
1826        array = new double[] { 0, 1, 2, 3, 0 };
1827        assertEquals(true, ArrayUtils.contains(array, (double) 0));
1828        assertEquals(true, ArrayUtils.contains(array, (double) 1));
1829        assertEquals(true, ArrayUtils.contains(array, (double) 2));
1830        assertEquals(true, ArrayUtils.contains(array, (double) 3));
1831        assertEquals(false, ArrayUtils.contains(array, (double) 99));
1832    }
1833
1834    public void testContainsDoubleTolerance() {
1835        double[] array = null;
1836        assertEquals(false, ArrayUtils.contains(array, (double) 1, (double) 0));
1837        array = new double[] { 0, 1, 2, 3, 0 };
1838        assertEquals(false, ArrayUtils.contains(array, (double) 4.0, (double) 0.33));
1839        assertEquals(false, ArrayUtils.contains(array, (double) 2.5, (double) 0.49));
1840        assertEquals(true, ArrayUtils.contains(array, (double) 2.5, (double) 0.50));
1841        assertEquals(true, ArrayUtils.contains(array, (double) 2.5, (double) 0.51));
1842    }
1843    
1844    //-----------------------------------------------------------------------
1845
public void testIndexOfFloat() {
1846        float[] array = null;
1847        assertEquals(-1, ArrayUtils.indexOf(array, (float) 0));
1848        array = new float[0];
1849        assertEquals(-1, ArrayUtils.indexOf(array, (float) 0));
1850        array = new float[] { 0, 1, 2, 3, 0 };
1851        assertEquals(0, ArrayUtils.indexOf(array, (float) 0));
1852        assertEquals(1, ArrayUtils.indexOf(array, (float) 1));
1853        assertEquals(2, ArrayUtils.indexOf(array, (float) 2));
1854        assertEquals(3, ArrayUtils.indexOf(array, (float) 3));
1855        assertEquals(-1, ArrayUtils.indexOf(array, (float) 99));
1856    }
1857
1858    public void testIndexOfFloatWithStartIndex() {
1859        float[] array = null;
1860        assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2));
1861        array = new float[0];
1862        assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2));
1863        array = new float[] { 0, 1, 2, 3, 0 };
1864        assertEquals(4, ArrayUtils.indexOf(array, (float) 0, 2));
1865        assertEquals(-1, ArrayUtils.indexOf(array, (float) 1, 2));
1866        assertEquals(2, ArrayUtils.indexOf(array, (float) 2, 2));
1867        assertEquals(3, ArrayUtils.indexOf(array, (float) 3, 2));
1868        assertEquals(3, ArrayUtils.indexOf(array, (float) 3, -1));
1869        assertEquals(-1, ArrayUtils.indexOf(array, (float) 99, 0));
1870        assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 6));
1871    }
1872
1873    public void testLastIndexOfFloat() {
1874        float[] array = null;
1875        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
1876        array = new float[0];
1877        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
1878        array = new float[] { 0, 1, 2, 3, 0 };
1879        assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0));
1880        assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1));
1881        assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2));
1882        assertEquals(3, ArrayUtils.lastIndexOf(array, (float) 3));
1883        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99));
1884    }
1885
1886    public void testLastIndexOfFloatWithStartIndex() {
1887        float[] array = null;
1888        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2));
1889        array = new float[0];
1890        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2));
1891        array = new float[] { 0, 1, 2, 3, 0 };
1892        assertEquals(0, ArrayUtils.lastIndexOf(array, (float) 0, 2));
1893        assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1, 2));
1894        assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2, 2));
1895        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, 2));
1896        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, -1));
1897        assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99));
1898        assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0, 88));
1899    }
1900
1901    public void testContainsFloat() {
1902        float[] array = null;
1903        assertEquals(false, ArrayUtils.contains(array, (float) 1));
1904        array = new float[] { 0, 1, 2, 3, 0 };
1905        assertEquals(true, ArrayUtils.contains(array, (float) 0));
1906        assertEquals(true, ArrayUtils.contains(array, (float) 1));
1907        assertEquals(true, ArrayUtils.contains(array, (float) 2));
1908        assertEquals(true, ArrayUtils.contains(array, (float) 3));
1909        assertEquals(false, ArrayUtils.contains(array, (float) 99));
1910    }
1911    
1912    //-----------------------------------------------------------------------
1913
public void testIndexOfBoolean() {
1914        boolean[] array = null;
1915        assertEquals(-1, ArrayUtils.indexOf(array, true));
1916        array = new boolean[0];
1917        assertEquals(-1, ArrayUtils.indexOf(array, true));
1918        array = new boolean[] { true, false, true };
1919        assertEquals(0, ArrayUtils.indexOf(array, true));
1920        assertEquals(1, ArrayUtils.indexOf(array, false));
1921        array = new boolean[] { true, true };
1922        assertEquals(-1, ArrayUtils.indexOf(array, false));
1923    }
1924
1925    public void testIndexOfBooleanWithStartIndex() {
1926        boolean[] array = null;
1927        assertEquals(-1, ArrayUtils.indexOf(array, true, 2));
1928        array = new boolean[0];
1929        assertEquals(-1, ArrayUtils.indexOf(array, true, 2));
1930        array = new boolean[] { true, false, true };
1931        assertEquals(2, ArrayUtils.indexOf(array, true, 1));
1932        assertEquals(-1, ArrayUtils.indexOf(array, false, 2));
1933        assertEquals(1, ArrayUtils.indexOf(array, false, 0));
1934        assertEquals(1, ArrayUtils.indexOf(array, false, -1));
1935        array = new boolean[] { true, true };
1936        assertEquals(-1, ArrayUtils.indexOf(array, false, 0));
1937        assertEquals(-1, ArrayUtils.indexOf(array, false, -1));
1938    }
1939
1940    public void testLastIndexOfBoolean() {
1941        boolean[] array = null;
1942        assertEquals(-1, ArrayUtils.lastIndexOf(array, true));
1943        array = new boolean[0];
1944        assertEquals(-1, ArrayUtils.lastIndexOf(array, true));
1945        array = new boolean[] { true, false, true };
1946        assertEquals(2, ArrayUtils.lastIndexOf(array, true));
1947        assertEquals(1, ArrayUtils.lastIndexOf(array, false));
1948        array = new boolean[] { true, true };
1949        assertEquals(-1, ArrayUtils.lastIndexOf(array, false));
1950    }
1951
1952    public void testLastIndexOfBooleanWithStartIndex() {
1953        boolean[] array = null;
1954        assertEquals(-1, ArrayUtils.lastIndexOf(array, true, 2));
1955        array = new boolean[0];
1956        assertEquals(-1, ArrayUtils.lastIndexOf(array, true, 2));
1957        array = new boolean[] { true, false, true };
1958        assertEquals(2, ArrayUtils.lastIndexOf(array, true, 2));
1959        assertEquals(0, ArrayUtils.lastIndexOf(array, true, 1));
1960        assertEquals(1, ArrayUtils.lastIndexOf(array, false, 2));
1961        assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
1962        array = new boolean[] { true, true };
1963        assertEquals(-1, ArrayUtils.lastIndexOf(array, false, 2));
1964        assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
1965    }
1966
1967    public void testContainsBoolean() {
1968        boolean[] array = null;
1969        assertEquals(false, ArrayUtils.contains(array, true));
1970        array = new boolean[] { true, false, true };
1971        assertEquals(true, ArrayUtils.contains(array, true));
1972        assertEquals(true, ArrayUtils.contains(array, false));
1973        array = new boolean[] { true, true };
1974        assertEquals(true, ArrayUtils.contains(array, true));
1975        assertEquals(false, ArrayUtils.contains(array, false));
1976    }
1977    
1978    // testToPrimitive/Object for boolean
1979
// -----------------------------------------------------------------------
1980
public void testToPrimitive_boolean() {
1981        final Boolean JavaDoc[] b = null;
1982        assertEquals(null, ArrayUtils.toPrimitive(b));
1983        assertSame(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.toPrimitive(new Boolean JavaDoc[0]));
1984        assertTrue(Arrays.equals(
1985            new boolean[] {true, false, true},
1986            ArrayUtils.toPrimitive(new Boolean JavaDoc[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE}))
1987        );
1988
1989        try {
1990            ArrayUtils.toPrimitive(new Boolean JavaDoc[] {Boolean.TRUE, null});
1991            fail();
1992        } catch (NullPointerException JavaDoc ex) {}
1993    }
1994
1995    public void testToPrimitive_boolean_boolean() {
1996        assertEquals(null, ArrayUtils.toPrimitive(null, false));
1997        assertSame(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.toPrimitive(new Boolean JavaDoc[0], false));
1998        assertTrue(Arrays.equals(
1999            new boolean[] {true, false, true},
2000            ArrayUtils.toPrimitive(new Boolean JavaDoc[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE}, false))
2001        );
2002        assertTrue(Arrays.equals(
2003            new boolean[] {true, false, false},
2004            ArrayUtils.toPrimitive(new Boolean JavaDoc[] {Boolean.TRUE, null, Boolean.FALSE}, false))
2005        );
2006        assertTrue(Arrays.equals(
2007            new boolean[] {true, true, false},
2008            ArrayUtils.toPrimitive(new Boolean JavaDoc[] {Boolean.TRUE, null, Boolean.FALSE}, true))
2009        );
2010    }
2011
2012    public void testToObject_boolean() {
2013        final boolean[] b = null;
2014        assertEquals(null, ArrayUtils.toObject(b));
2015        assertSame(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayUtils.toObject(new boolean[0]));
2016        assertTrue(Arrays.equals(
2017            new Boolean JavaDoc[] {Boolean.TRUE, Boolean.FALSE, Boolean.TRUE},
2018            ArrayUtils.toObject(new boolean[] {true, false, true}))
2019        );
2020    }
2021
2022    // testToPrimitive/Object for byte
2023
// -----------------------------------------------------------------------
2024
public void testToPrimitive_byte() {
2025        final Byte JavaDoc[] b = null;
2026        assertEquals(null, ArrayUtils.toPrimitive(b));
2027        
2028        assertSame(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.toPrimitive(new Byte JavaDoc[0]));
2029        
2030        assertTrue(Arrays.equals(
2031            new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
2032            ArrayUtils.toPrimitive(new Byte JavaDoc[] {new Byte JavaDoc(Byte.MIN_VALUE),
2033                new Byte JavaDoc(Byte.MAX_VALUE), new Byte JavaDoc((byte)9999999)}))
2034        );
2035
2036        try {
2037            ArrayUtils.toPrimitive(new Byte JavaDoc[] {new Byte JavaDoc(Byte.MIN_VALUE), null});
2038            fail();
2039        } catch (NullPointerException JavaDoc ex) {}
2040    }
2041
2042    public void testToPrimitive_byte_byte() {
2043        final Byte JavaDoc[] b = null;
2044        assertEquals(null, ArrayUtils.toPrimitive(b, Byte.MIN_VALUE));
2045        
2046        assertSame(ArrayUtils.EMPTY_BYTE_ARRAY,
2047            ArrayUtils.toPrimitive(new Byte JavaDoc[0], (byte)1));
2048        
2049        assertTrue(Arrays.equals(
2050            new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
2051            ArrayUtils.toPrimitive(new Byte JavaDoc[] {new Byte JavaDoc(Byte.MIN_VALUE),
2052                new Byte JavaDoc(Byte.MAX_VALUE), new Byte JavaDoc((byte)9999999)},
2053                Byte.MIN_VALUE))
2054        );
2055        
2056        assertTrue(Arrays.equals(
2057            new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE, (byte)9999999},
2058            ArrayUtils.toPrimitive(new Byte JavaDoc[] {new Byte JavaDoc(Byte.MIN_VALUE), null,
2059                new Byte JavaDoc((byte)9999999)}, Byte.MAX_VALUE))
2060        );
2061    }
2062
2063    public void testToObject_byte() {
2064        final byte[] b = null;
2065        assertEquals(null, ArrayUtils.toObject(b));
2066        
2067        assertSame(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY,
2068            ArrayUtils.toObject(new byte[0]));
2069        
2070        assertTrue(Arrays.equals(
2071            new Byte JavaDoc[] {new Byte JavaDoc(Byte.MIN_VALUE),
2072                new Byte JavaDoc(Byte.MAX_VALUE), new Byte JavaDoc((byte)9999999)},
2073                ArrayUtils.toObject(new byte[] {Byte.MIN_VALUE, Byte.MAX_VALUE,
2074                (byte)9999999}))
2075        );
2076    }
2077
2078    // testToPrimitive/Object for short
2079
// -----------------------------------------------------------------------
2080
public void testToPrimitive_short() {
2081        final Short JavaDoc[] b = null;
2082        assertEquals(null, ArrayUtils.toPrimitive(b));
2083        
2084        assertSame(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.toPrimitive(new Short JavaDoc[0]));
2085        
2086        assertTrue(Arrays.equals(
2087            new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
2088            ArrayUtils.toPrimitive(new Short JavaDoc[] {new Short JavaDoc(Short.MIN_VALUE),
2089                new Short JavaDoc(Short.MAX_VALUE), new Short JavaDoc((short)9999999)}))
2090        );
2091
2092        try {
2093            ArrayUtils.toPrimitive(new Short JavaDoc[] {new Short JavaDoc(Short.MIN_VALUE), null});
2094            fail();
2095        } catch (NullPointerException JavaDoc ex) {}
2096    }
2097
2098    public void testToPrimitive_short_short() {
2099        final Short JavaDoc[] s = null;
2100        assertEquals(null, ArrayUtils.toPrimitive(s, Short.MIN_VALUE));
2101        
2102        assertSame(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.toPrimitive(new Short JavaDoc[0],
2103        Short.MIN_VALUE));
2104        
2105        assertTrue(Arrays.equals(
2106            new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
2107            ArrayUtils.toPrimitive(new Short JavaDoc[] {new Short JavaDoc(Short.MIN_VALUE),
2108                new Short JavaDoc(Short.MAX_VALUE), new Short JavaDoc((short)9999999)}, Short.MIN_VALUE))
2109        );
2110        
2111        assertTrue(Arrays.equals(
2112            new short[] {Short.MIN_VALUE, Short.MAX_VALUE, (short)9999999},
2113            ArrayUtils.toPrimitive(new Short JavaDoc[] {new Short JavaDoc(Short.MIN_VALUE), null,
2114                new Short JavaDoc((short)9999999)}, Short.MAX_VALUE))
2115        );
2116    }
2117
2118    public void testToObject_short() {
2119        final short[] b = null;
2120        assertEquals(null, ArrayUtils.toObject(b));
2121        
2122        assertSame(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY,
2123        ArrayUtils.toObject(new short[0]));
2124        
2125        assertTrue(Arrays.equals(
2126            new Short JavaDoc[] {new Short JavaDoc(Short.MIN_VALUE), new Short JavaDoc(Short.MAX_VALUE),
2127                new Short JavaDoc((short)9999999)},
2128            ArrayUtils.toObject(new short[] {Short.MIN_VALUE, Short.MAX_VALUE,
2129                (short)9999999}))
2130        );
2131    }
2132
2133    // testToPrimitive/Object for int
2134
// -----------------------------------------------------------------------
2135
public void testToPrimitive_int() {
2136         final Integer JavaDoc[] b = null;
2137         assertEquals(null, ArrayUtils.toPrimitive(b));
2138         assertSame(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.toPrimitive(new Integer JavaDoc[0]));
2139         assertTrue(Arrays.equals(
2140             new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE, 9999999},
2141             ArrayUtils.toPrimitive(new Integer JavaDoc[] {new Integer JavaDoc(Integer.MIN_VALUE),
2142                 new Integer JavaDoc(Integer.MAX_VALUE), new Integer JavaDoc(9999999)}))
2143         );
2144
2145         try {
2146             ArrayUtils.toPrimitive(new Integer JavaDoc[] {new Integer JavaDoc(Integer.MIN_VALUE), null});
2147             fail();
2148         } catch (NullPointerException JavaDoc ex) {}
2149     }
2150
2151     public void testToPrimitive_int_int() {
2152         final Long JavaDoc[] l = null;
2153         assertEquals(null, ArrayUtils.toPrimitive(l, Integer.MIN_VALUE));
2154         assertSame(ArrayUtils.EMPTY_INT_ARRAY,
2155         ArrayUtils.toPrimitive(new Integer JavaDoc[0], 1));
2156         assertTrue(Arrays.equals(
2157             new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE, 9999999},
2158             ArrayUtils.toPrimitive(new Integer JavaDoc[] {new Integer JavaDoc(Integer.MIN_VALUE),
2159                 new Integer JavaDoc(Integer.MAX_VALUE), new Integer JavaDoc(9999999)},1)));
2160         assertTrue(Arrays.equals(
2161             new int[] {Integer.MIN_VALUE, Integer.MAX_VALUE, 9999999},
2162             ArrayUtils.toPrimitive(new Integer JavaDoc[] {new Integer JavaDoc(Integer.MIN_VALUE),
2163                 null, new Integer JavaDoc(9999999)}, Integer.MAX_VALUE))
2164         );
2165     }
2166     
2167    public void testToPrimitive_intNull() {
2168        Integer JavaDoc[] iArray = null;
2169        assertEquals(null, ArrayUtils.toPrimitive(iArray, Integer.MIN_VALUE));
2170    }
2171
2172    public void testToObject_int() {
2173        final int[] b = null;
2174        assertEquals(null, ArrayUtils.toObject(b));
2175    
2176        assertSame(
2177            ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY,
2178            ArrayUtils.toObject(new int[0]));
2179    
2180        assertTrue(
2181            Arrays.equals(
2182                new Integer JavaDoc[] {
2183                    new Integer JavaDoc(Integer.MIN_VALUE),
2184                    new Integer JavaDoc(Integer.MAX_VALUE),
2185                    new Integer JavaDoc(9999999)},
2186            ArrayUtils.toObject(
2187                new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE, 9999999 })));
2188    }
2189
2190    // testToPrimitive/Object for long
2191
// -----------------------------------------------------------------------
2192
public void testToPrimitive_long() {
2193         final Long JavaDoc[] b = null;
2194         assertEquals(null, ArrayUtils.toPrimitive(b));
2195         
2196         assertSame(ArrayUtils.EMPTY_LONG_ARRAY,
2197            ArrayUtils.toPrimitive(new Long JavaDoc[0]));
2198         
2199         assertTrue(Arrays.equals(
2200             new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
2201             ArrayUtils.toPrimitive(new Long JavaDoc[] {new Long JavaDoc(Long.MIN_VALUE),
2202                 new Long JavaDoc(Long.MAX_VALUE), new Long JavaDoc(9999999)}))
2203         );
2204
2205         try {
2206             ArrayUtils.toPrimitive(new Long JavaDoc[] {new Long JavaDoc(Long.MIN_VALUE), null});
2207             fail();
2208         } catch (NullPointerException JavaDoc ex) {}
2209     }
2210
2211     public void testToPrimitive_long_long() {
2212         final Long JavaDoc[] l = null;
2213         assertEquals(null, ArrayUtils.toPrimitive(l, Long.MIN_VALUE));
2214         
2215         assertSame(ArrayUtils.EMPTY_LONG_ARRAY,
2216         ArrayUtils.toPrimitive(new Long JavaDoc[0], 1));
2217         
2218         assertTrue(Arrays.equals(
2219             new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
2220             ArrayUtils.toPrimitive(new Long JavaDoc[] {new Long JavaDoc(Long.MIN_VALUE),
2221                 new Long JavaDoc(Long.MAX_VALUE), new Long JavaDoc(9999999)},1)));
2222         
2223         assertTrue(Arrays.equals(
2224             new long[] {Long.MIN_VALUE, Long.MAX_VALUE, 9999999},
2225             ArrayUtils.toPrimitive(new Long JavaDoc[] {new Long JavaDoc(Long.MIN_VALUE),
2226                 null, new Long JavaDoc(9999999)}, Long.MAX_VALUE))
2227         );
2228     }
2229     
2230    public void testToObject_long() {
2231        final long[] b = null;
2232        assertEquals(null, ArrayUtils.toObject(b));
2233    
2234        assertSame(
2235            ArrayUtils.EMPTY_LONG_OBJECT_ARRAY,
2236            ArrayUtils.toObject(new long[0]));
2237    
2238        assertTrue(
2239            Arrays.equals(
2240                new Long JavaDoc[] {
2241                    new Long JavaDoc(Long.MIN_VALUE),
2242                    new Long JavaDoc(Long.MAX_VALUE),
2243                    new Long JavaDoc(9999999)},
2244            ArrayUtils.toObject(
2245                new long[] { Long.MIN_VALUE, Long.MAX_VALUE, 9999999 })));
2246    }
2247
2248    // testToPrimitive/Object for float
2249
// -----------------------------------------------------------------------
2250
public void testToPrimitive_float() {
2251         final Float JavaDoc[] b = null;
2252         assertEquals(null, ArrayUtils.toPrimitive(b));
2253         
2254         assertSame(ArrayUtils.EMPTY_FLOAT_ARRAY,
2255            ArrayUtils.toPrimitive(new Float JavaDoc[0]));
2256         
2257         assertTrue(Arrays.equals(
2258             new float[] {Float.MIN_VALUE, Float.MAX_VALUE, 9999999},
2259             ArrayUtils.toPrimitive(new Float JavaDoc[] {new Float JavaDoc(Float.MIN_VALUE),
2260                 new Float JavaDoc(Float.MAX_VALUE), new Float JavaDoc(9999999)}))
2261         );
2262
2263         try {
2264             ArrayUtils.toPrimitive(new Float JavaDoc[] {new Float JavaDoc(Float.MIN_VALUE), null});
2265             fail();
2266         } catch (NullPointerException JavaDoc ex) {}
2267     }
2268
2269     public void testToPrimitive_float_float() {
2270         final Float JavaDoc[] l = null;
2271         assertEquals(null, ArrayUtils.toPrimitive(l, Float.MIN_VALUE));
2272         
2273         assertSame(ArrayUtils.EMPTY_FLOAT_ARRAY,
2274         ArrayUtils.toPrimitive(new Float JavaDoc[0], 1));
2275         
2276         assertTrue(Arrays.equals(
2277             new float[] {Float.MIN_VALUE, Float.MAX_VALUE, 9999999},
2278             ArrayUtils.toPrimitive(new Float JavaDoc[] {new Float JavaDoc(Float.MIN_VALUE),
2279                 new Float JavaDoc(Float.MAX_VALUE), new Float JavaDoc(9999999)},1)));
2280         
2281         assertTrue(Arrays.equals(
2282             new float[] {Float.MIN_VALUE, Float.MAX_VALUE, 9999999},
2283             ArrayUtils.toPrimitive(new Float JavaDoc[] {new Float JavaDoc(Float.MIN_VALUE),
2284                 null, new Float JavaDoc(9999999)}, Float.MAX_VALUE))
2285         );
2286     }
2287     
2288    public void testToObject_float() {
2289        final float[] b = null;
2290        assertEquals(null, ArrayUtils.toObject(b));
2291    
2292        assertSame(
2293            ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY,
2294            ArrayUtils.toObject(new float[0]));
2295    
2296        assertTrue(
2297            Arrays.equals(
2298                new Float JavaDoc[] {
2299                    new Float JavaDoc(Float.MIN_VALUE),
2300                    new Float JavaDoc(Float.MAX_VALUE),
2301                    new Float JavaDoc(9999999)},
2302            ArrayUtils.toObject(
2303                new float[] { Float.MIN_VALUE, Float.MAX_VALUE, 9999999 })));
2304    }
2305
2306    // testToPrimitive/Object for double
2307
// -----------------------------------------------------------------------
2308
public void testToPrimitive_double() {
2309         final Double JavaDoc[] b = null;
2310         assertEquals(null, ArrayUtils.toPrimitive(b));
2311         
2312         assertSame(ArrayUtils.EMPTY_DOUBLE_ARRAY,
2313            ArrayUtils.toPrimitive(new Double JavaDoc[0]));
2314         
2315         assertTrue(Arrays.equals(
2316             new double[] {Double.MIN_VALUE, Double.MAX_VALUE, 9999999},
2317             ArrayUtils.toPrimitive(new Double JavaDoc[] {new Double JavaDoc(Double.MIN_VALUE),
2318                 new Double JavaDoc(Double.MAX_VALUE), new Double JavaDoc(9999999)}))
2319         );
2320
2321         try {
2322             ArrayUtils.toPrimitive(new Float JavaDoc[] {new Float JavaDoc(Float.MIN_VALUE), null});
2323             fail();
2324         } catch (NullPointerException JavaDoc ex) {}
2325     }
2326
2327     public void testToPrimitive_double_double() {
2328         final Double JavaDoc[] l = null;
2329         assertEquals(null, ArrayUtils.toPrimitive(l, Double.MIN_VALUE));
2330         
2331         assertSame(ArrayUtils.EMPTY_DOUBLE_ARRAY,
2332         ArrayUtils.toPrimitive(new Double JavaDoc[0], 1));
2333         
2334         assertTrue(Arrays.equals(
2335             new double[] {Double.MIN_VALUE, Double.MAX_VALUE, 9999999},
2336             ArrayUtils.toPrimitive(new Double JavaDoc[] {new Double JavaDoc(Double.MIN_VALUE),
2337                 new Double JavaDoc(Double.MAX_VALUE), new Double JavaDoc(9999999)},1)));
2338         
2339         assertTrue(Arrays.equals(
2340             new double[] {Double.MIN_VALUE, Double.MAX_VALUE, 9999999},
2341             ArrayUtils.toPrimitive(new Double JavaDoc[] {new Double JavaDoc(Double.MIN_VALUE),
2342                 null, new Double JavaDoc(9999999)}, Double.MAX_VALUE))
2343         );
2344     }
2345     
2346    public void testToObject_double() {
2347        final double[] b = null;
2348        assertEquals(null, ArrayUtils.toObject(b));
2349    
2350        assertSame(
2351            ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY,
2352            ArrayUtils.toObject(new double[0]));
2353    
2354        assertTrue(
2355            Arrays.equals(
2356                new Double JavaDoc[] {
2357                    new Double JavaDoc(Double.MIN_VALUE),
2358                    new Double JavaDoc(Double.MAX_VALUE),
2359                    new Double JavaDoc(9999999)},
2360            ArrayUtils.toObject(
2361                new double[] { Double.MIN_VALUE, Double.MAX_VALUE, 9999999 })));
2362    }
2363
2364    //-----------------------------------------------------------------------
2365
/**
2366     * Test for {@link ArrayUtils#isEmpty(java.lang.Object[])}.
2367     */

2368    public void testIsEmptyObject() {
2369        Object JavaDoc[] emptyArray = new Object JavaDoc[] {};
2370        Object JavaDoc[] notEmptyArray = new Object JavaDoc[] { new String JavaDoc("Value") };
2371        assertEquals(true, ArrayUtils.isEmpty((Object JavaDoc[])null));
2372        assertEquals(true, ArrayUtils.isEmpty(emptyArray));
2373        assertEquals(false, ArrayUtils.isEmpty(notEmptyArray));
2374    }
2375
2376    /**
2377     * Tests for {@link ArrayUtils#isEmpty(long[])},
2378     * {@link ArrayUtils#isEmpty(int[])},
2379     * {@link ArrayUtils#isEmpty(short[])},
2380     * {@link ArrayUtils#isEmpty(char[])},
2381     * {@link ArrayUtils#isEmpty(byte[])},
2382     * {@link ArrayUtils#isEmpty(double[])},
2383     * {@link ArrayUtils#isEmpty(float[])} and
2384     * {@link ArrayUtils#isEmpty(boolean[])}.
2385     */

2386    public void testIsEmptyPrimitives() {
2387        long[] emptyLongArray = new long[] {};
2388        long[] notEmptyLongArray = new long[] { 1L };
2389        assertEquals(true, ArrayUtils.isEmpty((long[])null));
2390        assertEquals(true, ArrayUtils.isEmpty(emptyLongArray));
2391        assertEquals(false, ArrayUtils.isEmpty(notEmptyLongArray));
2392
2393        int[] emptyIntArray = new int[] {};
2394        int[] notEmptyIntArray = new int[] { 1 };
2395        assertEquals(true, ArrayUtils.isEmpty((int[])null));
2396        assertEquals(true, ArrayUtils.isEmpty(emptyIntArray));
2397        assertEquals(false, ArrayUtils.isEmpty(notEmptyIntArray));
2398
2399        short[] emptyShortArray = new short[] {};
2400        short[] notEmptyShortArray = new short[] { 1 };
2401        assertEquals(true, ArrayUtils.isEmpty((short[])null));
2402        assertEquals(true, ArrayUtils.isEmpty(emptyShortArray));
2403        assertEquals(false, ArrayUtils.isEmpty(notEmptyShortArray));
2404
2405        char[] emptyCharArray = new char[] {};
2406        char[] notEmptyCharArray = new char[] { 1 };
2407        assertEquals(true, ArrayUtils.isEmpty((char[])null));
2408        assertEquals(true, ArrayUtils.isEmpty(emptyCharArray));
2409        assertEquals(false, ArrayUtils.isEmpty(notEmptyCharArray));
2410
2411        byte[] emptyByteArray = new byte[] {};
2412        byte[] notEmptyByteArray = new byte[] { 1 };
2413        assertEquals(true, ArrayUtils.isEmpty((byte[])null));
2414        assertEquals(true, ArrayUtils.isEmpty(emptyByteArray));
2415        assertEquals(false, ArrayUtils.isEmpty(notEmptyByteArray));
2416
2417        double[] emptyDoubleArray = new double[] {};
2418        double[] notEmptyDoubleArray = new double[] { 1.0 };
2419        assertEquals(true, ArrayUtils.isEmpty((double[])null));
2420        assertEquals(true, ArrayUtils.isEmpty(emptyDoubleArray));
2421        assertEquals(false, ArrayUtils.isEmpty(notEmptyDoubleArray));
2422
2423        float[] emptyFloatArray = new float[] {};
2424        float[] notEmptyFloatArray = new float[] { 1.0F };
2425        assertEquals(true, ArrayUtils.isEmpty((float[])null));
2426        assertEquals(true, ArrayUtils.isEmpty(emptyFloatArray));
2427        assertEquals(false, ArrayUtils.isEmpty(notEmptyFloatArray));
2428
2429        boolean[] emptyBooleanArray = new boolean[] {};
2430        boolean[] notEmptyBooleanArray = new boolean[] { true };
2431        assertEquals(true, ArrayUtils.isEmpty((boolean[])null));
2432        assertEquals(true, ArrayUtils.isEmpty(emptyBooleanArray));
2433        assertEquals(false, ArrayUtils.isEmpty(notEmptyBooleanArray));
2434    }
2435    
2436    // ------------------------------------------------------------------------
2437
public void testGetLength() {
2438        assertEquals(0, ArrayUtils.getLength(null));
2439        
2440        Object JavaDoc[] emptyObjectArray = new Object JavaDoc[0];
2441        Object JavaDoc[] notEmptyObjectArray = new Object JavaDoc[] {"aValue"};
2442        assertEquals(0, ArrayUtils.getLength((Object JavaDoc[]) null));
2443        assertEquals(0, ArrayUtils.getLength(emptyObjectArray));
2444        assertEquals(1, ArrayUtils.getLength(notEmptyObjectArray));
2445 
2446        int[] emptyIntArray = new int[] {};
2447        int[] notEmptyIntArray = new int[] { 1 };
2448        assertEquals(0, ArrayUtils.getLength((int[]) null));
2449        assertEquals(0, ArrayUtils.getLength(emptyIntArray));
2450        assertEquals(1, ArrayUtils.getLength(notEmptyIntArray));
2451
2452        short[] emptyShortArray = new short[] {};
2453        short[] notEmptyShortArray = new short[] { 1 };
2454        assertEquals(0, ArrayUtils.getLength((short[]) null));
2455        assertEquals(0, ArrayUtils.getLength(emptyShortArray));
2456        assertEquals(1, ArrayUtils.getLength(notEmptyShortArray));
2457
2458        char[] emptyCharArray = new char[] {};
2459        char[] notEmptyCharArray = new char[] { 1 };
2460        assertEquals(0, ArrayUtils.getLength((char[]) null));
2461        assertEquals(0, ArrayUtils.getLength(emptyCharArray));
2462        assertEquals(1, ArrayUtils.getLength(notEmptyCharArray));
2463
2464        byte[] emptyByteArray = new byte[] {};
2465        byte[] notEmptyByteArray = new byte[] { 1 };
2466        assertEquals(0, ArrayUtils.getLength((byte[]) null));
2467        assertEquals(0, ArrayUtils.getLength(emptyByteArray));
2468        assertEquals(1, ArrayUtils.getLength(notEmptyByteArray));
2469
2470        double[] emptyDoubleArray = new double[] {};
2471        double[] notEmptyDoubleArray = new double[] { 1.0 };
2472        assertEquals(0, ArrayUtils.getLength((double[]) null));
2473        assertEquals(0, ArrayUtils.getLength(emptyDoubleArray));
2474        assertEquals(1, ArrayUtils.getLength(notEmptyDoubleArray));
2475
2476        float[] emptyFloatArray = new float[] {};
2477        float[] notEmptyFloatArray = new float[] { 1.0F };
2478        assertEquals(0, ArrayUtils.getLength((float[]) null));
2479        assertEquals(0, ArrayUtils.getLength(emptyFloatArray));
2480        assertEquals(1, ArrayUtils.getLength(notEmptyFloatArray));
2481
2482        boolean[] emptyBooleanArray = new boolean[] {};
2483        boolean[] notEmptyBooleanArray = new boolean[] { true };
2484        assertEquals(0, ArrayUtils.getLength((boolean[]) null));
2485        assertEquals(0, ArrayUtils.getLength(emptyBooleanArray));
2486        assertEquals(1, ArrayUtils.getLength(notEmptyBooleanArray));
2487        
2488        try {
2489            ArrayUtils.getLength("notAnArray");
2490            fail("IllegalArgumentException should have been thrown");
2491        } catch (IllegalArgumentException JavaDoc e) {}
2492    }
2493
2494}
2495
Popular Tags