Author: bayard
Date: Wed Feb 3 07:20:40 2010
New Revision: 905917
URL: http://svn.apache.org/viewvc?rev=905917&view=rev
Log:
Applying Chandrashekar M's patch to LANG-583, adding isNotEmpty(array) methods
to ArrayUtils.
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java?rev=905917&r1=905916&r2=905917&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
(original)
+++
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/ArrayUtils.java
Wed Feb 3 07:20:40 2010
@@ -2974,6 +2974,106 @@
return false;
}
+ // ----------------------------------------------------------------------
+ /**
+ * <p>Checks if an array of Objects is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static <T> boolean isNotEmpty(T[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive longs is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(long[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive ints is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(int[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive shorts is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(short[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive chars is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(char[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive bytes is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(byte[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive doubles is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(double[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive floats is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(float[] array) {
+ return (array != null && array.length != 0);
+ }
+
+ /**
+ * <p>Checks if an array of primitive booleans is not empty or <code>not
null</code>.</p>
+ *
+ * @param array the array to test
+ * @return <code>true</code> if the array is not empty or <code>not
null</code>
+ *
+ */
+ public static boolean isNotEmpty(boolean[] array) {
+ return (array != null && array.length != 0);
+ }
+
/**
* <p>Adds all the elements of the given arrays into a new array.</p>
* <p>The new array contains all of the element of <code>array1</code>
followed
Modified:
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java?rev=905917&r1=905916&r2=905917&view=diff
==============================================================================
---
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
(original)
+++
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
Wed Feb 3 07:20:40 2010
@@ -2542,6 +2542,76 @@
assertEquals(false, ArrayUtils.isEmpty(notEmptyBooleanArray));
}
+ /**
+ * Test for {...@link ArrayUtils#isNotEmpty(java.lang.Object[])}.
+ */
+ public void testIsNotEmptyObject() {
+ Object[] emptyArray = new Object[] {};
+ Object[] notEmptyArray = new Object[] { new String("Value") };
+ assertFalse(ArrayUtils.isNotEmpty((Object[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyArray));
+ }
+
+ /**
+ * Tests for {...@link ArrayUtils#isNotEmpty(long[])},
+ * {...@link ArrayUtils#isNotEmpty(int[])},
+ * {...@link ArrayUtils#isNotEmpty(short[])},
+ * {...@link ArrayUtils#isNotEmpty(char[])},
+ * {...@link ArrayUtils#isNotEmpty(byte[])},
+ * {...@link ArrayUtils#isNotEmpty(double[])},
+ * {...@link ArrayUtils#isNotEmpty(float[])} and
+ * {...@link ArrayUtils#isNotEmpty(boolean[])}.
+ */
+ public void testIsNotEmptyPrimitives() {
+ long[] emptyLongArray = new long[] {};
+ long[] notEmptyLongArray = new long[] { 1L };
+ assertFalse(ArrayUtils.isNotEmpty((long[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyLongArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyLongArray));
+
+ int[] emptyIntArray = new int[] {};
+ int[] notEmptyIntArray = new int[] { 1 };
+ assertFalse(ArrayUtils.isNotEmpty((int[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyIntArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyIntArray));
+
+ short[] emptyShortArray = new short[] {};
+ short[] notEmptyShortArray = new short[] { 1 };
+ assertFalse(ArrayUtils.isNotEmpty((short[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyShortArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyShortArray));
+
+ char[] emptyCharArray = new char[] {};
+ char[] notEmptyCharArray = new char[] { 1 };
+ assertFalse(ArrayUtils.isNotEmpty((char[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyCharArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyCharArray));
+
+ byte[] emptyByteArray = new byte[] {};
+ byte[] notEmptyByteArray = new byte[] { 1 };
+ assertFalse(ArrayUtils.isNotEmpty((byte[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyByteArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyByteArray));
+
+ double[] emptyDoubleArray = new double[] {};
+ double[] notEmptyDoubleArray = new double[] { 1.0 };
+ assertFalse(ArrayUtils.isNotEmpty((double[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyDoubleArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyDoubleArray));
+
+ float[] emptyFloatArray = new float[] {};
+ float[] notEmptyFloatArray = new float[] { 1.0F };
+ assertFalse(ArrayUtils.isNotEmpty((float[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyFloatArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyFloatArray));
+
+ boolean[] emptyBooleanArray = new boolean[] {};
+ boolean[] notEmptyBooleanArray = new boolean[] { true };
+ assertFalse(ArrayUtils.isNotEmpty((boolean[])null));
+ assertFalse(ArrayUtils.isNotEmpty(emptyBooleanArray));
+ assertTrue(ArrayUtils.isNotEmpty(notEmptyBooleanArray));
+ }
// ------------------------------------------------------------------------
public void testGetLength() {
assertEquals(0, ArrayUtils.getLength(null));