0001: /*
0002: * Licensed to the Apache Software Foundation (ASF) under one or more
0003: * contributor license agreements. See the NOTICE file distributed with
0004: * this work for additional information regarding copyright ownership.
0005: * The ASF licenses this file to You under the Apache License, Version 2.0
0006: * (the "License"); you may not use this file except in compliance with
0007: * the License. You may obtain a copy of the License at
0008: *
0009: * http://www.apache.org/licenses/LICENSE-2.0
0010: *
0011: * Unless required by applicable law or agreed to in writing, software
0012: * distributed under the License is distributed on an "AS IS" BASIS,
0013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014: * See the License for the specific language governing permissions and
0015: * limitations under the License.
0016: */
0017: package org.apache.commons.lang;
0018:
0019: import java.lang.reflect.Constructor;
0020: import java.lang.reflect.Modifier;
0021: import java.util.Arrays;
0022: import java.util.Date;
0023: import java.util.Map;
0024:
0025: import junit.framework.Test;
0026: import junit.framework.TestCase;
0027: import junit.framework.TestSuite;
0028: import junit.textui.TestRunner;
0029:
0030: /**
0031: * Unit tests {@link org.apache.commons.lang.ArrayUtils}.
0032: *
0033: * @author Stephen Colebourne
0034: * @author Moritz Petersen
0035: * @author Nikolay Metchev
0036: * @author Matthew Hawthorne
0037: * @author Tim O'Brien
0038: * @author <a href="mailto:equinus100@hotmail.com">Ashwin S</a>
0039: * @author Fredrik Westermarck
0040: * @author Gary Gregory
0041: * @author Maarten Coene
0042: * @version $Id: ArrayUtilsTest.java 437554 2006-08-28 06:21:41Z bayard $
0043: */
0044: public class ArrayUtilsTest extends TestCase {
0045:
0046: public ArrayUtilsTest(String name) {
0047: super (name);
0048: }
0049:
0050: public static void main(String[] args) {
0051: TestRunner.run(suite());
0052: }
0053:
0054: public static Test suite() {
0055: TestSuite suite = new TestSuite(ArrayUtilsTest.class);
0056: suite.setName("ArrayUtils Tests");
0057: return suite;
0058: }
0059:
0060: protected void setUp() throws Exception {
0061: super .setUp();
0062: }
0063:
0064: protected void tearDown() throws Exception {
0065: super .tearDown();
0066: }
0067:
0068: //-----------------------------------------------------------------------
0069: public void testConstructor() {
0070: assertNotNull(new ArrayUtils());
0071: Constructor[] cons = ArrayUtils.class.getDeclaredConstructors();
0072: assertEquals(1, cons.length);
0073: assertEquals(true, Modifier.isPublic(cons[0].getModifiers()));
0074: assertEquals(true, Modifier.isPublic(ArrayUtils.class
0075: .getModifiers()));
0076: assertEquals(false, Modifier.isFinal(ArrayUtils.class
0077: .getModifiers()));
0078: }
0079:
0080: //-----------------------------------------------------------------------
0081: public void testToString() {
0082: assertEquals("{}", ArrayUtils.toString(null));
0083: assertEquals("{}", ArrayUtils.toString(new Object[0]));
0084: assertEquals("{}", ArrayUtils.toString(new String[0]));
0085: assertEquals("{<null>}", ArrayUtils
0086: .toString(new String[] { null }));
0087: assertEquals("{pink,blue}", ArrayUtils.toString(new String[] {
0088: "pink", "blue" }));
0089:
0090: assertEquals("<empty>", ArrayUtils.toString(null, "<empty>"));
0091: assertEquals("{}", ArrayUtils
0092: .toString(new Object[0], "<empty>"));
0093: assertEquals("{}", ArrayUtils
0094: .toString(new String[0], "<empty>"));
0095: assertEquals("{<null>}", ArrayUtils.toString(
0096: new String[] { null }, "<empty>"));
0097: assertEquals("{pink,blue}", ArrayUtils.toString(new String[] {
0098: "pink", "blue" }, "<empty>"));
0099: }
0100:
0101: //-----------------------------------------------------------------------
0102: public void testHashCode() {
0103: long[][] array1 = new long[][] { { 2, 5 }, { 4, 5 } };
0104: long[][] array2 = new long[][] { { 2, 5 }, { 4, 6 } };
0105: assertEquals(true, ArrayUtils.hashCode(array1) == ArrayUtils
0106: .hashCode(array1));
0107: assertEquals(false, ArrayUtils.hashCode(array1) == ArrayUtils
0108: .hashCode(array2));
0109:
0110: Object[] array3 = new Object[] { new String(new char[] { 'A',
0111: 'B' }) };
0112: Object[] array4 = new Object[] { "AB" };
0113: assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils
0114: .hashCode(array3));
0115: assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils
0116: .hashCode(array4));
0117: }
0118:
0119: //-----------------------------------------------------------------------
0120: private void assertIsEquals(Object array1, Object array2,
0121: Object array3) {
0122: assertEquals(true, ArrayUtils.isEquals(array1, array1));
0123: assertEquals(true, ArrayUtils.isEquals(array2, array2));
0124: assertEquals(true, ArrayUtils.isEquals(array3, array3));
0125: assertEquals(false, ArrayUtils.isEquals(array1, array2));
0126: assertEquals(false, ArrayUtils.isEquals(array2, array1));
0127: assertEquals(false, ArrayUtils.isEquals(array1, array3));
0128: assertEquals(false, ArrayUtils.isEquals(array3, array1));
0129: assertEquals(false, ArrayUtils.isEquals(array1, array2));
0130: assertEquals(false, ArrayUtils.isEquals(array2, array1));
0131: }
0132:
0133: public void testIsEquals() {
0134: long[][] larray1 = new long[][] { { 2, 5 }, { 4, 5 } };
0135: long[][] larray2 = new long[][] { { 2, 5 }, { 4, 6 } };
0136: long[] larray3 = new long[] { 2, 5 };
0137: this .assertIsEquals(larray1, larray2, larray3);
0138:
0139: int[][] iarray1 = new int[][] { { 2, 5 }, { 4, 5 } };
0140: int[][] iarray2 = new int[][] { { 2, 5 }, { 4, 6 } };
0141: int[] iarray3 = new int[] { 2, 5 };
0142: this .assertIsEquals(iarray1, iarray2, iarray3);
0143:
0144: short[][] sarray1 = new short[][] { { 2, 5 }, { 4, 5 } };
0145: short[][] sarray2 = new short[][] { { 2, 5 }, { 4, 6 } };
0146: short[] sarray3 = new short[] { 2, 5 };
0147: this .assertIsEquals(sarray1, sarray2, sarray3);
0148:
0149: float[][] farray1 = new float[][] { { 2, 5 }, { 4, 5 } };
0150: float[][] farray2 = new float[][] { { 2, 5 }, { 4, 6 } };
0151: float[] farray3 = new float[] { 2, 5 };
0152: this .assertIsEquals(farray1, farray2, farray3);
0153:
0154: double[][] darray1 = new double[][] { { 2, 5 }, { 4, 5 } };
0155: double[][] darray2 = new double[][] { { 2, 5 }, { 4, 6 } };
0156: double[] darray3 = new double[] { 2, 5 };
0157: this .assertIsEquals(darray1, darray2, darray3);
0158:
0159: byte[][] byteArray1 = new byte[][] { { 2, 5 }, { 4, 5 } };
0160: byte[][] byteArray2 = new byte[][] { { 2, 5 }, { 4, 6 } };
0161: byte[] byteArray3 = new byte[] { 2, 5 };
0162: this .assertIsEquals(byteArray1, byteArray2, byteArray3);
0163:
0164: char[][] charArray1 = new char[][] { { 2, 5 }, { 4, 5 } };
0165: char[][] charArray2 = new char[][] { { 2, 5 }, { 4, 6 } };
0166: char[] charArray3 = new char[] { 2, 5 };
0167: this .assertIsEquals(charArray1, charArray2, charArray3);
0168:
0169: boolean[][] barray1 = new boolean[][] { { true, false },
0170: { true, true } };
0171: boolean[][] barray2 = new boolean[][] { { true, false },
0172: { true, false } };
0173: boolean[] barray3 = new boolean[] { false, true };
0174: this .assertIsEquals(barray1, barray2, barray3);
0175:
0176: Object[] array3 = new Object[] { new String(new char[] { 'A',
0177: 'B' }) };
0178: Object[] array4 = new Object[] { "AB" };
0179: assertEquals(true, ArrayUtils.isEquals(array3, array3));
0180: assertEquals(true, ArrayUtils.isEquals(array3, array4));
0181:
0182: assertEquals(true, ArrayUtils.isEquals(null, null));
0183: assertEquals(false, ArrayUtils.isEquals(null, array4));
0184: }
0185:
0186: //-----------------------------------------------------------------------
0187: public void testToMap() {
0188: Map map = ArrayUtils.toMap(new String[][] { { "foo", "bar" },
0189: { "hello", "world" } });
0190:
0191: assertEquals("bar", map.get("foo"));
0192: assertEquals("world", map.get("hello"));
0193:
0194: assertEquals(null, ArrayUtils.toMap(null));
0195: try {
0196: ArrayUtils.toMap(new String[][] { { "foo", "bar" },
0197: { "short" } });
0198: fail("exception expected");
0199: } catch (IllegalArgumentException ex) {
0200: }
0201: try {
0202: ArrayUtils.toMap(new Object[] {
0203: new Object[] { "foo", "bar" }, "illegal type" });
0204: fail("exception expected");
0205: } catch (IllegalArgumentException ex) {
0206: }
0207: try {
0208: ArrayUtils.toMap(new Object[] {
0209: new Object[] { "foo", "bar" }, null });
0210: fail("exception expected");
0211: } catch (IllegalArgumentException ex) {
0212: }
0213:
0214: map = ArrayUtils.toMap(new Object[] { new Map.Entry() {
0215: public Object getKey() {
0216: return "foo";
0217: }
0218:
0219: public Object getValue() {
0220: return "bar";
0221: }
0222:
0223: public Object setValue(Object value) {
0224: throw new UnsupportedOperationException();
0225: }
0226:
0227: public boolean equals(Object o) {
0228: throw new UnsupportedOperationException();
0229: }
0230:
0231: public int hashCode() {
0232: throw new UnsupportedOperationException();
0233: }
0234: } });
0235: assertEquals("bar", map.get("foo"));
0236: }
0237:
0238: //-----------------------------------------------------------------------
0239: public void testClone() {
0240: assertEquals(null, ArrayUtils.clone((Object[]) null));
0241: Object[] original1 = new Object[0];
0242: Object[] cloned1 = ArrayUtils.clone(original1);
0243: assertTrue(Arrays.equals(original1, cloned1));
0244: assertTrue(original1 != cloned1);
0245:
0246: StringBuffer buf = new StringBuffer("pick");
0247: original1 = new Object[] { buf, "a", new String[] { "stick" } };
0248: cloned1 = ArrayUtils.clone(original1);
0249: assertTrue(Arrays.equals(original1, cloned1));
0250: assertTrue(original1 != cloned1);
0251: assertSame(original1[0], cloned1[0]);
0252: assertSame(original1[1], cloned1[1]);
0253: assertSame(original1[2], cloned1[2]);
0254: }
0255:
0256: public void testCloneBoolean() {
0257: assertEquals(null, ArrayUtils.clone((boolean[]) null));
0258: boolean[] original = new boolean[] { true, false };
0259: boolean[] cloned = ArrayUtils.clone(original);
0260: assertTrue(Arrays.equals(original, cloned));
0261: assertTrue(original != cloned);
0262: }
0263:
0264: public void testCloneLong() {
0265: assertEquals(null, ArrayUtils.clone((long[]) null));
0266: long[] original = new long[] { 0L, 1L };
0267: long[] cloned = ArrayUtils.clone(original);
0268: assertTrue(Arrays.equals(original, cloned));
0269: assertTrue(original != cloned);
0270: }
0271:
0272: public void testCloneInt() {
0273: assertEquals(null, ArrayUtils.clone((int[]) null));
0274: int[] original = new int[] { 5, 8 };
0275: int[] cloned = ArrayUtils.clone(original);
0276: assertTrue(Arrays.equals(original, cloned));
0277: assertTrue(original != cloned);
0278: }
0279:
0280: public void testCloneShort() {
0281: assertEquals(null, ArrayUtils.clone((short[]) null));
0282: short[] original = new short[] { 1, 4 };
0283: short[] cloned = ArrayUtils.clone(original);
0284: assertTrue(Arrays.equals(original, cloned));
0285: assertTrue(original != cloned);
0286: }
0287:
0288: public void testCloneChar() {
0289: assertEquals(null, ArrayUtils.clone((char[]) null));
0290: char[] original = new char[] { 'a', '4' };
0291: char[] cloned = ArrayUtils.clone(original);
0292: assertTrue(Arrays.equals(original, cloned));
0293: assertTrue(original != cloned);
0294: }
0295:
0296: public void testCloneByte() {
0297: assertEquals(null, ArrayUtils.clone((byte[]) null));
0298: byte[] original = new byte[] { 1, 6 };
0299: byte[] cloned = ArrayUtils.clone(original);
0300: assertTrue(Arrays.equals(original, cloned));
0301: assertTrue(original != cloned);
0302: }
0303:
0304: public void testCloneDouble() {
0305: assertEquals(null, ArrayUtils.clone((double[]) null));
0306: double[] original = new double[] { 2.4d, 5.7d };
0307: double[] cloned = ArrayUtils.clone(original);
0308: assertTrue(Arrays.equals(original, cloned));
0309: assertTrue(original != cloned);
0310: }
0311:
0312: public void testCloneFloat() {
0313: assertEquals(null, ArrayUtils.clone((float[]) null));
0314: float[] original = new float[] { 2.6f, 6.4f };
0315: float[] cloned = ArrayUtils.clone(original);
0316: assertTrue(Arrays.equals(original, cloned));
0317: assertTrue(original != cloned);
0318: }
0319:
0320: //-----------------------------------------------------------------------
0321:
0322: public void testSubarrayObject() {
0323: Object[] nullArray = null;
0324: Object[] objectArray = { "a", "b", "c", "d", "e", "f" };
0325:
0326: assertEquals("0 start, mid end", "abcd", StringUtils
0327: .join(ArrayUtils.subarray(objectArray, 0, 4)));
0328: assertEquals("0 start, length end", "abcdef", StringUtils
0329: .join(ArrayUtils.subarray(objectArray, 0,
0330: objectArray.length)));
0331: assertEquals("mid start, mid end", "bcd", StringUtils
0332: .join(ArrayUtils.subarray(objectArray, 1, 4)));
0333: assertEquals("mid start, length end", "bcdef", StringUtils
0334: .join(ArrayUtils.subarray(objectArray, 1,
0335: objectArray.length)));
0336:
0337: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0338: assertEquals("empty array", "", StringUtils.join(ArrayUtils
0339: .subarray(ArrayUtils.EMPTY_OBJECT_ARRAY, 1, 2)));
0340: assertEquals("start > end", "", StringUtils.join(ArrayUtils
0341: .subarray(objectArray, 4, 2)));
0342: assertEquals("start == end", "", StringUtils.join(ArrayUtils
0343: .subarray(objectArray, 3, 3)));
0344: assertEquals("start undershoot, normal end", "abcd",
0345: StringUtils.join(ArrayUtils
0346: .subarray(objectArray, -2, 4)));
0347: assertEquals("start overshoot, any end", "", StringUtils
0348: .join(ArrayUtils.subarray(objectArray, 33, 4)));
0349: assertEquals("normal start, end overshoot", "cdef", StringUtils
0350: .join(ArrayUtils.subarray(objectArray, 2, 33)));
0351: assertEquals("start undershoot, end overshoot", "abcdef",
0352: StringUtils.join(ArrayUtils.subarray(objectArray, -2,
0353: 12)));
0354:
0355: // array type tests
0356: Date[] dateArray = { new java.sql.Date(new Date().getTime()),
0357: new Date(), new Date(), new Date(), new Date() };
0358:
0359: assertSame("Object type", Object.class, ArrayUtils.subarray(
0360: objectArray, 2, 4).getClass().getComponentType());
0361: assertSame("java.util.Date type", java.util.Date.class,
0362: ArrayUtils.subarray(dateArray, 1, 4).getClass()
0363: .getComponentType());
0364: assertNotSame("java.sql.Date type", java.sql.Date.class,
0365: ArrayUtils.subarray(dateArray, 1, 4).getClass()
0366: .getComponentType());
0367: try {
0368: Object dummy = (java.sql.Date[]) ArrayUtils.subarray(
0369: dateArray, 1, 3);
0370: fail("Invalid downcast");
0371: } catch (ClassCastException e) {
0372: }
0373: }
0374:
0375: public void testSubarrayLong() {
0376: long[] nullArray = null;
0377: long[] array = { 999910, 999911, 999912, 999913, 999914, 999915 };
0378: long[] leftSubarray = { 999910, 999911, 999912, 999913 };
0379: long[] midSubarray = { 999911, 999912, 999913, 999914 };
0380: long[] rightSubarray = { 999912, 999913, 999914, 999915 };
0381:
0382: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0383: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0384:
0385: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0386: ArrayUtils.subarray(array, 0, array.length)));
0387:
0388: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0389: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0390:
0391: assertTrue("mid start, length end", ArrayUtils.isEquals(
0392: rightSubarray, ArrayUtils.subarray(array, 2,
0393: array.length)));
0394:
0395: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0396:
0397: assertEquals("empty array", ArrayUtils.EMPTY_LONG_ARRAY,
0398: ArrayUtils.subarray(ArrayUtils.EMPTY_LONG_ARRAY, 1, 2));
0399:
0400: assertEquals("start > end", ArrayUtils.EMPTY_LONG_ARRAY,
0401: ArrayUtils.subarray(array, 4, 2));
0402:
0403: assertEquals("start == end", ArrayUtils.EMPTY_LONG_ARRAY,
0404: ArrayUtils.subarray(array, 3, 3));
0405:
0406: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0407: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0408:
0409: assertEquals("start overshoot, any end",
0410: ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.subarray(array,
0411: 33, 4));
0412:
0413: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0414: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0415:
0416: assertTrue("start undershoot, end overshoot", ArrayUtils
0417: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0418:
0419: // empty-return tests
0420:
0421: assertSame("empty array, object test",
0422: ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.subarray(
0423: ArrayUtils.EMPTY_LONG_ARRAY, 1, 2));
0424:
0425: assertSame("start > end, object test",
0426: ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.subarray(array,
0427: 4, 1));
0428:
0429: assertSame("start == end, object test",
0430: ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.subarray(array,
0431: 3, 3));
0432:
0433: assertSame("start overshoot, any end, object test",
0434: ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.subarray(array,
0435: 8733, 4));
0436:
0437: // array type tests
0438:
0439: assertSame("long type", long.class, ArrayUtils.subarray(array,
0440: 2, 4).getClass().getComponentType());
0441:
0442: }
0443:
0444: public void testSubarrayInt() {
0445: int[] nullArray = null;
0446: int[] array = { 10, 11, 12, 13, 14, 15 };
0447: int[] leftSubarray = { 10, 11, 12, 13 };
0448: int[] midSubarray = { 11, 12, 13, 14 };
0449: int[] rightSubarray = { 12, 13, 14, 15 };
0450:
0451: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0452: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0453:
0454: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0455: ArrayUtils.subarray(array, 0, array.length)));
0456:
0457: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0458: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0459:
0460: assertTrue("mid start, length end", ArrayUtils.isEquals(
0461: rightSubarray, ArrayUtils.subarray(array, 2,
0462: array.length)));
0463:
0464: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0465:
0466: assertEquals("empty array", ArrayUtils.EMPTY_INT_ARRAY,
0467: ArrayUtils.subarray(ArrayUtils.EMPTY_INT_ARRAY, 1, 2));
0468:
0469: assertEquals("start > end", ArrayUtils.EMPTY_INT_ARRAY,
0470: ArrayUtils.subarray(array, 4, 2));
0471:
0472: assertEquals("start == end", ArrayUtils.EMPTY_INT_ARRAY,
0473: ArrayUtils.subarray(array, 3, 3));
0474:
0475: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0476: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0477:
0478: assertEquals("start overshoot, any end",
0479: ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.subarray(array,
0480: 33, 4));
0481:
0482: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0483: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0484:
0485: assertTrue("start undershoot, end overshoot", ArrayUtils
0486: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0487:
0488: // empty-return tests
0489:
0490: assertSame("empty array, object test",
0491: ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.subarray(
0492: ArrayUtils.EMPTY_INT_ARRAY, 1, 2));
0493:
0494: assertSame("start > end, object test",
0495: ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.subarray(array,
0496: 4, 1));
0497:
0498: assertSame("start == end, object test",
0499: ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.subarray(array,
0500: 3, 3));
0501:
0502: assertSame("start overshoot, any end, object test",
0503: ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.subarray(array,
0504: 8733, 4));
0505:
0506: // array type tests
0507:
0508: assertSame("int type", int.class, ArrayUtils.subarray(array, 2,
0509: 4).getClass().getComponentType());
0510:
0511: }
0512:
0513: public void testSubarrayShort() {
0514: short[] nullArray = null;
0515: short[] array = { 10, 11, 12, 13, 14, 15 };
0516: short[] leftSubarray = { 10, 11, 12, 13 };
0517: short[] midSubarray = { 11, 12, 13, 14 };
0518: short[] rightSubarray = { 12, 13, 14, 15 };
0519:
0520: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0521: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0522:
0523: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0524: ArrayUtils.subarray(array, 0, array.length)));
0525:
0526: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0527: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0528:
0529: assertTrue("mid start, length end", ArrayUtils.isEquals(
0530: rightSubarray, ArrayUtils.subarray(array, 2,
0531: array.length)));
0532:
0533: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0534:
0535: assertEquals("empty array", ArrayUtils.EMPTY_SHORT_ARRAY,
0536: ArrayUtils.subarray(ArrayUtils.EMPTY_SHORT_ARRAY, 1, 2));
0537:
0538: assertEquals("start > end", ArrayUtils.EMPTY_SHORT_ARRAY,
0539: ArrayUtils.subarray(array, 4, 2));
0540:
0541: assertEquals("start == end", ArrayUtils.EMPTY_SHORT_ARRAY,
0542: ArrayUtils.subarray(array, 3, 3));
0543:
0544: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0545: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0546:
0547: assertEquals("start overshoot, any end",
0548: ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.subarray(
0549: array, 33, 4));
0550:
0551: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0552: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0553:
0554: assertTrue("start undershoot, end overshoot", ArrayUtils
0555: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0556:
0557: // empty-return tests
0558:
0559: assertSame("empty array, object test",
0560: ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.subarray(
0561: ArrayUtils.EMPTY_SHORT_ARRAY, 1, 2));
0562:
0563: assertSame("start > end, object test",
0564: ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.subarray(
0565: array, 4, 1));
0566:
0567: assertSame("start == end, object test",
0568: ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.subarray(
0569: array, 3, 3));
0570:
0571: assertSame("start overshoot, any end, object test",
0572: ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils.subarray(
0573: array, 8733, 4));
0574:
0575: // array type tests
0576:
0577: assertSame("short type", short.class, ArrayUtils.subarray(
0578: array, 2, 4).getClass().getComponentType());
0579:
0580: }
0581:
0582: public void testSubarrChar() {
0583: char[] nullArray = null;
0584: char[] array = { 'a', 'b', 'c', 'd', 'e', 'f' };
0585: char[] leftSubarray = { 'a', 'b', 'c', 'd', };
0586: char[] midSubarray = { 'b', 'c', 'd', 'e', };
0587: char[] rightSubarray = { 'c', 'd', 'e', 'f', };
0588:
0589: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0590: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0591:
0592: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0593: ArrayUtils.subarray(array, 0, array.length)));
0594:
0595: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0596: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0597:
0598: assertTrue("mid start, length end", ArrayUtils.isEquals(
0599: rightSubarray, ArrayUtils.subarray(array, 2,
0600: array.length)));
0601:
0602: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0603:
0604: assertEquals("empty array", ArrayUtils.EMPTY_CHAR_ARRAY,
0605: ArrayUtils.subarray(ArrayUtils.EMPTY_CHAR_ARRAY, 1, 2));
0606:
0607: assertEquals("start > end", ArrayUtils.EMPTY_CHAR_ARRAY,
0608: ArrayUtils.subarray(array, 4, 2));
0609:
0610: assertEquals("start == end", ArrayUtils.EMPTY_CHAR_ARRAY,
0611: ArrayUtils.subarray(array, 3, 3));
0612:
0613: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0614: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0615:
0616: assertEquals("start overshoot, any end",
0617: ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.subarray(array,
0618: 33, 4));
0619:
0620: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0621: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0622:
0623: assertTrue("start undershoot, end overshoot", ArrayUtils
0624: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0625:
0626: // empty-return tests
0627:
0628: assertSame("empty array, object test",
0629: ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.subarray(
0630: ArrayUtils.EMPTY_CHAR_ARRAY, 1, 2));
0631:
0632: assertSame("start > end, object test",
0633: ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.subarray(array,
0634: 4, 1));
0635:
0636: assertSame("start == end, object test",
0637: ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.subarray(array,
0638: 3, 3));
0639:
0640: assertSame("start overshoot, any end, object test",
0641: ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.subarray(array,
0642: 8733, 4));
0643:
0644: // array type tests
0645:
0646: assertSame("char type", char.class, ArrayUtils.subarray(array,
0647: 2, 4).getClass().getComponentType());
0648:
0649: }
0650:
0651: public void testSubarrayByte() {
0652: byte[] nullArray = null;
0653: byte[] array = { 10, 11, 12, 13, 14, 15 };
0654: byte[] leftSubarray = { 10, 11, 12, 13 };
0655: byte[] midSubarray = { 11, 12, 13, 14 };
0656: byte[] rightSubarray = { 12, 13, 14, 15 };
0657:
0658: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0659: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0660:
0661: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0662: ArrayUtils.subarray(array, 0, array.length)));
0663:
0664: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0665: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0666:
0667: assertTrue("mid start, length end", ArrayUtils.isEquals(
0668: rightSubarray, ArrayUtils.subarray(array, 2,
0669: array.length)));
0670:
0671: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0672:
0673: assertEquals("empty array", ArrayUtils.EMPTY_BYTE_ARRAY,
0674: ArrayUtils.subarray(ArrayUtils.EMPTY_BYTE_ARRAY, 1, 2));
0675:
0676: assertEquals("start > end", ArrayUtils.EMPTY_BYTE_ARRAY,
0677: ArrayUtils.subarray(array, 4, 2));
0678:
0679: assertEquals("start == end", ArrayUtils.EMPTY_BYTE_ARRAY,
0680: ArrayUtils.subarray(array, 3, 3));
0681:
0682: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0683: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0684:
0685: assertEquals("start overshoot, any end",
0686: ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.subarray(array,
0687: 33, 4));
0688:
0689: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0690: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0691:
0692: assertTrue("start undershoot, end overshoot", ArrayUtils
0693: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0694:
0695: // empty-return tests
0696:
0697: assertSame("empty array, object test",
0698: ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.subarray(
0699: ArrayUtils.EMPTY_BYTE_ARRAY, 1, 2));
0700:
0701: assertSame("start > end, object test",
0702: ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.subarray(array,
0703: 4, 1));
0704:
0705: assertSame("start == end, object test",
0706: ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.subarray(array,
0707: 3, 3));
0708:
0709: assertSame("start overshoot, any end, object test",
0710: ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.subarray(array,
0711: 8733, 4));
0712:
0713: // array type tests
0714:
0715: assertSame("byte type", byte.class, ArrayUtils.subarray(array,
0716: 2, 4).getClass().getComponentType());
0717:
0718: }
0719:
0720: public void testSubarrayDouble() {
0721: double[] nullArray = null;
0722: double[] array = { 10.123, 11.234, 12.345, 13.456, 14.567,
0723: 15.678 };
0724: double[] leftSubarray = { 10.123, 11.234, 12.345, 13.456, };
0725: double[] midSubarray = { 11.234, 12.345, 13.456, 14.567, };
0726: double[] rightSubarray = { 12.345, 13.456, 14.567, 15.678 };
0727:
0728: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0729: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0730:
0731: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0732: ArrayUtils.subarray(array, 0, array.length)));
0733:
0734: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0735: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0736:
0737: assertTrue("mid start, length end", ArrayUtils.isEquals(
0738: rightSubarray, ArrayUtils.subarray(array, 2,
0739: array.length)));
0740:
0741: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0742:
0743: assertEquals("empty array", ArrayUtils.EMPTY_DOUBLE_ARRAY,
0744: ArrayUtils
0745: .subarray(ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2));
0746:
0747: assertEquals("start > end", ArrayUtils.EMPTY_DOUBLE_ARRAY,
0748: ArrayUtils.subarray(array, 4, 2));
0749:
0750: assertEquals("start == end", ArrayUtils.EMPTY_DOUBLE_ARRAY,
0751: ArrayUtils.subarray(array, 3, 3));
0752:
0753: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0754: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0755:
0756: assertEquals("start overshoot, any end",
0757: ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.subarray(
0758: array, 33, 4));
0759:
0760: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0761: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0762:
0763: assertTrue("start undershoot, end overshoot", ArrayUtils
0764: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0765:
0766: // empty-return tests
0767:
0768: assertSame("empty array, object test",
0769: ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.subarray(
0770: ArrayUtils.EMPTY_DOUBLE_ARRAY, 1, 2));
0771:
0772: assertSame("start > end, object test",
0773: ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.subarray(
0774: array, 4, 1));
0775:
0776: assertSame("start == end, object test",
0777: ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.subarray(
0778: array, 3, 3));
0779:
0780: assertSame("start overshoot, any end, object test",
0781: ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils.subarray(
0782: array, 8733, 4));
0783:
0784: // array type tests
0785:
0786: assertSame("double type", double.class, ArrayUtils.subarray(
0787: array, 2, 4).getClass().getComponentType());
0788:
0789: }
0790:
0791: public void testSubarrayFloat() {
0792: float[] nullArray = null;
0793: float[] array = { 10, 11, 12, 13, 14, 15 };
0794: float[] leftSubarray = { 10, 11, 12, 13 };
0795: float[] midSubarray = { 11, 12, 13, 14 };
0796: float[] rightSubarray = { 12, 13, 14, 15 };
0797:
0798: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0799: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0800:
0801: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0802: ArrayUtils.subarray(array, 0, array.length)));
0803:
0804: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0805: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0806:
0807: assertTrue("mid start, length end", ArrayUtils.isEquals(
0808: rightSubarray, ArrayUtils.subarray(array, 2,
0809: array.length)));
0810:
0811: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0812:
0813: assertEquals("empty array", ArrayUtils.EMPTY_FLOAT_ARRAY,
0814: ArrayUtils.subarray(ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 2));
0815:
0816: assertEquals("start > end", ArrayUtils.EMPTY_FLOAT_ARRAY,
0817: ArrayUtils.subarray(array, 4, 2));
0818:
0819: assertEquals("start == end", ArrayUtils.EMPTY_FLOAT_ARRAY,
0820: ArrayUtils.subarray(array, 3, 3));
0821:
0822: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0823: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0824:
0825: assertEquals("start overshoot, any end",
0826: ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.subarray(
0827: array, 33, 4));
0828:
0829: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0830: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0831:
0832: assertTrue("start undershoot, end overshoot", ArrayUtils
0833: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0834:
0835: // empty-return tests
0836:
0837: assertSame("empty array, object test",
0838: ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.subarray(
0839: ArrayUtils.EMPTY_FLOAT_ARRAY, 1, 2));
0840:
0841: assertSame("start > end, object test",
0842: ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.subarray(
0843: array, 4, 1));
0844:
0845: assertSame("start == end, object test",
0846: ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.subarray(
0847: array, 3, 3));
0848:
0849: assertSame("start overshoot, any end, object test",
0850: ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils.subarray(
0851: array, 8733, 4));
0852:
0853: // array type tests
0854:
0855: assertSame("float type", float.class, ArrayUtils.subarray(
0856: array, 2, 4).getClass().getComponentType());
0857:
0858: }
0859:
0860: public void testSubarrayBoolean() {
0861: boolean[] nullArray = null;
0862: boolean[] array = { true, true, false, true, false, true };
0863: boolean[] leftSubarray = { true, true, false, true };
0864: boolean[] midSubarray = { true, false, true, false };
0865: boolean[] rightSubarray = { false, true, false, true };
0866:
0867: assertTrue("0 start, mid end", ArrayUtils.isEquals(
0868: leftSubarray, ArrayUtils.subarray(array, 0, 4)));
0869:
0870: assertTrue("0 start, length end", ArrayUtils.isEquals(array,
0871: ArrayUtils.subarray(array, 0, array.length)));
0872:
0873: assertTrue("mid start, mid end", ArrayUtils.isEquals(
0874: midSubarray, ArrayUtils.subarray(array, 1, 5)));
0875:
0876: assertTrue("mid start, length end", ArrayUtils.isEquals(
0877: rightSubarray, ArrayUtils.subarray(array, 2,
0878: array.length)));
0879:
0880: assertNull("null input", ArrayUtils.subarray(nullArray, 0, 3));
0881:
0882: assertEquals("empty array", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
0883: ArrayUtils.subarray(ArrayUtils.EMPTY_BOOLEAN_ARRAY, 1,
0884: 2));
0885:
0886: assertEquals("start > end", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
0887: ArrayUtils.subarray(array, 4, 2));
0888:
0889: assertEquals("start == end", ArrayUtils.EMPTY_BOOLEAN_ARRAY,
0890: ArrayUtils.subarray(array, 3, 3));
0891:
0892: assertTrue("start undershoot, normal end", ArrayUtils.isEquals(
0893: leftSubarray, ArrayUtils.subarray(array, -2, 4)));
0894:
0895: assertEquals("start overshoot, any end",
0896: ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.subarray(
0897: array, 33, 4));
0898:
0899: assertTrue("normal start, end overshoot", ArrayUtils.isEquals(
0900: rightSubarray, ArrayUtils.subarray(array, 2, 33)));
0901:
0902: assertTrue("start undershoot, end overshoot", ArrayUtils
0903: .isEquals(array, ArrayUtils.subarray(array, -2, 12)));
0904:
0905: // empty-return tests
0906:
0907: assertSame("empty array, object test",
0908: ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.subarray(
0909: ArrayUtils.EMPTY_BOOLEAN_ARRAY, 1, 2));
0910:
0911: assertSame("start > end, object test",
0912: ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.subarray(
0913: array, 4, 1));
0914:
0915: assertSame("start == end, object test",
0916: ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.subarray(
0917: array, 3, 3));
0918:
0919: assertSame("start overshoot, any end, object test",
0920: ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils.subarray(
0921: array, 8733, 4));
0922:
0923: // array type tests
0924:
0925: assertSame("boolean type", boolean.class, ArrayUtils.subarray(
0926: array, 2, 4).getClass().getComponentType());
0927:
0928: }
0929:
0930: //-----------------------------------------------------------------------
0931: public void testSameLength() {
0932: Object[] nullArray = null;
0933: Object[] emptyArray = new Object[0];
0934: Object[] oneArray = new Object[] { "pick" };
0935: Object[] twoArray = new Object[] { "pick", "stick" };
0936:
0937: assertEquals(true, ArrayUtils
0938: .isSameLength(nullArray, nullArray));
0939: assertEquals(true, ArrayUtils.isSameLength(nullArray,
0940: emptyArray));
0941: assertEquals(false, ArrayUtils
0942: .isSameLength(nullArray, oneArray));
0943: assertEquals(false, ArrayUtils
0944: .isSameLength(nullArray, twoArray));
0945:
0946: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
0947: nullArray));
0948: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
0949: emptyArray));
0950: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
0951: oneArray));
0952: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
0953: twoArray));
0954:
0955: assertEquals(false, ArrayUtils
0956: .isSameLength(oneArray, nullArray));
0957: assertEquals(false, ArrayUtils.isSameLength(oneArray,
0958: emptyArray));
0959: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
0960: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
0961:
0962: assertEquals(false, ArrayUtils
0963: .isSameLength(twoArray, nullArray));
0964: assertEquals(false, ArrayUtils.isSameLength(twoArray,
0965: emptyArray));
0966: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
0967: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
0968: }
0969:
0970: public void testSameLengthBoolean() {
0971: boolean[] nullArray = null;
0972: boolean[] emptyArray = new boolean[0];
0973: boolean[] oneArray = new boolean[] { true };
0974: boolean[] twoArray = new boolean[] { true, false };
0975:
0976: assertEquals(true, ArrayUtils
0977: .isSameLength(nullArray, nullArray));
0978: assertEquals(true, ArrayUtils.isSameLength(nullArray,
0979: emptyArray));
0980: assertEquals(false, ArrayUtils
0981: .isSameLength(nullArray, oneArray));
0982: assertEquals(false, ArrayUtils
0983: .isSameLength(nullArray, twoArray));
0984:
0985: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
0986: nullArray));
0987: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
0988: emptyArray));
0989: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
0990: oneArray));
0991: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
0992: twoArray));
0993:
0994: assertEquals(false, ArrayUtils
0995: .isSameLength(oneArray, nullArray));
0996: assertEquals(false, ArrayUtils.isSameLength(oneArray,
0997: emptyArray));
0998: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
0999: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1000:
1001: assertEquals(false, ArrayUtils
1002: .isSameLength(twoArray, nullArray));
1003: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1004: emptyArray));
1005: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1006: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1007: }
1008:
1009: public void testSameLengthLong() {
1010: long[] nullArray = null;
1011: long[] emptyArray = new long[0];
1012: long[] oneArray = new long[] { 0L };
1013: long[] twoArray = new long[] { 0L, 76L };
1014:
1015: assertEquals(true, ArrayUtils
1016: .isSameLength(nullArray, nullArray));
1017: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1018: emptyArray));
1019: assertEquals(false, ArrayUtils
1020: .isSameLength(nullArray, oneArray));
1021: assertEquals(false, ArrayUtils
1022: .isSameLength(nullArray, twoArray));
1023:
1024: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1025: nullArray));
1026: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1027: emptyArray));
1028: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1029: oneArray));
1030: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1031: twoArray));
1032:
1033: assertEquals(false, ArrayUtils
1034: .isSameLength(oneArray, nullArray));
1035: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1036: emptyArray));
1037: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1038: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1039:
1040: assertEquals(false, ArrayUtils
1041: .isSameLength(twoArray, nullArray));
1042: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1043: emptyArray));
1044: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1045: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1046: }
1047:
1048: public void testSameLengthInt() {
1049: int[] nullArray = null;
1050: int[] emptyArray = new int[0];
1051: int[] oneArray = new int[] { 4 };
1052: int[] twoArray = new int[] { 5, 7 };
1053:
1054: assertEquals(true, ArrayUtils
1055: .isSameLength(nullArray, nullArray));
1056: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1057: emptyArray));
1058: assertEquals(false, ArrayUtils
1059: .isSameLength(nullArray, oneArray));
1060: assertEquals(false, ArrayUtils
1061: .isSameLength(nullArray, twoArray));
1062:
1063: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1064: nullArray));
1065: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1066: emptyArray));
1067: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1068: oneArray));
1069: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1070: twoArray));
1071:
1072: assertEquals(false, ArrayUtils
1073: .isSameLength(oneArray, nullArray));
1074: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1075: emptyArray));
1076: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1077: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1078:
1079: assertEquals(false, ArrayUtils
1080: .isSameLength(twoArray, nullArray));
1081: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1082: emptyArray));
1083: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1084: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1085: }
1086:
1087: public void testSameLengthShort() {
1088: short[] nullArray = null;
1089: short[] emptyArray = new short[0];
1090: short[] oneArray = new short[] { 4 };
1091: short[] twoArray = new short[] { 6, 8 };
1092:
1093: assertEquals(true, ArrayUtils
1094: .isSameLength(nullArray, nullArray));
1095: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1096: emptyArray));
1097: assertEquals(false, ArrayUtils
1098: .isSameLength(nullArray, oneArray));
1099: assertEquals(false, ArrayUtils
1100: .isSameLength(nullArray, twoArray));
1101:
1102: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1103: nullArray));
1104: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1105: emptyArray));
1106: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1107: oneArray));
1108: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1109: twoArray));
1110:
1111: assertEquals(false, ArrayUtils
1112: .isSameLength(oneArray, nullArray));
1113: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1114: emptyArray));
1115: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1116: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1117:
1118: assertEquals(false, ArrayUtils
1119: .isSameLength(twoArray, nullArray));
1120: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1121: emptyArray));
1122: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1123: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1124: }
1125:
1126: public void testSameLengthChar() {
1127: char[] nullArray = null;
1128: char[] emptyArray = new char[0];
1129: char[] oneArray = new char[] { 'f' };
1130: char[] twoArray = new char[] { 'd', 't' };
1131:
1132: assertEquals(true, ArrayUtils
1133: .isSameLength(nullArray, nullArray));
1134: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1135: emptyArray));
1136: assertEquals(false, ArrayUtils
1137: .isSameLength(nullArray, oneArray));
1138: assertEquals(false, ArrayUtils
1139: .isSameLength(nullArray, twoArray));
1140:
1141: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1142: nullArray));
1143: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1144: emptyArray));
1145: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1146: oneArray));
1147: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1148: twoArray));
1149:
1150: assertEquals(false, ArrayUtils
1151: .isSameLength(oneArray, nullArray));
1152: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1153: emptyArray));
1154: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1155: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1156:
1157: assertEquals(false, ArrayUtils
1158: .isSameLength(twoArray, nullArray));
1159: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1160: emptyArray));
1161: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1162: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1163: }
1164:
1165: public void testSameLengthByte() {
1166: byte[] nullArray = null;
1167: byte[] emptyArray = new byte[0];
1168: byte[] oneArray = new byte[] { 3 };
1169: byte[] twoArray = new byte[] { 4, 6 };
1170:
1171: assertEquals(true, ArrayUtils
1172: .isSameLength(nullArray, nullArray));
1173: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1174: emptyArray));
1175: assertEquals(false, ArrayUtils
1176: .isSameLength(nullArray, oneArray));
1177: assertEquals(false, ArrayUtils
1178: .isSameLength(nullArray, twoArray));
1179:
1180: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1181: nullArray));
1182: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1183: emptyArray));
1184: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1185: oneArray));
1186: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1187: twoArray));
1188:
1189: assertEquals(false, ArrayUtils
1190: .isSameLength(oneArray, nullArray));
1191: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1192: emptyArray));
1193: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1194: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1195:
1196: assertEquals(false, ArrayUtils
1197: .isSameLength(twoArray, nullArray));
1198: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1199: emptyArray));
1200: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1201: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1202: }
1203:
1204: public void testSameLengthDouble() {
1205: double[] nullArray = null;
1206: double[] emptyArray = new double[0];
1207: double[] oneArray = new double[] { 1.3d };
1208: double[] twoArray = new double[] { 4.5d, 6.3d };
1209:
1210: assertEquals(true, ArrayUtils
1211: .isSameLength(nullArray, nullArray));
1212: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1213: emptyArray));
1214: assertEquals(false, ArrayUtils
1215: .isSameLength(nullArray, oneArray));
1216: assertEquals(false, ArrayUtils
1217: .isSameLength(nullArray, twoArray));
1218:
1219: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1220: nullArray));
1221: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1222: emptyArray));
1223: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1224: oneArray));
1225: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1226: twoArray));
1227:
1228: assertEquals(false, ArrayUtils
1229: .isSameLength(oneArray, nullArray));
1230: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1231: emptyArray));
1232: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1233: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1234:
1235: assertEquals(false, ArrayUtils
1236: .isSameLength(twoArray, nullArray));
1237: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1238: emptyArray));
1239: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1240: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1241: }
1242:
1243: public void testSameLengthFloat() {
1244: float[] nullArray = null;
1245: float[] emptyArray = new float[0];
1246: float[] oneArray = new float[] { 2.5f };
1247: float[] twoArray = new float[] { 6.4f, 5.8f };
1248:
1249: assertEquals(true, ArrayUtils
1250: .isSameLength(nullArray, nullArray));
1251: assertEquals(true, ArrayUtils.isSameLength(nullArray,
1252: emptyArray));
1253: assertEquals(false, ArrayUtils
1254: .isSameLength(nullArray, oneArray));
1255: assertEquals(false, ArrayUtils
1256: .isSameLength(nullArray, twoArray));
1257:
1258: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1259: nullArray));
1260: assertEquals(true, ArrayUtils.isSameLength(emptyArray,
1261: emptyArray));
1262: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1263: oneArray));
1264: assertEquals(false, ArrayUtils.isSameLength(emptyArray,
1265: twoArray));
1266:
1267: assertEquals(false, ArrayUtils
1268: .isSameLength(oneArray, nullArray));
1269: assertEquals(false, ArrayUtils.isSameLength(oneArray,
1270: emptyArray));
1271: assertEquals(true, ArrayUtils.isSameLength(oneArray, oneArray));
1272: assertEquals(false, ArrayUtils.isSameLength(oneArray, twoArray));
1273:
1274: assertEquals(false, ArrayUtils
1275: .isSameLength(twoArray, nullArray));
1276: assertEquals(false, ArrayUtils.isSameLength(twoArray,
1277: emptyArray));
1278: assertEquals(false, ArrayUtils.isSameLength(twoArray, oneArray));
1279: assertEquals(true, ArrayUtils.isSameLength(twoArray, twoArray));
1280: }
1281:
1282: //-----------------------------------------------------------------------
1283: public void testSameType() {
1284: try {
1285: ArrayUtils.isSameType(null, null);
1286: fail();
1287: } catch (IllegalArgumentException ex) {
1288: }
1289: try {
1290: ArrayUtils.isSameType(null, new Object[0]);
1291: fail();
1292: } catch (IllegalArgumentException ex) {
1293: }
1294: try {
1295: ArrayUtils.isSameType(new Object[0], null);
1296: fail();
1297: } catch (IllegalArgumentException ex) {
1298: }
1299:
1300: assertEquals(true, ArrayUtils.isSameType(new Object[0],
1301: new Object[0]));
1302: assertEquals(false, ArrayUtils.isSameType(new String[0],
1303: new Object[0]));
1304: assertEquals(true, ArrayUtils.isSameType(new String[0][0],
1305: new String[0][0]));
1306: assertEquals(false, ArrayUtils.isSameType(new String[0],
1307: new String[0][0]));
1308: assertEquals(false, ArrayUtils.isSameType(new String[0][0],
1309: new String[0]));
1310: }
1311:
1312: //-----------------------------------------------------------------------
1313: public void testReverse() {
1314: StringBuffer str1 = new StringBuffer("pick");
1315: String str2 = "a";
1316: String[] str3 = new String[] { "stick" };
1317: String str4 = "up";
1318:
1319: Object[] array = new Object[] { str1, str2, str3 };
1320: ArrayUtils.reverse(array);
1321: assertEquals(array[0], str3);
1322: assertEquals(array[1], str2);
1323: assertEquals(array[2], str1);
1324:
1325: array = new Object[] { str1, str2, str3, str4 };
1326: ArrayUtils.reverse(array);
1327: assertEquals(array[0], str4);
1328: assertEquals(array[1], str3);
1329: assertEquals(array[2], str2);
1330: assertEquals(array[3], str1);
1331:
1332: array = null;
1333: ArrayUtils.reverse(array);
1334: assertEquals(null, array);
1335: }
1336:
1337: public void testReverseLong() {
1338: long[] array = new long[] { 1L, 2L, 3L };
1339: ArrayUtils.reverse(array);
1340: assertEquals(array[0], 3L);
1341: assertEquals(array[1], 2L);
1342: assertEquals(array[2], 1L);
1343:
1344: array = null;
1345: ArrayUtils.reverse(array);
1346: assertEquals(null, array);
1347: }
1348:
1349: public void testReverseInt() {
1350: int[] array = new int[] { 1, 2, 3 };
1351: ArrayUtils.reverse(array);
1352: assertEquals(array[0], 3);
1353: assertEquals(array[1], 2);
1354: assertEquals(array[2], 1);
1355:
1356: array = null;
1357: ArrayUtils.reverse(array);
1358: assertEquals(null, array);
1359: }
1360:
1361: public void testReverseShort() {
1362: short[] array = new short[] { 1, 2, 3 };
1363: ArrayUtils.reverse(array);
1364: assertEquals(array[0], 3);
1365: assertEquals(array[1], 2);
1366: assertEquals(array[2], 1);
1367:
1368: array = null;
1369: ArrayUtils.reverse(array);
1370: assertEquals(null, array);
1371: }
1372:
1373: public void testReverseChar() {
1374: char[] array = new char[] { 'a', 'f', 'C' };
1375: ArrayUtils.reverse(array);
1376: assertEquals(array[0], 'C');
1377: assertEquals(array[1], 'f');
1378: assertEquals(array[2], 'a');
1379:
1380: array = null;
1381: ArrayUtils.reverse(array);
1382: assertEquals(null, array);
1383: }
1384:
1385: public void testReverseByte() {
1386: byte[] array = new byte[] { 2, 3, 4 };
1387: ArrayUtils.reverse(array);
1388: assertEquals(array[0], 4);
1389: assertEquals(array[1], 3);
1390: assertEquals(array[2], 2);
1391:
1392: array = null;
1393: ArrayUtils.reverse(array);
1394: assertEquals(null, array);
1395: }
1396:
1397: public void testReverseDouble() {
1398: double[] array = new double[] { 0.3d, 0.4d, 0.5d };
1399: ArrayUtils.reverse(array);
1400: assertEquals(array[0], 0.5d, 0.0d);
1401: assertEquals(array[1], 0.4d, 0.0d);
1402: assertEquals(array[2], 0.3d, 0.0d);
1403:
1404: array = null;
1405: ArrayUtils.reverse(array);
1406: assertEquals(null, array);
1407: }
1408:
1409: public void testReverseFloat() {
1410: float[] array = new float[] { 0.3f, 0.4f, 0.5f };
1411: ArrayUtils.reverse(array);
1412: assertEquals(array[0], 0.5f, 0.0f);
1413: assertEquals(array[1], 0.4f, 0.0f);
1414: assertEquals(array[2], 0.3f, 0.0f);
1415:
1416: array = null;
1417: ArrayUtils.reverse(array);
1418: assertEquals(null, array);
1419: }
1420:
1421: public void testReverseBoolean() {
1422: boolean[] array = new boolean[] { false, false, true };
1423: ArrayUtils.reverse(array);
1424: assertEquals(array[0], true);
1425: assertEquals(array[1], false);
1426: assertEquals(array[2], false);
1427:
1428: array = null;
1429: ArrayUtils.reverse(array);
1430: assertEquals(null, array);
1431: }
1432:
1433: //-----------------------------------------------------------------------
1434: public void testIndexOf() {
1435: Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
1436: assertEquals(-1, ArrayUtils.indexOf(null, null));
1437: assertEquals(-1, ArrayUtils.indexOf(null, "0"));
1438: assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0"));
1439: assertEquals(0, ArrayUtils.indexOf(array, "0"));
1440: assertEquals(1, ArrayUtils.indexOf(array, "1"));
1441: assertEquals(2, ArrayUtils.indexOf(array, "2"));
1442: assertEquals(3, ArrayUtils.indexOf(array, "3"));
1443: assertEquals(4, ArrayUtils.indexOf(array, null));
1444: assertEquals(-1, ArrayUtils.indexOf(array, "notInArray"));
1445: }
1446:
1447: public void testIndexOfWithStartIndex() {
1448: Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
1449: assertEquals(-1, ArrayUtils.indexOf(null, null, 2));
1450: assertEquals(-1, ArrayUtils.indexOf(new Object[0], "0", 0));
1451: assertEquals(-1, ArrayUtils.indexOf(null, "0", 2));
1452: assertEquals(5, ArrayUtils.indexOf(array, "0", 2));
1453: assertEquals(-1, ArrayUtils.indexOf(array, "1", 2));
1454: assertEquals(2, ArrayUtils.indexOf(array, "2", 2));
1455: assertEquals(3, ArrayUtils.indexOf(array, "3", 2));
1456: assertEquals(4, ArrayUtils.indexOf(array, null, 2));
1457: assertEquals(-1, ArrayUtils.indexOf(array, "notInArray", 2));
1458:
1459: assertEquals(4, ArrayUtils.indexOf(array, null, -1));
1460: assertEquals(-1, ArrayUtils.indexOf(array, null, 8));
1461: assertEquals(-1, ArrayUtils.indexOf(array, "0", 8));
1462: }
1463:
1464: public void testLastIndexOf() {
1465: Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
1466: assertEquals(-1, ArrayUtils.lastIndexOf(null, null));
1467: assertEquals(-1, ArrayUtils.lastIndexOf(null, "0"));
1468: assertEquals(5, ArrayUtils.lastIndexOf(array, "0"));
1469: assertEquals(1, ArrayUtils.lastIndexOf(array, "1"));
1470: assertEquals(2, ArrayUtils.lastIndexOf(array, "2"));
1471: assertEquals(3, ArrayUtils.lastIndexOf(array, "3"));
1472: assertEquals(4, ArrayUtils.lastIndexOf(array, null));
1473: assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray"));
1474: }
1475:
1476: public void testLastIndexOfWithStartIndex() {
1477: Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
1478: assertEquals(-1, ArrayUtils.lastIndexOf(null, null, 2));
1479: assertEquals(-1, ArrayUtils.lastIndexOf(null, "0", 2));
1480: assertEquals(0, ArrayUtils.lastIndexOf(array, "0", 2));
1481: assertEquals(1, ArrayUtils.lastIndexOf(array, "1", 2));
1482: assertEquals(2, ArrayUtils.lastIndexOf(array, "2", 2));
1483: assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", 2));
1484: assertEquals(-1, ArrayUtils.lastIndexOf(array, "3", -1));
1485: assertEquals(4, ArrayUtils.lastIndexOf(array, null, 5));
1486: assertEquals(-1, ArrayUtils.lastIndexOf(array, null, 2));
1487: assertEquals(-1, ArrayUtils.lastIndexOf(array, "notInArray", 5));
1488:
1489: assertEquals(-1, ArrayUtils.lastIndexOf(array, null, -1));
1490: assertEquals(5, ArrayUtils.lastIndexOf(array, "0", 88));
1491: }
1492:
1493: public void testContains() {
1494: Object[] array = new Object[] { "0", "1", "2", "3", null, "0" };
1495: assertEquals(false, ArrayUtils.contains(null, null));
1496: assertEquals(false, ArrayUtils.contains(null, "1"));
1497: assertEquals(true, ArrayUtils.contains(array, "0"));
1498: assertEquals(true, ArrayUtils.contains(array, "1"));
1499: assertEquals(true, ArrayUtils.contains(array, "2"));
1500: assertEquals(true, ArrayUtils.contains(array, "3"));
1501: assertEquals(true, ArrayUtils.contains(array, null));
1502: assertEquals(false, ArrayUtils.contains(array, "notInArray"));
1503: }
1504:
1505: //-----------------------------------------------------------------------
1506: public void testIndexOfLong() {
1507: long[] array = null;
1508: assertEquals(-1, ArrayUtils.indexOf(array, 0));
1509: array = new long[] { 0, 1, 2, 3, 0 };
1510: assertEquals(0, ArrayUtils.indexOf(array, 0));
1511: assertEquals(1, ArrayUtils.indexOf(array, 1));
1512: assertEquals(2, ArrayUtils.indexOf(array, 2));
1513: assertEquals(3, ArrayUtils.indexOf(array, 3));
1514: assertEquals(-1, ArrayUtils.indexOf(array, 99));
1515: }
1516:
1517: public void testIndexOfLongWithStartIndex() {
1518: long[] array = null;
1519: assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
1520: array = new long[] { 0, 1, 2, 3, 0 };
1521: assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
1522: assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
1523: assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
1524: assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
1525: assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
1526: assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
1527: assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
1528: }
1529:
1530: public void testLastIndexOfLong() {
1531: long[] array = null;
1532: assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
1533: array = new long[] { 0, 1, 2, 3, 0 };
1534: assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
1535: assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
1536: assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
1537: assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
1538: assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1539: }
1540:
1541: public void testLastIndexOfLongWithStartIndex() {
1542: long[] array = null;
1543: assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
1544: array = new long[] { 0, 1, 2, 3, 0 };
1545: assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
1546: assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
1547: assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
1548: assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
1549: assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
1550: assertEquals(-1, ArrayUtils.lastIndexOf(array, 99, 4));
1551: assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
1552: }
1553:
1554: public void testContainsLong() {
1555: long[] array = null;
1556: assertEquals(false, ArrayUtils.contains(array, 1));
1557: array = new long[] { 0, 1, 2, 3, 0 };
1558: assertEquals(true, ArrayUtils.contains(array, 0));
1559: assertEquals(true, ArrayUtils.contains(array, 1));
1560: assertEquals(true, ArrayUtils.contains(array, 2));
1561: assertEquals(true, ArrayUtils.contains(array, 3));
1562: assertEquals(false, ArrayUtils.contains(array, 99));
1563: }
1564:
1565: //-----------------------------------------------------------------------
1566: public void testIndexOfInt() {
1567: int[] array = null;
1568: assertEquals(-1, ArrayUtils.indexOf(array, 0));
1569: array = new int[] { 0, 1, 2, 3, 0 };
1570: assertEquals(0, ArrayUtils.indexOf(array, 0));
1571: assertEquals(1, ArrayUtils.indexOf(array, 1));
1572: assertEquals(2, ArrayUtils.indexOf(array, 2));
1573: assertEquals(3, ArrayUtils.indexOf(array, 3));
1574: assertEquals(-1, ArrayUtils.indexOf(array, 99));
1575: }
1576:
1577: public void testIndexOfIntWithStartIndex() {
1578: int[] array = null;
1579: assertEquals(-1, ArrayUtils.indexOf(array, 0, 2));
1580: array = new int[] { 0, 1, 2, 3, 0 };
1581: assertEquals(4, ArrayUtils.indexOf(array, 0, 2));
1582: assertEquals(-1, ArrayUtils.indexOf(array, 1, 2));
1583: assertEquals(2, ArrayUtils.indexOf(array, 2, 2));
1584: assertEquals(3, ArrayUtils.indexOf(array, 3, 2));
1585: assertEquals(3, ArrayUtils.indexOf(array, 3, -1));
1586: assertEquals(-1, ArrayUtils.indexOf(array, 99, 0));
1587: assertEquals(-1, ArrayUtils.indexOf(array, 0, 6));
1588: }
1589:
1590: public void testLastIndexOfInt() {
1591: int[] array = null;
1592: assertEquals(-1, ArrayUtils.lastIndexOf(array, 0));
1593: array = new int[] { 0, 1, 2, 3, 0 };
1594: assertEquals(4, ArrayUtils.lastIndexOf(array, 0));
1595: assertEquals(1, ArrayUtils.lastIndexOf(array, 1));
1596: assertEquals(2, ArrayUtils.lastIndexOf(array, 2));
1597: assertEquals(3, ArrayUtils.lastIndexOf(array, 3));
1598: assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1599: }
1600:
1601: public void testLastIndexOfIntWithStartIndex() {
1602: int[] array = null;
1603: assertEquals(-1, ArrayUtils.lastIndexOf(array, 0, 2));
1604: array = new int[] { 0, 1, 2, 3, 0 };
1605: assertEquals(0, ArrayUtils.lastIndexOf(array, 0, 2));
1606: assertEquals(1, ArrayUtils.lastIndexOf(array, 1, 2));
1607: assertEquals(2, ArrayUtils.lastIndexOf(array, 2, 2));
1608: assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, 2));
1609: assertEquals(-1, ArrayUtils.lastIndexOf(array, 3, -1));
1610: assertEquals(-1, ArrayUtils.lastIndexOf(array, 99));
1611: assertEquals(4, ArrayUtils.lastIndexOf(array, 0, 88));
1612: }
1613:
1614: public void testContainsInt() {
1615: int[] array = null;
1616: assertEquals(false, ArrayUtils.contains(array, 1));
1617: array = new int[] { 0, 1, 2, 3, 0 };
1618: assertEquals(true, ArrayUtils.contains(array, 0));
1619: assertEquals(true, ArrayUtils.contains(array, 1));
1620: assertEquals(true, ArrayUtils.contains(array, 2));
1621: assertEquals(true, ArrayUtils.contains(array, 3));
1622: assertEquals(false, ArrayUtils.contains(array, 99));
1623: }
1624:
1625: //-----------------------------------------------------------------------
1626: public void testIndexOfShort() {
1627: short[] array = null;
1628: assertEquals(-1, ArrayUtils.indexOf(array, (short) 0));
1629: array = new short[] { 0, 1, 2, 3, 0 };
1630: assertEquals(0, ArrayUtils.indexOf(array, (short) 0));
1631: assertEquals(1, ArrayUtils.indexOf(array, (short) 1));
1632: assertEquals(2, ArrayUtils.indexOf(array, (short) 2));
1633: assertEquals(3, ArrayUtils.indexOf(array, (short) 3));
1634: assertEquals(-1, ArrayUtils.indexOf(array, (short) 99));
1635: }
1636:
1637: public void testIndexOfShortWithStartIndex() {
1638: short[] array = null;
1639: assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 2));
1640: array = new short[] { 0, 1, 2, 3, 0 };
1641: assertEquals(4, ArrayUtils.indexOf(array, (short) 0, 2));
1642: assertEquals(-1, ArrayUtils.indexOf(array, (short) 1, 2));
1643: assertEquals(2, ArrayUtils.indexOf(array, (short) 2, 2));
1644: assertEquals(3, ArrayUtils.indexOf(array, (short) 3, 2));
1645: assertEquals(3, ArrayUtils.indexOf(array, (short) 3, -1));
1646: assertEquals(-1, ArrayUtils.indexOf(array, (short) 99, 0));
1647: assertEquals(-1, ArrayUtils.indexOf(array, (short) 0, 6));
1648: }
1649:
1650: public void testLastIndexOfShort() {
1651: short[] array = null;
1652: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0));
1653: array = new short[] { 0, 1, 2, 3, 0 };
1654: assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0));
1655: assertEquals(1, ArrayUtils.lastIndexOf(array, (short) 1));
1656: assertEquals(2, ArrayUtils.lastIndexOf(array, (short) 2));
1657: assertEquals(3, ArrayUtils.lastIndexOf(array, (short) 3));
1658: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
1659: }
1660:
1661: public void testLastIndexOfShortWithStartIndex() {
1662: short[] array = null;
1663: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 0, 2));
1664: array = new short[] { 0, 1, 2, 3, 0 };
1665: assertEquals(0, ArrayUtils.lastIndexOf(array, (short) 0, 2));
1666: assertEquals(1, ArrayUtils.lastIndexOf(array, (short) 1, 2));
1667: assertEquals(2, ArrayUtils.lastIndexOf(array, (short) 2, 2));
1668: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, 2));
1669: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 3, -1));
1670: assertEquals(-1, ArrayUtils.lastIndexOf(array, (short) 99));
1671: assertEquals(4, ArrayUtils.lastIndexOf(array, (short) 0, 88));
1672: }
1673:
1674: public void testContainsShort() {
1675: short[] array = null;
1676: assertEquals(false, ArrayUtils.contains(array, (short) 1));
1677: array = new short[] { 0, 1, 2, 3, 0 };
1678: assertEquals(true, ArrayUtils.contains(array, (short) 0));
1679: assertEquals(true, ArrayUtils.contains(array, (short) 1));
1680: assertEquals(true, ArrayUtils.contains(array, (short) 2));
1681: assertEquals(true, ArrayUtils.contains(array, (short) 3));
1682: assertEquals(false, ArrayUtils.contains(array, (short) 99));
1683: }
1684:
1685: //-----------------------------------------------------------------------
1686: public void testIndexOfChar() {
1687: char[] array = null;
1688: assertEquals(-1, ArrayUtils.indexOf(array, 'a'));
1689: array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1690: assertEquals(0, ArrayUtils.indexOf(array, 'a'));
1691: assertEquals(1, ArrayUtils.indexOf(array, 'b'));
1692: assertEquals(2, ArrayUtils.indexOf(array, 'c'));
1693: assertEquals(3, ArrayUtils.indexOf(array, 'd'));
1694: assertEquals(-1, ArrayUtils.indexOf(array, 'e'));
1695: }
1696:
1697: public void testIndexOfCharWithStartIndex() {
1698: char[] array = null;
1699: assertEquals(-1, ArrayUtils.indexOf(array, 'a', 2));
1700: array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1701: assertEquals(4, ArrayUtils.indexOf(array, 'a', 2));
1702: assertEquals(-1, ArrayUtils.indexOf(array, 'b', 2));
1703: assertEquals(2, ArrayUtils.indexOf(array, 'c', 2));
1704: assertEquals(3, ArrayUtils.indexOf(array, 'd', 2));
1705: assertEquals(3, ArrayUtils.indexOf(array, 'd', -1));
1706: assertEquals(-1, ArrayUtils.indexOf(array, 'e', 0));
1707: assertEquals(-1, ArrayUtils.indexOf(array, 'a', 6));
1708: }
1709:
1710: public void testLastIndexOfChar() {
1711: char[] array = null;
1712: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a'));
1713: array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1714: assertEquals(4, ArrayUtils.lastIndexOf(array, 'a'));
1715: assertEquals(1, ArrayUtils.lastIndexOf(array, 'b'));
1716: assertEquals(2, ArrayUtils.lastIndexOf(array, 'c'));
1717: assertEquals(3, ArrayUtils.lastIndexOf(array, 'd'));
1718: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'e'));
1719: }
1720:
1721: public void testLastIndexOfCharWithStartIndex() {
1722: char[] array = null;
1723: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'a', 2));
1724: array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1725: assertEquals(0, ArrayUtils.lastIndexOf(array, 'a', 2));
1726: assertEquals(1, ArrayUtils.lastIndexOf(array, 'b', 2));
1727: assertEquals(2, ArrayUtils.lastIndexOf(array, 'c', 2));
1728: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'd', 2));
1729: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'd', -1));
1730: assertEquals(-1, ArrayUtils.lastIndexOf(array, 'e'));
1731: assertEquals(4, ArrayUtils.lastIndexOf(array, 'a', 88));
1732: }
1733:
1734: public void testContainsChar() {
1735: char[] array = null;
1736: assertEquals(false, ArrayUtils.contains(array, 'b'));
1737: array = new char[] { 'a', 'b', 'c', 'd', 'a' };
1738: assertEquals(true, ArrayUtils.contains(array, 'a'));
1739: assertEquals(true, ArrayUtils.contains(array, 'b'));
1740: assertEquals(true, ArrayUtils.contains(array, 'c'));
1741: assertEquals(true, ArrayUtils.contains(array, 'd'));
1742: assertEquals(false, ArrayUtils.contains(array, 'e'));
1743: }
1744:
1745: //-----------------------------------------------------------------------
1746: public void testIndexOfByte() {
1747: byte[] array = null;
1748: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0));
1749: array = new byte[] { 0, 1, 2, 3, 0 };
1750: assertEquals(0, ArrayUtils.indexOf(array, (byte) 0));
1751: assertEquals(1, ArrayUtils.indexOf(array, (byte) 1));
1752: assertEquals(2, ArrayUtils.indexOf(array, (byte) 2));
1753: assertEquals(3, ArrayUtils.indexOf(array, (byte) 3));
1754: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99));
1755: }
1756:
1757: public void testIndexOfByteWithStartIndex() {
1758: byte[] array = null;
1759: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 2));
1760: array = new byte[] { 0, 1, 2, 3, 0 };
1761: assertEquals(4, ArrayUtils.indexOf(array, (byte) 0, 2));
1762: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 1, 2));
1763: assertEquals(2, ArrayUtils.indexOf(array, (byte) 2, 2));
1764: assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, 2));
1765: assertEquals(3, ArrayUtils.indexOf(array, (byte) 3, -1));
1766: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 99, 0));
1767: assertEquals(-1, ArrayUtils.indexOf(array, (byte) 0, 6));
1768: }
1769:
1770: public void testLastIndexOfByte() {
1771: byte[] array = null;
1772: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0));
1773: array = new byte[] { 0, 1, 2, 3, 0 };
1774: assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0));
1775: assertEquals(1, ArrayUtils.lastIndexOf(array, (byte) 1));
1776: assertEquals(2, ArrayUtils.lastIndexOf(array, (byte) 2));
1777: assertEquals(3, ArrayUtils.lastIndexOf(array, (byte) 3));
1778: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
1779: }
1780:
1781: public void testLastIndexOfByteWithStartIndex() {
1782: byte[] array = null;
1783: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 0, 2));
1784: array = new byte[] { 0, 1, 2, 3, 0 };
1785: assertEquals(0, ArrayUtils.lastIndexOf(array, (byte) 0, 2));
1786: assertEquals(1, ArrayUtils.lastIndexOf(array, (byte) 1, 2));
1787: assertEquals(2, ArrayUtils.lastIndexOf(array, (byte) 2, 2));
1788: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, 2));
1789: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 3, -1));
1790: assertEquals(-1, ArrayUtils.lastIndexOf(array, (byte) 99));
1791: assertEquals(4, ArrayUtils.lastIndexOf(array, (byte) 0, 88));
1792: }
1793:
1794: public void testContainsByte() {
1795: byte[] array = null;
1796: assertEquals(false, ArrayUtils.contains(array, (byte) 1));
1797: array = new byte[] { 0, 1, 2, 3, 0 };
1798: assertEquals(true, ArrayUtils.contains(array, (byte) 0));
1799: assertEquals(true, ArrayUtils.contains(array, (byte) 1));
1800: assertEquals(true, ArrayUtils.contains(array, (byte) 2));
1801: assertEquals(true, ArrayUtils.contains(array, (byte) 3));
1802: assertEquals(false, ArrayUtils.contains(array, (byte) 99));
1803: }
1804:
1805: //-----------------------------------------------------------------------
1806: public void testIndexOfDouble() {
1807: double[] array = null;
1808: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0));
1809: array = new double[0];
1810: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0));
1811: array = new double[] { 0, 1, 2, 3, 0 };
1812: assertEquals(0, ArrayUtils.indexOf(array, (double) 0));
1813: assertEquals(1, ArrayUtils.indexOf(array, (double) 1));
1814: assertEquals(2, ArrayUtils.indexOf(array, (double) 2));
1815: assertEquals(3, ArrayUtils.indexOf(array, (double) 3));
1816: assertEquals(3, ArrayUtils.indexOf(array, (double) 3, -1));
1817: assertEquals(-1, ArrayUtils.indexOf(array, (double) 99));
1818: }
1819:
1820: public void testIndexOfDoubleTolerance() {
1821: double[] array = null;
1822: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0,
1823: (double) 0));
1824: array = new double[0];
1825: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0,
1826: (double) 0));
1827: array = new double[] { 0, 1, 2, 3, 0 };
1828: assertEquals(0, ArrayUtils.indexOf(array, (double) 0,
1829: (double) 0.3));
1830: assertEquals(2, ArrayUtils.indexOf(array, (double) 2.2,
1831: (double) 0.35));
1832: assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15,
1833: (double) 2.0));
1834: assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324,
1835: (double) 0.0001));
1836: }
1837:
1838: public void testIndexOfDoubleWithStartIndex() {
1839: double[] array = null;
1840: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2));
1841: array = new double[0];
1842: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2));
1843: array = new double[] { 0, 1, 2, 3, 0 };
1844: assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 2));
1845: assertEquals(-1, ArrayUtils.indexOf(array, (double) 1, 2));
1846: assertEquals(2, ArrayUtils.indexOf(array, (double) 2, 2));
1847: assertEquals(3, ArrayUtils.indexOf(array, (double) 3, 2));
1848: assertEquals(-1, ArrayUtils.indexOf(array, (double) 99, 0));
1849: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 6));
1850: }
1851:
1852: public void testIndexOfDoubleWithStartIndexTolerance() {
1853: double[] array = null;
1854: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2,
1855: (double) 0));
1856: array = new double[0];
1857: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 2,
1858: (double) 0));
1859: array = new double[] { 0, 1, 2, 3, 0 };
1860: assertEquals(-1, ArrayUtils.indexOf(array, (double) 0, 99,
1861: (double) 0.3));
1862: assertEquals(0, ArrayUtils.indexOf(array, (double) 0, 0,
1863: (double) 0.3));
1864: assertEquals(4, ArrayUtils.indexOf(array, (double) 0, 3,
1865: (double) 0.3));
1866: assertEquals(2, ArrayUtils.indexOf(array, (double) 2.2, 0,
1867: (double) 0.35));
1868: assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15, 0,
1869: (double) 2.0));
1870: assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324,
1871: 0, (double) 0.0001));
1872: assertEquals(3, ArrayUtils.indexOf(array, (double) 4.15, -1,
1873: (double) 2.0));
1874: assertEquals(1, ArrayUtils.indexOf(array, (double) 1.00001324,
1875: -300, (double) 0.0001));
1876: }
1877:
1878: public void testLastIndexOfDouble() {
1879: double[] array = null;
1880: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
1881: array = new double[0];
1882: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0));
1883: array = new double[] { 0, 1, 2, 3, 0 };
1884: assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0));
1885: assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1));
1886: assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2));
1887: assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 3));
1888: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99));
1889: }
1890:
1891: public void testLastIndexOfDoubleTolerance() {
1892: double[] array = null;
1893: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0,
1894: (double) 0));
1895: array = new double[0];
1896: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0,
1897: (double) 0));
1898: array = new double[] { 0, 1, 2, 3, 0 };
1899: assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0,
1900: (double) 0.3));
1901: assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2.2,
1902: (double) 0.35));
1903: assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 4.15,
1904: (double) 2.0));
1905: assertEquals(1, ArrayUtils.lastIndexOf(array,
1906: (double) 1.00001324, (double) 0.0001));
1907: }
1908:
1909: public void testLastIndexOfDoubleWithStartIndex() {
1910: double[] array = null;
1911: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1912: array = new double[0];
1913: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1914: array = new double[] { 0, 1, 2, 3, 0 };
1915: assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 2));
1916: assertEquals(1, ArrayUtils.lastIndexOf(array, (double) 1, 2));
1917: assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2, 2));
1918: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, 2));
1919: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 3, -1));
1920: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 99));
1921: assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 88));
1922: }
1923:
1924: public void testLastIndexOfDoubleWithStartIndexTolerance() {
1925: double[] array = null;
1926: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2,
1927: (double) 0));
1928: array = new double[0];
1929: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 0, 2,
1930: (double) 0));
1931: array = new double[] { (double) 3 };
1932: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 1, 0,
1933: (double) 0));
1934: array = new double[] { 0, 1, 2, 3, 0 };
1935: assertEquals(4, ArrayUtils.lastIndexOf(array, (double) 0, 99,
1936: (double) 0.3));
1937: assertEquals(0, ArrayUtils.lastIndexOf(array, (double) 0, 3,
1938: (double) 0.3));
1939: assertEquals(2, ArrayUtils.lastIndexOf(array, (double) 2.2, 3,
1940: (double) 0.35));
1941: assertEquals(3, ArrayUtils.lastIndexOf(array, (double) 4.15,
1942: array.length, (double) 2.0));
1943: assertEquals(1, ArrayUtils.lastIndexOf(array,
1944: (double) 1.00001324, array.length, (double) 0.0001));
1945: assertEquals(-1, ArrayUtils.lastIndexOf(array, (double) 4.15,
1946: -200, (double) 2.0));
1947: }
1948:
1949: public void testContainsDouble() {
1950: double[] array = null;
1951: assertEquals(false, ArrayUtils.contains(array, (double) 1));
1952: array = new double[] { 0, 1, 2, 3, 0 };
1953: assertEquals(true, ArrayUtils.contains(array, (double) 0));
1954: assertEquals(true, ArrayUtils.contains(array, (double) 1));
1955: assertEquals(true, ArrayUtils.contains(array, (double) 2));
1956: assertEquals(true, ArrayUtils.contains(array, (double) 3));
1957: assertEquals(false, ArrayUtils.contains(array, (double) 99));
1958: }
1959:
1960: public void testContainsDoubleTolerance() {
1961: double[] array = null;
1962: assertEquals(false, ArrayUtils.contains(array, (double) 1,
1963: (double) 0));
1964: array = new double[] { 0, 1, 2, 3, 0 };
1965: assertEquals(false, ArrayUtils.contains(array, (double) 4.0,
1966: (double) 0.33));
1967: assertEquals(false, ArrayUtils.contains(array, (double) 2.5,
1968: (double) 0.49));
1969: assertEquals(true, ArrayUtils.contains(array, (double) 2.5,
1970: (double) 0.50));
1971: assertEquals(true, ArrayUtils.contains(array, (double) 2.5,
1972: (double) 0.51));
1973: }
1974:
1975: //-----------------------------------------------------------------------
1976: public void testIndexOfFloat() {
1977: float[] array = null;
1978: assertEquals(-1, ArrayUtils.indexOf(array, (float) 0));
1979: array = new float[0];
1980: assertEquals(-1, ArrayUtils.indexOf(array, (float) 0));
1981: array = new float[] { 0, 1, 2, 3, 0 };
1982: assertEquals(0, ArrayUtils.indexOf(array, (float) 0));
1983: assertEquals(1, ArrayUtils.indexOf(array, (float) 1));
1984: assertEquals(2, ArrayUtils.indexOf(array, (float) 2));
1985: assertEquals(3, ArrayUtils.indexOf(array, (float) 3));
1986: assertEquals(-1, ArrayUtils.indexOf(array, (float) 99));
1987: }
1988:
1989: public void testIndexOfFloatWithStartIndex() {
1990: float[] array = null;
1991: assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2));
1992: array = new float[0];
1993: assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 2));
1994: array = new float[] { 0, 1, 2, 3, 0 };
1995: assertEquals(4, ArrayUtils.indexOf(array, (float) 0, 2));
1996: assertEquals(-1, ArrayUtils.indexOf(array, (float) 1, 2));
1997: assertEquals(2, ArrayUtils.indexOf(array, (float) 2, 2));
1998: assertEquals(3, ArrayUtils.indexOf(array, (float) 3, 2));
1999: assertEquals(3, ArrayUtils.indexOf(array, (float) 3, -1));
2000: assertEquals(-1, ArrayUtils.indexOf(array, (float) 99, 0));
2001: assertEquals(-1, ArrayUtils.indexOf(array, (float) 0, 6));
2002: }
2003:
2004: public void testLastIndexOfFloat() {
2005: float[] array = null;
2006: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
2007: array = new float[0];
2008: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0));
2009: array = new float[] { 0, 1, 2, 3, 0 };
2010: assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0));
2011: assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1));
2012: assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2));
2013: assertEquals(3, ArrayUtils.lastIndexOf(array, (float) 3));
2014: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99));
2015: }
2016:
2017: public void testLastIndexOfFloatWithStartIndex() {
2018: float[] array = null;
2019: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2));
2020: array = new float[0];
2021: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 0, 2));
2022: array = new float[] { 0, 1, 2, 3, 0 };
2023: assertEquals(0, ArrayUtils.lastIndexOf(array, (float) 0, 2));
2024: assertEquals(1, ArrayUtils.lastIndexOf(array, (float) 1, 2));
2025: assertEquals(2, ArrayUtils.lastIndexOf(array, (float) 2, 2));
2026: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, 2));
2027: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 3, -1));
2028: assertEquals(-1, ArrayUtils.lastIndexOf(array, (float) 99));
2029: assertEquals(4, ArrayUtils.lastIndexOf(array, (float) 0, 88));
2030: }
2031:
2032: public void testContainsFloat() {
2033: float[] array = null;
2034: assertEquals(false, ArrayUtils.contains(array, (float) 1));
2035: array = new float[] { 0, 1, 2, 3, 0 };
2036: assertEquals(true, ArrayUtils.contains(array, (float) 0));
2037: assertEquals(true, ArrayUtils.contains(array, (float) 1));
2038: assertEquals(true, ArrayUtils.contains(array, (float) 2));
2039: assertEquals(true, ArrayUtils.contains(array, (float) 3));
2040: assertEquals(false, ArrayUtils.contains(array, (float) 99));
2041: }
2042:
2043: //-----------------------------------------------------------------------
2044: public void testIndexOfBoolean() {
2045: boolean[] array = null;
2046: assertEquals(-1, ArrayUtils.indexOf(array, true));
2047: array = new boolean[0];
2048: assertEquals(-1, ArrayUtils.indexOf(array, true));
2049: array = new boolean[] { true, false, true };
2050: assertEquals(0, ArrayUtils.indexOf(array, true));
2051: assertEquals(1, ArrayUtils.indexOf(array, false));
2052: array = new boolean[] { true, true };
2053: assertEquals(-1, ArrayUtils.indexOf(array, false));
2054: }
2055:
2056: public void testIndexOfBooleanWithStartIndex() {
2057: boolean[] array = null;
2058: assertEquals(-1, ArrayUtils.indexOf(array, true, 2));
2059: array = new boolean[0];
2060: assertEquals(-1, ArrayUtils.indexOf(array, true, 2));
2061: array = new boolean[] { true, false, true };
2062: assertEquals(2, ArrayUtils.indexOf(array, true, 1));
2063: assertEquals(-1, ArrayUtils.indexOf(array, false, 2));
2064: assertEquals(1, ArrayUtils.indexOf(array, false, 0));
2065: assertEquals(1, ArrayUtils.indexOf(array, false, -1));
2066: array = new boolean[] { true, true };
2067: assertEquals(-1, ArrayUtils.indexOf(array, false, 0));
2068: assertEquals(-1, ArrayUtils.indexOf(array, false, -1));
2069: }
2070:
2071: public void testLastIndexOfBoolean() {
2072: boolean[] array = null;
2073: assertEquals(-1, ArrayUtils.lastIndexOf(array, true));
2074: array = new boolean[0];
2075: assertEquals(-1, ArrayUtils.lastIndexOf(array, true));
2076: array = new boolean[] { true, false, true };
2077: assertEquals(2, ArrayUtils.lastIndexOf(array, true));
2078: assertEquals(1, ArrayUtils.lastIndexOf(array, false));
2079: array = new boolean[] { true, true };
2080: assertEquals(-1, ArrayUtils.lastIndexOf(array, false));
2081: }
2082:
2083: public void testLastIndexOfBooleanWithStartIndex() {
2084: boolean[] array = null;
2085: assertEquals(-1, ArrayUtils.lastIndexOf(array, true, 2));
2086: array = new boolean[0];
2087: assertEquals(-1, ArrayUtils.lastIndexOf(array, true, 2));
2088: array = new boolean[] { true, false, true };
2089: assertEquals(2, ArrayUtils.lastIndexOf(array, true, 2));
2090: assertEquals(0, ArrayUtils.lastIndexOf(array, true, 1));
2091: assertEquals(1, ArrayUtils.lastIndexOf(array, false, 2));
2092: assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
2093: array = new boolean[] { true, true };
2094: assertEquals(-1, ArrayUtils.lastIndexOf(array, false, 2));
2095: assertEquals(-1, ArrayUtils.lastIndexOf(array, true, -1));
2096: }
2097:
2098: public void testContainsBoolean() {
2099: boolean[] array = null;
2100: assertEquals(false, ArrayUtils.contains(array, true));
2101: array = new boolean[] { true, false, true };
2102: assertEquals(true, ArrayUtils.contains(array, true));
2103: assertEquals(true, ArrayUtils.contains(array, false));
2104: array = new boolean[] { true, true };
2105: assertEquals(true, ArrayUtils.contains(array, true));
2106: assertEquals(false, ArrayUtils.contains(array, false));
2107: }
2108:
2109: // testToPrimitive/Object for boolean
2110: // -----------------------------------------------------------------------
2111: public void testToPrimitive_boolean() {
2112: final Boolean[] b = null;
2113: assertEquals(null, ArrayUtils.toPrimitive(b));
2114: assertSame(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils
2115: .toPrimitive(new Boolean[0]));
2116: assertTrue(Arrays.equals(new boolean[] { true, false, true },
2117: ArrayUtils.toPrimitive(new Boolean[] { Boolean.TRUE,
2118: Boolean.FALSE, Boolean.TRUE })));
2119:
2120: try {
2121: ArrayUtils
2122: .toPrimitive(new Boolean[] { Boolean.TRUE, null });
2123: fail();
2124: } catch (NullPointerException ex) {
2125: }
2126: }
2127:
2128: public void testToPrimitive_boolean_boolean() {
2129: assertEquals(null, ArrayUtils.toPrimitive(null, false));
2130: assertSame(ArrayUtils.EMPTY_BOOLEAN_ARRAY, ArrayUtils
2131: .toPrimitive(new Boolean[0], false));
2132: assertTrue(Arrays.equals(new boolean[] { true, false, true },
2133: ArrayUtils.toPrimitive(new Boolean[] { Boolean.TRUE,
2134: Boolean.FALSE, Boolean.TRUE }, false)));
2135: assertTrue(Arrays.equals(new boolean[] { true, false, false },
2136: ArrayUtils.toPrimitive(new Boolean[] { Boolean.TRUE,
2137: null, Boolean.FALSE }, false)));
2138: assertTrue(Arrays.equals(new boolean[] { true, true, false },
2139: ArrayUtils.toPrimitive(new Boolean[] { Boolean.TRUE,
2140: null, Boolean.FALSE }, true)));
2141: }
2142:
2143: public void testToObject_boolean() {
2144: final boolean[] b = null;
2145: assertEquals(null, ArrayUtils.toObject(b));
2146: assertSame(ArrayUtils.EMPTY_BOOLEAN_OBJECT_ARRAY, ArrayUtils
2147: .toObject(new boolean[0]));
2148: assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE,
2149: Boolean.FALSE, Boolean.TRUE }, ArrayUtils
2150: .toObject(new boolean[] { true, false, true })));
2151: }
2152:
2153: // testToPrimitive/Object for byte
2154: // -----------------------------------------------------------------------
2155: public void testToPrimitive_char() {
2156: final Character[] b = null;
2157: assertEquals(null, ArrayUtils.toPrimitive(b));
2158:
2159: assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils
2160: .toPrimitive(new Character[0]));
2161:
2162: assertTrue(Arrays.equals(new char[] { Character.MIN_VALUE,
2163: Character.MAX_VALUE, '0' }, ArrayUtils
2164: .toPrimitive(new Character[] {
2165: new Character(Character.MIN_VALUE),
2166: new Character(Character.MAX_VALUE),
2167: new Character('0') })));
2168:
2169: try {
2170: ArrayUtils.toPrimitive(new Character[] {
2171: new Character(Character.MIN_VALUE), null });
2172: fail();
2173: } catch (NullPointerException ex) {
2174: }
2175: }
2176:
2177: public void testToPrimitive_char_char() {
2178: final Character[] b = null;
2179: assertEquals(null, ArrayUtils.toPrimitive(b,
2180: Character.MIN_VALUE));
2181:
2182: assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.toPrimitive(
2183: new Character[0], (char) 0));
2184:
2185: assertTrue(Arrays.equals(new char[] { Character.MIN_VALUE,
2186: Character.MAX_VALUE, '0' }, ArrayUtils.toPrimitive(
2187: new Character[] { new Character(Character.MIN_VALUE),
2188: new Character(Character.MAX_VALUE),
2189: new Character('0') }, Character.MIN_VALUE)));
2190:
2191: assertTrue(Arrays.equals(new char[] { Character.MIN_VALUE,
2192: Character.MAX_VALUE, '0' }, ArrayUtils
2193: .toPrimitive(new Character[] {
2194: new Character(Character.MIN_VALUE), null,
2195: new Character('0') }, Character.MAX_VALUE)));
2196: }
2197:
2198: public void testToObject_char() {
2199: final char[] b = null;
2200: assertEquals(null, ArrayUtils.toObject(b));
2201:
2202: assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, ArrayUtils
2203: .toObject(new char[0]));
2204:
2205: assertTrue(Arrays.equals(
2206: new Character[] { new Character(Character.MIN_VALUE),
2207: new Character(Character.MAX_VALUE),
2208: new Character('0') }, ArrayUtils
2209: .toObject(new char[] { Character.MIN_VALUE,
2210: Character.MAX_VALUE, '0' })));
2211: }
2212:
2213: // testToPrimitive/Object for byte
2214: // -----------------------------------------------------------------------
2215: public void testToPrimitive_byte() {
2216: final Byte[] b = null;
2217: assertEquals(null, ArrayUtils.toPrimitive(b));
2218:
2219: assertSame(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils
2220: .toPrimitive(new Byte[0]));
2221:
2222: assertTrue(Arrays.equals(new byte[] { Byte.MIN_VALUE,
2223: Byte.MAX_VALUE, (byte) 9999999 }, ArrayUtils
2224: .toPrimitive(new Byte[] { new Byte(Byte.MIN_VALUE),
2225: new Byte(Byte.MAX_VALUE),
2226: new Byte((byte) 9999999) })));
2227:
2228: try {
2229: ArrayUtils.toPrimitive(new Byte[] {
2230: new Byte(Byte.MIN_VALUE), null });
2231: fail();
2232: } catch (NullPointerException ex) {
2233: }
2234: }
2235:
2236: public void testToPrimitive_byte_byte() {
2237: final Byte[] b = null;
2238: assertEquals(null, ArrayUtils.toPrimitive(b, Byte.MIN_VALUE));
2239:
2240: assertSame(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.toPrimitive(
2241: new Byte[0], (byte) 1));
2242:
2243: assertTrue(Arrays.equals(new byte[] { Byte.MIN_VALUE,
2244: Byte.MAX_VALUE, (byte) 9999999 }, ArrayUtils
2245: .toPrimitive(new Byte[] { new Byte(Byte.MIN_VALUE),
2246: new Byte(Byte.MAX_VALUE),
2247: new Byte((byte) 9999999) }, Byte.MIN_VALUE)));
2248:
2249: assertTrue(Arrays.equals(new byte[] { Byte.MIN_VALUE,
2250: Byte.MAX_VALUE, (byte) 9999999 }, ArrayUtils
2251: .toPrimitive(new Byte[] { new Byte(Byte.MIN_VALUE),
2252: null, new Byte((byte) 9999999) },
2253: Byte.MAX_VALUE)));
2254: }
2255:
2256: public void testToObject_byte() {
2257: final byte[] b = null;
2258: assertEquals(null, ArrayUtils.toObject(b));
2259:
2260: assertSame(ArrayUtils.EMPTY_BYTE_OBJECT_ARRAY, ArrayUtils
2261: .toObject(new byte[0]));
2262:
2263: assertTrue(Arrays.equals(new Byte[] { new Byte(Byte.MIN_VALUE),
2264: new Byte(Byte.MAX_VALUE), new Byte((byte) 9999999) },
2265: ArrayUtils.toObject(new byte[] { Byte.MIN_VALUE,
2266: Byte.MAX_VALUE, (byte) 9999999 })));
2267: }
2268:
2269: // testToPrimitive/Object for short
2270: // -----------------------------------------------------------------------
2271: public void testToPrimitive_short() {
2272: final Short[] b = null;
2273: assertEquals(null, ArrayUtils.toPrimitive(b));
2274:
2275: assertSame(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils
2276: .toPrimitive(new Short[0]));
2277:
2278: assertTrue(Arrays.equals(new short[] { Short.MIN_VALUE,
2279: Short.MAX_VALUE, (short) 9999999 }, ArrayUtils
2280: .toPrimitive(new Short[] { new Short(Short.MIN_VALUE),
2281: new Short(Short.MAX_VALUE),
2282: new Short((short) 9999999) })));
2283:
2284: try {
2285: ArrayUtils.toPrimitive(new Short[] {
2286: new Short(Short.MIN_VALUE), null });
2287: fail();
2288: } catch (NullPointerException ex) {
2289: }
2290: }
2291:
2292: public void testToPrimitive_short_short() {
2293: final Short[] s = null;
2294: assertEquals(null, ArrayUtils.toPrimitive(s, Short.MIN_VALUE));
2295:
2296: assertSame(ArrayUtils.EMPTY_SHORT_ARRAY, ArrayUtils
2297: .toPrimitive(new Short[0], Short.MIN_VALUE));
2298:
2299: assertTrue(Arrays.equals(new short[] { Short.MIN_VALUE,
2300: Short.MAX_VALUE, (short) 9999999 }, ArrayUtils
2301: .toPrimitive(new Short[] { new Short(Short.MIN_VALUE),
2302: new Short(Short.MAX_VALUE),
2303: new Short((short) 9999999) }, Short.MIN_VALUE)));
2304:
2305: assertTrue(Arrays.equals(new short[] { Short.MIN_VALUE,
2306: Short.MAX_VALUE, (short) 9999999 }, ArrayUtils
2307: .toPrimitive(new Short[] { new Short(Short.MIN_VALUE),
2308: null, new Short((short) 9999999) },
2309: Short.MAX_VALUE)));
2310: }
2311:
2312: public void testToObject_short() {
2313: final short[] b = null;
2314: assertEquals(null, ArrayUtils.toObject(b));
2315:
2316: assertSame(ArrayUtils.EMPTY_SHORT_OBJECT_ARRAY, ArrayUtils
2317: .toObject(new short[0]));
2318:
2319: assertTrue(Arrays.equals(new Short[] {
2320: new Short(Short.MIN_VALUE), new Short(Short.MAX_VALUE),
2321: new Short((short) 9999999) }, ArrayUtils
2322: .toObject(new short[] { Short.MIN_VALUE,
2323: Short.MAX_VALUE, (short) 9999999 })));
2324: }
2325:
2326: // testToPrimitive/Object for int
2327: // -----------------------------------------------------------------------
2328: public void testToPrimitive_int() {
2329: final Integer[] b = null;
2330: assertEquals(null, ArrayUtils.toPrimitive(b));
2331: assertSame(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils
2332: .toPrimitive(new Integer[0]));
2333: assertTrue(Arrays.equals(new int[] { Integer.MIN_VALUE,
2334: Integer.MAX_VALUE, 9999999 }, ArrayUtils
2335: .toPrimitive(new Integer[] {
2336: new Integer(Integer.MIN_VALUE),
2337: new Integer(Integer.MAX_VALUE),
2338: new Integer(9999999) })));
2339:
2340: try {
2341: ArrayUtils.toPrimitive(new Integer[] {
2342: new Integer(Integer.MIN_VALUE), null });
2343: fail();
2344: } catch (NullPointerException ex) {
2345: }
2346: }
2347:
2348: public void testToPrimitive_int_int() {
2349: final Long[] l = null;
2350: assertEquals(null, ArrayUtils.toPrimitive(l, Integer.MIN_VALUE));
2351: assertSame(ArrayUtils.EMPTY_INT_ARRAY, ArrayUtils.toPrimitive(
2352: new Integer[0], 1));
2353: assertTrue(Arrays.equals(new int[] { Integer.MIN_VALUE,
2354: Integer.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2355: new Integer[] { new Integer(Integer.MIN_VALUE),
2356: new Integer(Integer.MAX_VALUE),
2357: new Integer(9999999) }, 1)));
2358: assertTrue(Arrays.equals(new int[] { Integer.MIN_VALUE,
2359: Integer.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2360: new Integer[] { new Integer(Integer.MIN_VALUE), null,
2361: new Integer(9999999) }, Integer.MAX_VALUE)));
2362: }
2363:
2364: public void testToPrimitive_intNull() {
2365: Integer[] iArray = null;
2366: assertEquals(null, ArrayUtils.toPrimitive(iArray,
2367: Integer.MIN_VALUE));
2368: }
2369:
2370: public void testToObject_int() {
2371: final int[] b = null;
2372: assertEquals(null, ArrayUtils.toObject(b));
2373:
2374: assertSame(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY, ArrayUtils
2375: .toObject(new int[0]));
2376:
2377: assertTrue(Arrays.equals(new Integer[] {
2378: new Integer(Integer.MIN_VALUE),
2379: new Integer(Integer.MAX_VALUE), new Integer(9999999) },
2380: ArrayUtils.toObject(new int[] { Integer.MIN_VALUE,
2381: Integer.MAX_VALUE, 9999999 })));
2382: }
2383:
2384: // testToPrimitive/Object for long
2385: // -----------------------------------------------------------------------
2386: public void testToPrimitive_long() {
2387: final Long[] b = null;
2388: assertEquals(null, ArrayUtils.toPrimitive(b));
2389:
2390: assertSame(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils
2391: .toPrimitive(new Long[0]));
2392:
2393: assertTrue(Arrays.equals(new long[] { Long.MIN_VALUE,
2394: Long.MAX_VALUE, 9999999 }, ArrayUtils
2395: .toPrimitive(new Long[] { new Long(Long.MIN_VALUE),
2396: new Long(Long.MAX_VALUE), new Long(9999999) })));
2397:
2398: try {
2399: ArrayUtils.toPrimitive(new Long[] {
2400: new Long(Long.MIN_VALUE), null });
2401: fail();
2402: } catch (NullPointerException ex) {
2403: }
2404: }
2405:
2406: public void testToPrimitive_long_long() {
2407: final Long[] l = null;
2408: assertEquals(null, ArrayUtils.toPrimitive(l, Long.MIN_VALUE));
2409:
2410: assertSame(ArrayUtils.EMPTY_LONG_ARRAY, ArrayUtils.toPrimitive(
2411: new Long[0], 1));
2412:
2413: assertTrue(Arrays.equals(new long[] { Long.MIN_VALUE,
2414: Long.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2415: new Long[] { new Long(Long.MIN_VALUE),
2416: new Long(Long.MAX_VALUE), new Long(9999999) },
2417: 1)));
2418:
2419: assertTrue(Arrays.equals(new long[] { Long.MIN_VALUE,
2420: Long.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2421: new Long[] { new Long(Long.MIN_VALUE), null,
2422: new Long(9999999) }, Long.MAX_VALUE)));
2423: }
2424:
2425: public void testToObject_long() {
2426: final long[] b = null;
2427: assertEquals(null, ArrayUtils.toObject(b));
2428:
2429: assertSame(ArrayUtils.EMPTY_LONG_OBJECT_ARRAY, ArrayUtils
2430: .toObject(new long[0]));
2431:
2432: assertTrue(Arrays.equals(new Long[] { new Long(Long.MIN_VALUE),
2433: new Long(Long.MAX_VALUE), new Long(9999999) },
2434: ArrayUtils.toObject(new long[] { Long.MIN_VALUE,
2435: Long.MAX_VALUE, 9999999 })));
2436: }
2437:
2438: // testToPrimitive/Object for float
2439: // -----------------------------------------------------------------------
2440: public void testToPrimitive_float() {
2441: final Float[] b = null;
2442: assertEquals(null, ArrayUtils.toPrimitive(b));
2443:
2444: assertSame(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils
2445: .toPrimitive(new Float[0]));
2446:
2447: assertTrue(Arrays.equals(new float[] { Float.MIN_VALUE,
2448: Float.MAX_VALUE, 9999999 },
2449: ArrayUtils
2450: .toPrimitive(new Float[] {
2451: new Float(Float.MIN_VALUE),
2452: new Float(Float.MAX_VALUE),
2453: new Float(9999999) })));
2454:
2455: try {
2456: ArrayUtils.toPrimitive(new Float[] {
2457: new Float(Float.MIN_VALUE), null });
2458: fail();
2459: } catch (NullPointerException ex) {
2460: }
2461: }
2462:
2463: public void testToPrimitive_float_float() {
2464: final Float[] l = null;
2465: assertEquals(null, ArrayUtils.toPrimitive(l, Float.MIN_VALUE));
2466:
2467: assertSame(ArrayUtils.EMPTY_FLOAT_ARRAY, ArrayUtils
2468: .toPrimitive(new Float[0], 1));
2469:
2470: assertTrue(Arrays.equals(new float[] { Float.MIN_VALUE,
2471: Float.MAX_VALUE, 9999999 }, ArrayUtils
2472: .toPrimitive(
2473: new Float[] { new Float(Float.MIN_VALUE),
2474: new Float(Float.MAX_VALUE),
2475: new Float(9999999) }, 1)));
2476:
2477: assertTrue(Arrays.equals(new float[] { Float.MIN_VALUE,
2478: Float.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2479: new Float[] { new Float(Float.MIN_VALUE), null,
2480: new Float(9999999) }, Float.MAX_VALUE)));
2481: }
2482:
2483: public void testToObject_float() {
2484: final float[] b = null;
2485: assertEquals(null, ArrayUtils.toObject(b));
2486:
2487: assertSame(ArrayUtils.EMPTY_FLOAT_OBJECT_ARRAY, ArrayUtils
2488: .toObject(new float[0]));
2489:
2490: assertTrue(Arrays.equals(new Float[] {
2491: new Float(Float.MIN_VALUE), new Float(Float.MAX_VALUE),
2492: new Float(9999999) }, ArrayUtils.toObject(new float[] {
2493: Float.MIN_VALUE, Float.MAX_VALUE, 9999999 })));
2494: }
2495:
2496: // testToPrimitive/Object for double
2497: // -----------------------------------------------------------------------
2498: public void testToPrimitive_double() {
2499: final Double[] b = null;
2500: assertEquals(null, ArrayUtils.toPrimitive(b));
2501:
2502: assertSame(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils
2503: .toPrimitive(new Double[0]));
2504:
2505: assertTrue(Arrays.equals(new double[] { Double.MIN_VALUE,
2506: Double.MAX_VALUE, 9999999 }, ArrayUtils
2507: .toPrimitive(new Double[] {
2508: new Double(Double.MIN_VALUE),
2509: new Double(Double.MAX_VALUE),
2510: new Double(9999999) })));
2511:
2512: try {
2513: ArrayUtils.toPrimitive(new Float[] {
2514: new Float(Float.MIN_VALUE), null });
2515: fail();
2516: } catch (NullPointerException ex) {
2517: }
2518: }
2519:
2520: public void testToPrimitive_double_double() {
2521: final Double[] l = null;
2522: assertEquals(null, ArrayUtils.toPrimitive(l, Double.MIN_VALUE));
2523:
2524: assertSame(ArrayUtils.EMPTY_DOUBLE_ARRAY, ArrayUtils
2525: .toPrimitive(new Double[0], 1));
2526:
2527: assertTrue(Arrays.equals(new double[] { Double.MIN_VALUE,
2528: Double.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2529: new Double[] { new Double(Double.MIN_VALUE),
2530: new Double(Double.MAX_VALUE),
2531: new Double(9999999) }, 1)));
2532:
2533: assertTrue(Arrays.equals(new double[] { Double.MIN_VALUE,
2534: Double.MAX_VALUE, 9999999 }, ArrayUtils.toPrimitive(
2535: new Double[] { new Double(Double.MIN_VALUE), null,
2536: new Double(9999999) }, Double.MAX_VALUE)));
2537: }
2538:
2539: public void testToObject_double() {
2540: final double[] b = null;
2541: assertEquals(null, ArrayUtils.toObject(b));
2542:
2543: assertSame(ArrayUtils.EMPTY_DOUBLE_OBJECT_ARRAY, ArrayUtils
2544: .toObject(new double[0]));
2545:
2546: assertTrue(Arrays.equals(new Double[] {
2547: new Double(Double.MIN_VALUE),
2548: new Double(Double.MAX_VALUE), new Double(9999999) },
2549: ArrayUtils.toObject(new double[] { Double.MIN_VALUE,
2550: Double.MAX_VALUE, 9999999 })));
2551: }
2552:
2553: //-----------------------------------------------------------------------
2554: /**
2555: * Test for {@link ArrayUtils#isEmpty(java.lang.Object[])}.
2556: */
2557: public void testIsEmptyObject() {
2558: Object[] emptyArray = new Object[] {};
2559: Object[] notEmptyArray = new Object[] { new String("Value") };
2560: assertEquals(true, ArrayUtils.isEmpty((Object[]) null));
2561: assertEquals(true, ArrayUtils.isEmpty(emptyArray));
2562: assertEquals(false, ArrayUtils.isEmpty(notEmptyArray));
2563: }
2564:
2565: /**
2566: * Tests for {@link ArrayUtils#isEmpty(long[])},
2567: * {@link ArrayUtils#isEmpty(int[])},
2568: * {@link ArrayUtils#isEmpty(short[])},
2569: * {@link ArrayUtils#isEmpty(char[])},
2570: * {@link ArrayUtils#isEmpty(byte[])},
2571: * {@link ArrayUtils#isEmpty(double[])},
2572: * {@link ArrayUtils#isEmpty(float[])} and
2573: * {@link ArrayUtils#isEmpty(boolean[])}.
2574: */
2575: public void testIsEmptyPrimitives() {
2576: long[] emptyLongArray = new long[] {};
2577: long[] notEmptyLongArray = new long[] { 1L };
2578: assertEquals(true, ArrayUtils.isEmpty((long[]) null));
2579: assertEquals(true, ArrayUtils.isEmpty(emptyLongArray));
2580: assertEquals(false, ArrayUtils.isEmpty(notEmptyLongArray));
2581:
2582: int[] emptyIntArray = new int[] {};
2583: int[] notEmptyIntArray = new int[] { 1 };
2584: assertEquals(true, ArrayUtils.isEmpty((int[]) null));
2585: assertEquals(true, ArrayUtils.isEmpty(emptyIntArray));
2586: assertEquals(false, ArrayUtils.isEmpty(notEmptyIntArray));
2587:
2588: short[] emptyShortArray = new short[] {};
2589: short[] notEmptyShortArray = new short[] { 1 };
2590: assertEquals(true, ArrayUtils.isEmpty((short[]) null));
2591: assertEquals(true, ArrayUtils.isEmpty(emptyShortArray));
2592: assertEquals(false, ArrayUtils.isEmpty(notEmptyShortArray));
2593:
2594: char[] emptyCharArray = new char[] {};
2595: char[] notEmptyCharArray = new char[] { 1 };
2596: assertEquals(true, ArrayUtils.isEmpty((char[]) null));
2597: assertEquals(true, ArrayUtils.isEmpty(emptyCharArray));
2598: assertEquals(false, ArrayUtils.isEmpty(notEmptyCharArray));
2599:
2600: byte[] emptyByteArray = new byte[] {};
2601: byte[] notEmptyByteArray = new byte[] { 1 };
2602: assertEquals(true, ArrayUtils.isEmpty((byte[]) null));
2603: assertEquals(true, ArrayUtils.isEmpty(emptyByteArray));
2604: assertEquals(false, ArrayUtils.isEmpty(notEmptyByteArray));
2605:
2606: double[] emptyDoubleArray = new double[] {};
2607: double[] notEmptyDoubleArray = new double[] { 1.0 };
2608: assertEquals(true, ArrayUtils.isEmpty((double[]) null));
2609: assertEquals(true, ArrayUtils.isEmpty(emptyDoubleArray));
2610: assertEquals(false, ArrayUtils.isEmpty(notEmptyDoubleArray));
2611:
2612: float[] emptyFloatArray = new float[] {};
2613: float[] notEmptyFloatArray = new float[] { 1.0F };
2614: assertEquals(true, ArrayUtils.isEmpty((float[]) null));
2615: assertEquals(true, ArrayUtils.isEmpty(emptyFloatArray));
2616: assertEquals(false, ArrayUtils.isEmpty(notEmptyFloatArray));
2617:
2618: boolean[] emptyBooleanArray = new boolean[] {};
2619: boolean[] notEmptyBooleanArray = new boolean[] { true };
2620: assertEquals(true, ArrayUtils.isEmpty((boolean[]) null));
2621: assertEquals(true, ArrayUtils.isEmpty(emptyBooleanArray));
2622: assertEquals(false, ArrayUtils.isEmpty(notEmptyBooleanArray));
2623: }
2624:
2625: // ------------------------------------------------------------------------
2626: public void testGetLength() {
2627: assertEquals(0, ArrayUtils.getLength(null));
2628:
2629: Object[] emptyObjectArray = new Object[0];
2630: Object[] notEmptyObjectArray = new Object[] { "aValue" };
2631: assertEquals(0, ArrayUtils.getLength((Object[]) null));
2632: assertEquals(0, ArrayUtils.getLength(emptyObjectArray));
2633: assertEquals(1, ArrayUtils.getLength(notEmptyObjectArray));
2634:
2635: int[] emptyIntArray = new int[] {};
2636: int[] notEmptyIntArray = new int[] { 1 };
2637: assertEquals(0, ArrayUtils.getLength((int[]) null));
2638: assertEquals(0, ArrayUtils.getLength(emptyIntArray));
2639: assertEquals(1, ArrayUtils.getLength(notEmptyIntArray));
2640:
2641: short[] emptyShortArray = new short[] {};
2642: short[] notEmptyShortArray = new short[] { 1 };
2643: assertEquals(0, ArrayUtils.getLength((short[]) null));
2644: assertEquals(0, ArrayUtils.getLength(emptyShortArray));
2645: assertEquals(1, ArrayUtils.getLength(notEmptyShortArray));
2646:
2647: char[] emptyCharArray = new char[] {};
2648: char[] notEmptyCharArray = new char[] { 1 };
2649: assertEquals(0, ArrayUtils.getLength((char[]) null));
2650: assertEquals(0, ArrayUtils.getLength(emptyCharArray));
2651: assertEquals(1, ArrayUtils.getLength(notEmptyCharArray));
2652:
2653: byte[] emptyByteArray = new byte[] {};
2654: byte[] notEmptyByteArray = new byte[] { 1 };
2655: assertEquals(0, ArrayUtils.getLength((byte[]) null));
2656: assertEquals(0, ArrayUtils.getLength(emptyByteArray));
2657: assertEquals(1, ArrayUtils.getLength(notEmptyByteArray));
2658:
2659: double[] emptyDoubleArray = new double[] {};
2660: double[] notEmptyDoubleArray = new double[] { 1.0 };
2661: assertEquals(0, ArrayUtils.getLength((double[]) null));
2662: assertEquals(0, ArrayUtils.getLength(emptyDoubleArray));
2663: assertEquals(1, ArrayUtils.getLength(notEmptyDoubleArray));
2664:
2665: float[] emptyFloatArray = new float[] {};
2666: float[] notEmptyFloatArray = new float[] { 1.0F };
2667: assertEquals(0, ArrayUtils.getLength((float[]) null));
2668: assertEquals(0, ArrayUtils.getLength(emptyFloatArray));
2669: assertEquals(1, ArrayUtils.getLength(notEmptyFloatArray));
2670:
2671: boolean[] emptyBooleanArray = new boolean[] {};
2672: boolean[] notEmptyBooleanArray = new boolean[] { true };
2673: assertEquals(0, ArrayUtils.getLength((boolean[]) null));
2674: assertEquals(0, ArrayUtils.getLength(emptyBooleanArray));
2675: assertEquals(1, ArrayUtils.getLength(notEmptyBooleanArray));
2676:
2677: try {
2678: ArrayUtils.getLength("notAnArray");
2679: fail("IllegalArgumentException should have been thrown");
2680: } catch (IllegalArgumentException e) {
2681: }
2682: }
2683:
2684: }
|