Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 3332 invoked from network); 19 Jan 2004 21:50:12 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Jan 2004 21:50:12 -0000 Received: (qmail 61883 invoked by uid 500); 19 Jan 2004 21:49:55 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 61799 invoked by uid 500); 19 Jan 2004 21:49:55 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 61786 invoked by uid 500); 19 Jan 2004 21:49:55 -0000 Received: (qmail 61783 invoked from network); 19 Jan 2004 21:49:55 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 19 Jan 2004 21:49:55 -0000 Received: (qmail 3268 invoked by uid 1749); 19 Jan 2004 21:50:06 -0000 Date: 19 Jan 2004 21:50:06 -0000 Message-ID: <20040119215006.3267.qmail@minotaur.apache.org> From: fredrik@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang ArrayUtilsTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N fredrik 2004/01/19 13:50:06 Modified: lang/src/java/org/apache/commons/lang ArrayUtils.java lang/src/test/org/apache/commons/lang ArrayUtilsTest.java Log: Added isEmpty for Object and primitives arrays. RFE in bugzilla (#26243). Revision Changes Path 1.32 +129 -2 jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java Index: ArrayUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ArrayUtils.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- ArrayUtils.java 8 Jan 2004 17:50:40 -0000 1.31 +++ ArrayUtils.java 19 Jan 2004 21:50:06 -0000 1.32 @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2002-2003 The Apache Software Foundation. All rights + * Copyright (c) 2002-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -80,6 +80,7 @@ * @author Pete Gieser * @author Gary Gregory * @author Ashwin S + * @author Fredrik Westermarck * @since 2.0 * @version $Id$ */ @@ -2625,4 +2626,130 @@ return result; } + // ---------------------------------------------------------------------- + /** + *

Checks if an array of Objects is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final Object[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive longs is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final long[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive ints is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final int[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive shorts is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final short[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive chars is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final char[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive bytes is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final byte[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive doubles is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final double[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive floats is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final float[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } + + /** + *

Checks if an array of primitive booleans is empty or null.

+ * + * @param array the array to test + * @return true if the array is empty or null + * @since 2.1 + */ + public static boolean isEmpty(final boolean[] array) { + if (array == null || array.length == 0) { + return true; + } + return false; + } } 1.20 +66 -3 jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsTest.java Index: ArrayUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/ArrayUtilsTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- ArrayUtilsTest.java 8 Jan 2004 17:54:28 -0000 1.19 +++ ArrayUtilsTest.java 19 Jan 2004 21:50:06 -0000 1.20 @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2002-2003 The Apache Software Foundation. All rights + * Copyright (c) 2002-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,6 +73,7 @@ * @author Matthew Hawthorne * @author Tim O'Brien * @author Ashwin S + * @author Fredrik Westermarck * @version $Id$ */ public class ArrayUtilsTest extends TestCase { @@ -136,7 +137,7 @@ assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array3)); assertEquals(true, ArrayUtils.hashCode(array3) == ArrayUtils.hashCode(array4)); } - + //----------------------------------------------------------------------- public void testIsEquals() { long[][] array1 = new long[][] {{2,5}, {4,5}}; @@ -2289,4 +2290,66 @@ new double[] { Double.MIN_VALUE, Double.MAX_VALUE, 9999999 }))); } + //----------------------------------------------------------------------- + /** + * Test for {@link ArrayUtils#isEmpty(java.lang.Object[])}. + */ + public void testIsEmptyObject() { + Object[] emptyArray = new Object[] {}; + Object[] notEmptyArray = new Object[] { new String("Value") }; + assertEquals(true, ArrayUtils.isEmpty(emptyArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyArray)); + } + + /** + * Tests for {@link ArrayUtils#isEmpty(long[])}, + * {@link ArrayUtils#isEmpty(int[])}, + * {@link ArrayUtils#isEmpty(short[])}, + * {@link ArrayUtils#isEmpty(char[])}, + * {@link ArrayUtils#isEmpty(byte[])}, + * {@link ArrayUtils#isEmpty(double[])}, + * {@link ArrayUtils#isEmpty(float[])} and + * {@link ArrayUtils#isEmpty(boolean[])}. + */ + public void testIsEmptyPrimitives() { + long[] emptyLongArray = new long[] {}; + long[] notEmptyLongArray = new long[] { 1L }; + assertEquals(true, ArrayUtils.isEmpty(emptyLongArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyLongArray)); + + int[] emptyIntArray = new int[] {}; + int[] notEmptyIntArray = new int[] { 1 }; + assertEquals(true, ArrayUtils.isEmpty(emptyIntArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyIntArray)); + + short[] emptyShortArray = new short[] {}; + short[] notEmptyShortArray = new short[] { 1 }; + assertEquals(true, ArrayUtils.isEmpty(emptyShortArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyShortArray)); + + char[] emptyCharArray = new char[] {}; + char[] notEmptyCharArray = new char[] { 1 }; + assertEquals(true, ArrayUtils.isEmpty(emptyCharArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyCharArray)); + + byte[] emptyByteArray = new byte[] {}; + byte[] notEmptyByteArray = new byte[] { 1 }; + assertEquals(true, ArrayUtils.isEmpty(emptyByteArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyByteArray)); + + double[] emptyDoubleArray = new double[] {}; + double[] notEmptyDoubleArray = new double[] { 1.0 }; + assertEquals(true, ArrayUtils.isEmpty(emptyDoubleArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyDoubleArray)); + + float[] emptyFloatArray = new float[] {}; + float[] notEmptyFloatArray = new float[] { 1.0F }; + assertEquals(true, ArrayUtils.isEmpty(emptyFloatArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyFloatArray)); + + boolean[] emptyBooleanArray = new boolean[] {}; + boolean[] notEmptyBooleanArray = new boolean[] { true }; + assertEquals(true, ArrayUtils.isEmpty(emptyBooleanArray)); + assertEquals(false, ArrayUtils.isEmpty(notEmptyBooleanArray)); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org