Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 81855 invoked from network); 19 Jul 2003 20:17:16 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 19 Jul 2003 20:17:16 -0000 Received: (qmail 29598 invoked by uid 97); 19 Jul 2003 20:19:51 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 29591 invoked from network); 19 Jul 2003 20:19:50 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 19 Jul 2003 20:19:50 -0000 Received: (qmail 81622 invoked by uid 500); 19 Jul 2003 20:17:13 -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 81611 invoked by uid 500); 19 Jul 2003 20:17:13 -0000 Received: (qmail 81607 invoked from network); 19 Jul 2003 20:17:13 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 19 Jul 2003 20:17:13 -0000 Received: (qmail 40703 invoked by uid 1529); 19 Jul 2003 20:17:12 -0000 Date: 19 Jul 2003 20:17:12 -0000 Message-ID: <20030719201712.40702.qmail@icarus.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang BooleanUtils.java ClassUtils.java ArrayUtils.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N scolebourne 2003/07/19 13:17:12 Modified: lang/src/java/org/apache/commons/lang BooleanUtils.java ClassUtils.java ArrayUtils.java Log: Document null behaviour Revision Changes Path 1.8 +13 -8 jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java Index: BooleanUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/BooleanUtils.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- BooleanUtils.java 14 Jul 2003 22:25:02 -0000 1.7 +++ BooleanUtils.java 19 Jul 2003 20:17:12 -0000 1.8 @@ -59,6 +59,10 @@ *

BooleanUtils contains utility methods for working for * boolean and Boolean objects.

* + *

This class tries to handle null input gracefully. + * An exception will not be thrown for a null input. + * Each method documents its behaviour in more detail.

+ * * @author Stephen Colebourne * @author Matthew Hawthorne * @since 2.0 @@ -84,7 +88,7 @@ *

If null is passed in, null will be returned.

* * @param bool the Boolean to negate, may be null - * @return the negated Boolean, or null if null passed in + * @return the negated Boolean, or null if null input */ public static Boolean negate(Boolean bool) { if (bool == null) { @@ -112,7 +116,8 @@ * by returning false.

* * @param bool the boolean to convert - * @return true or false + * @return true or false, + * null returns false */ public static boolean toBoolean(Boolean bool) { if (bool == null) { @@ -169,7 +174,7 @@ * * @param value the Integer to convert * @return Boolean.TRUE if non-zero, Boolean.FALSE if zero, - * null if null + * null if null input */ public static Boolean toBooleanObject(Integer value) { if (value == null) { @@ -392,8 +397,8 @@ * Otherwise, null is returned.

* * @param str the String to check - * @return the Boolean value of the string, null - * if no match or null input + * @return the Boolean value of the string, + * null if no match or null input */ public static Boolean toBooleanObject(String str) { if ("true".equalsIgnoreCase(str)) { @@ -423,8 +428,8 @@ * (case sensitive), may be null * @param nullString the String to match for null * (case sensitive), may be null - * @return the Boolean value of the string, null - * if no match or null input + * @return the Boolean value of the string, + * null if no match or null input */ public static Boolean toBooleanObject(String str, String trueString, String falseString, String nullString) { if (str == null) { 1.16 +4 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/ClassUtils.java Index: ClassUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/ClassUtils.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ClassUtils.java 16 Jul 2003 21:19:22 -0000 1.15 +++ ClassUtils.java 19 Jul 2003 20:17:12 -0000 1.16 @@ -59,6 +59,9 @@ /** *

Provides utility methods for working for classes without using reflection.

* + *

This class throws exceptions for invalid null inputs. + * Each method documents its behaviour in more detail.

+ * * @author Stephen Colebourne * @author Gary Gregory * @since 2.0 1.19 +218 -206 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.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- ArrayUtils.java 14 Jul 2003 22:25:02 -0000 1.18 +++ ArrayUtils.java 19 Jul 2003 20:17:12 -0000 1.19 @@ -63,6 +63,11 @@ /** *

ArrayUtils contains utility methods for working with * arrays.

+ * + *

This class tries to handle null input gracefully. + * An exception will not be thrown for a null + * array input. However, an Object array that contains a null + * element may throw an exception. Each method documents its behaviour.

* * @author Stephen Colebourne * @author Moritz Petersen @@ -172,7 +177,7 @@ *

The format is that of Java source code, for example {a,b}.

* * @param array the array to get a toString for, may be null - * @return a String representation of the array, '{}' if null passed in + * @return a String representation of the array, '{}' if null array input */ public static String toString(final Object array) { return toString(array, "{}"); @@ -203,7 +208,7 @@ *

Multi-dimensional primitive arrays are also handled correctly by this method.

* * @param array the array to get a hashCode for, may be null - * @return a hashCode for the array + * @return a hashCode for the array, zero if null array input */ public static int hashCode(final Object array) { return new HashCodeBuilder().append(array).toHashCode(); @@ -288,8 +293,7 @@ *

This method returns null if null array input.

* * @param array the array to shallow clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static Object[] clone(final Object[] array) { if (array == null) { @@ -305,8 +309,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static long[] clone(final long[] array) { if (array == null) { @@ -322,8 +325,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static int[] clone(int[] array) { if (array == null) { @@ -339,8 +341,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static short[] clone(final short[] array) { if (array == null) { @@ -356,8 +357,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static char[] clone(final char[] array) { if (array == null) { @@ -373,8 +373,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static byte[] clone(final byte[] array) { if (array == null) { @@ -390,8 +389,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static double[] clone(final double[] array) { if (array == null) { @@ -407,8 +405,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static float[] clone(final float[] array) { if (array == null) { @@ -424,8 +421,7 @@ *

This method returns null if null array input.

* * @param array the array to clone, may be null - * @return the cloned array, or null if null - * passed in + * @return the cloned array, null if null input */ public static boolean[] clone(final boolean[] array) { if (array == null) { @@ -623,7 +619,7 @@ * *

There is no special handling for multi-dimensional arrays.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -646,7 +642,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -669,7 +665,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -692,7 +688,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -715,7 +711,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -738,7 +734,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -761,7 +757,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -784,7 +780,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -807,7 +803,7 @@ /** *

Reverses the order of the given array.

* - *

This method returns null if null array input.

+ *

This method does nothing if null array input.

* * @param array the array to reverse, may be null */ @@ -839,7 +835,8 @@ * * @param array the array to search through for the object, may be null * @param objectToFind the object to find, may be null - * @return the index of the object within the array, or -1 if not found + * @return the index of the object within the array, + * -1 if not found or null array input */ public static int indexOf(final Object[] array, final Object objectToFind) { return indexOf(array, objectToFind, 0); @@ -856,8 +853,8 @@ * @param array the array to search through for the object, may be null * @param objectToFind the object to find, may be null * @param startIndex the index to start searching at - * @return the index of the object within the array starting at the - * given index, or -1 if not found + * @return the index of the object within the array starting at the index, + * -1 if not found or null array input */ public static int indexOf(final Object[] array, final Object objectToFind, int startIndex) { if (array == null) { @@ -889,7 +886,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param objectToFind the object to find, may be null - * @return the last index of the object to find, or -1 if not found + * @return the last index of the object within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final Object[] array, final Object objectToFind) { return lastIndexOf(array, objectToFind, Integer.MAX_VALUE); @@ -906,8 +904,8 @@ * @param array the array to traverse for looking for the object, may be null * @param objectToFind the object to find, may be null * @param startIndex the start index to travers backwards from - * @return the last index of the object within the array starting at the given index, - * or -1 if not found + * @return the last index of the object within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final Object[] array, final Object objectToFind, int startIndex) { if (array == null) { @@ -956,7 +954,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final long[] array, final long valueToFind) { return indexOf(array, valueToFind, 0); @@ -973,8 +972,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final long[] array, final long valueToFind, int startIndex) { if (array == null) { @@ -998,7 +997,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final long[] array, final long valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1015,8 +1015,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final long[] array, final long valueToFind, int startIndex) { if (array == null) { @@ -1057,7 +1057,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final int[] array, final int valueToFind) { return indexOf(array, valueToFind, 0); @@ -1074,8 +1075,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final int[] array, final int valueToFind, int startIndex) { if (array == null) { @@ -1099,7 +1100,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final int[] array, final int valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1116,8 +1118,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final int[] array, final int valueToFind, int startIndex) { if (array == null) { @@ -1158,7 +1160,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final short[] array, final short valueToFind) { return indexOf(array, valueToFind, 0); @@ -1175,8 +1178,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final short[] array, final short valueToFind, int startIndex) { if (array == null) { @@ -1200,7 +1203,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final short[] array, final short valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1217,8 +1221,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final short[] array, final short valueToFind, int startIndex) { if (array == null) { @@ -1259,7 +1263,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final byte[] array, final byte valueToFind) { return indexOf(array, valueToFind, 0); @@ -1276,8 +1281,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final byte[] array, final byte valueToFind, int startIndex) { if (array == null) { @@ -1301,7 +1306,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final byte[] array, final byte valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1318,8 +1324,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final byte[] array, final byte valueToFind, int startIndex) { if (array == null) { @@ -1360,7 +1366,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final double[] array, final double valueToFind) { return indexOf(array, valueToFind, 0); @@ -1377,8 +1384,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final double[] array, final double valueToFind, int startIndex) { if (array == null) { @@ -1402,7 +1409,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final double[] array, final double valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1419,8 +1427,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex) { if (array == null) { @@ -1461,7 +1469,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final float[] array, final float valueToFind) { return indexOf(array, valueToFind, 0); @@ -1478,8 +1487,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final float[] array, final float valueToFind, int startIndex) { if (array == null) { @@ -1503,7 +1512,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final float[] array, final float valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1520,8 +1530,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final float[] array, final float valueToFind, int startIndex) { if (array == null) { @@ -1562,7 +1572,8 @@ * * @param array the array to search through for the object, may be null * @param valueToFind the value to find - * @return the index of the value within the array, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final boolean[] array, final boolean valueToFind) { return indexOf(array, valueToFind, 0); @@ -1579,8 +1590,8 @@ * @param array the array to search through for the object, may be null * @param valueToFind the value to find * @param startIndex the index to start searching at - * @return the index of the value within the array starting at the - * given index, or -1 if not found + * @return the index of the value within the array, + * -1 if not found or null array input */ public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) { if (array == null) { @@ -1604,7 +1615,8 @@ * * @param array the array to travers backwords looking for the object, may be null * @param valueToFind the object to find - * @return the last index of the value to find, or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final boolean[] array, final boolean valueToFind) { return lastIndexOf(array, valueToFind, Integer.MAX_VALUE); @@ -1621,8 +1633,8 @@ * @param array the array to traverse for looking for the object, may be null * @param valueToFind the value to find * @param startIndex the start index to travers backwards from - * @return the last index of the value within the array starting at the given index, - * or -1 if not found + * @return the last index of the value within the array, + * -1 if not found or null array input */ public static int lastIndexOf(final boolean[] array, final boolean valueToFind, int startIndex) { if (array == null) { @@ -1657,141 +1669,141 @@ // Primitive/Object array converters // ---------------------------------------------------------------------- - // Boolean array converters + // Long array converters // ---------------------------------------------------------------------- /** - *

Converts an array of object Booleans to primitives.

+ *

Converts an array of object Longs to primitives.

* *

This method returns null if null array input.

* - * @param array a Boolean array, may be null - * @return a boolean array + * @param array a Long array, may be null + * @return a long array, null if null array input * @throws NullPointerException if array content is null */ - public static boolean[] toPrimitive(final Boolean[] array) { + public static long[] toPrimitive(final Long[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BOOLEAN_ARRAY; + return EMPTY_LONG_ARRAY; } - final boolean[] result = new boolean[array.length]; + final long[] result = new long[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].booleanValue(); + result[i] = array[i].longValue(); } return result; } - + /** - *

Converts an array of object Booleans to primitives handling null.

+ *

Converts an array of object Long to primitives handling null.

* *

This method returns null if null array input.

* - * @param array a Boolean array, may be null + * @param array a Long array, may be null * @param valueForNull the value to insert if null found - * @return a boolean array + * @return a long array, null if null array input */ - public static boolean[] toPrimitive(final Boolean[] array, final boolean valueForNull) { + public static long[] toPrimitive(final Long[] array, final long valueForNull) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BOOLEAN_ARRAY; + return EMPTY_LONG_ARRAY; } - final boolean[] result = new boolean[array.length]; + final long[] result = new long[array.length]; for (int i = 0; i < array.length; i++) { - Boolean b = array[i]; - result[i] = (b == null ? valueForNull : b.booleanValue()); + Long b = array[i]; + result[i] = (b == null ? valueForNull : b.longValue()); } return result; } - + /** - *

Converts an array of primitive booleans to objects.

+ *

Converts an array of primitive longs to objects.

* *

This method returns null if null array input.

* - * @param array a boolean array - * @return a Boolean array + * @param array a long array + * @return a Long array, null if null array input */ - public static Boolean[] toObject(final boolean[] array) { + public static Long[] toObject(final long[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BOOLEAN_OBJECT_ARRAY; + return EMPTY_LONG_OBJECT_ARRAY; } - final Boolean[] result = new Boolean[array.length]; + final Long[] result = new Long[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = (array[i] ? Boolean.TRUE : Boolean.FALSE); + result[i] = new Long(array[i]); } return result; } - // Byte array converters + // Int array converters // ---------------------------------------------------------------------- /** - *

Converts an array of object Bytes to primitives.

+ *

Converts an array of object Integers to primitives.

* *

This method returns null if null array input.

* - * @param array a Byte array, may be null - * @return a byte array + * @param array a Integer array, may be null + * @return an int array, null if null array input * @throws NullPointerException if array content is null */ - public static byte[] toPrimitive(final Byte[] array) { + public static int[] toPrimitive(final Integer[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BYTE_ARRAY; + return EMPTY_INT_ARRAY; } - final byte[] result = new byte[array.length]; + final int[] result = new int[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].byteValue(); + result[i] = array[i].intValue(); } return result; } /** - *

Converts an array of object Bytes to primitives handling null.

+ *

Converts an array of object Integer to primitives handling null.

* *

This method returns null if null array input.

* - * @param array a Byte array, may be null + * @param array a Integer array, may be null * @param valueForNull the value to insert if null found - * @return a byte array + * @return an int array, null if null array input */ - public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) { + public static int[] toPrimitive(final Integer[] array, final int valueForNull) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BYTE_ARRAY; + return EMPTY_INT_ARRAY; } - final byte[] result = new byte[array.length]; + final int[] result = new int[array.length]; for (int i = 0; i < array.length; i++) { - Byte b = array[i]; - result[i] = (b == null ? valueForNull : b.byteValue()); + Integer b = array[i]; + result[i] = (b == null ? valueForNull : b.intValue()); } return result; } /** - *

Converts an array of primitive bytes to objects.

+ *

Converts an array of primitive ints to objects.

* *

This method returns null if null array input.

* - * @param array a byte array - * @return a Byte array + * @param array an int array + * @return an Integer array, null if null array input */ - public static Byte[] toObject(final byte[] array) { + public static Integer[] toObject(final int[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_BYTE_OBJECT_ARRAY; + return EMPTY_INTEGER_OBJECT_ARRAY; } - final Byte[] result = new Byte[array.length]; + final Integer[] result = new Integer[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = new Byte(array[i]); + result[i] = new Integer(array[i]); } return result; - } + } // Short array converters // ---------------------------------------------------------------------- @@ -1801,7 +1813,7 @@ *

This method returns null if null array input.

* * @param array a Short array, may be null - * @return a byte array + * @return a byte array, null if null array input * @throws NullPointerException if array content is null */ public static short[] toPrimitive(final Short[] array) { @@ -1824,7 +1836,7 @@ * * @param array a Short array, may be null * @param valueForNull the value to insert if null found - * @return a byte array + * @return a byte array, null if null array input */ public static short[] toPrimitive(final Short[] array, final short valueForNull) { if (array == null) { @@ -1846,7 +1858,7 @@ *

This method returns null if null array input.

* * @param array a short array - * @return a Short array + * @return a Short array, null if null array input */ public static Short[] toObject(final short[] array) { if (array == null) { @@ -1861,138 +1873,138 @@ return result; } - // Int array converters + // Byte array converters // ---------------------------------------------------------------------- /** - *

Converts an array of object Integers to primitives.

+ *

Converts an array of object Bytes to primitives.

* *

This method returns null if null array input.

* - * @param array a Integer array, may be null - * @return an int array + * @param array a Byte array, may be null + * @return a byte array, null if null array input * @throws NullPointerException if array content is null */ - public static int[] toPrimitive(final Integer[] array) { + public static byte[] toPrimitive(final Byte[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_INT_ARRAY; + return EMPTY_BYTE_ARRAY; } - final int[] result = new int[array.length]; + final byte[] result = new byte[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].intValue(); + result[i] = array[i].byteValue(); } return result; } /** - *

Converts an array of object Integer to primitives handling null.

+ *

Converts an array of object Bytes to primitives handling null.

* *

This method returns null if null array input.

* - * @param array a Integer array, may be null + * @param array a Byte array, may be null * @param valueForNull the value to insert if null found - * @return an int array + * @return a byte array, null if null array input */ - public static int[] toPrimitive(final Integer[] array, final int valueForNull) { + public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_INT_ARRAY; + return EMPTY_BYTE_ARRAY; } - final int[] result = new int[array.length]; + final byte[] result = new byte[array.length]; for (int i = 0; i < array.length; i++) { - Integer b = array[i]; - result[i] = (b == null ? valueForNull : b.intValue()); + Byte b = array[i]; + result[i] = (b == null ? valueForNull : b.byteValue()); } return result; } /** - *

Converts an array of primitive ints to objects.

+ *

Converts an array of primitive bytes to objects.

* *

This method returns null if null array input.

* - * @param array an int array - * @return an Integer array + * @param array a byte array + * @return a Byte array, null if null array input */ - public static Integer[] toObject(final int[] array) { + public static Byte[] toObject(final byte[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_INTEGER_OBJECT_ARRAY; + return EMPTY_BYTE_OBJECT_ARRAY; } - final Integer[] result = new Integer[array.length]; + final Byte[] result = new Byte[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = new Integer(array[i]); + result[i] = new Byte(array[i]); } return result; - } + } - // Long array converters + // Double array converters // ---------------------------------------------------------------------- /** - *

Converts an array of object Longs to primitives.

+ *

Converts an array of object Doubles to primitives.

* *

This method returns null if null array input.

* - * @param array a Long array, may be null - * @return a long array + * @param array a Double array, may be null + * @return a double array, null if null array input * @throws NullPointerException if array content is null */ - public static long[] toPrimitive(final Long[] array) { + public static double[] toPrimitive(final Double[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_LONG_ARRAY; + return EMPTY_DOUBLE_ARRAY; } - final long[] result = new long[array.length]; + final double[] result = new double[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].longValue(); + result[i] = array[i].doubleValue(); } return result; } - + /** - *

Converts an array of object Long to primitives handling null.

+ *

Converts an array of object Doubles to primitives handling null.

* *

This method returns null if null array input.

* - * @param array a Long array, may be null + * @param array a Double array, may be null * @param valueForNull the value to insert if null found - * @return a long array + * @return a double array, null if null array input */ - public static long[] toPrimitive(final Long[] array, final long valueForNull) { + public static double[] toPrimitive(final Double[] array, final double valueForNull) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_LONG_ARRAY; + return EMPTY_DOUBLE_ARRAY; } - final long[] result = new long[array.length]; + final double[] result = new double[array.length]; for (int i = 0; i < array.length; i++) { - Long b = array[i]; - result[i] = (b == null ? valueForNull : b.longValue()); + Double b = array[i]; + result[i] = (b == null ? valueForNull : b.doubleValue()); } return result; } - + /** - *

Converts an array of primitive longs to objects.

+ *

Converts an array of primitive doubles to objects.

* *

This method returns null if null array input.

* - * @param array a long array - * @return a Long array + * @param array a double array + * @return a Double array, null if null array input */ - public static Long[] toObject(final long[] array) { + public static Double[] toObject(final double[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_LONG_OBJECT_ARRAY; + return EMPTY_DOUBLE_OBJECT_ARRAY; } - final Long[] result = new Long[array.length]; + final Double[] result = new Double[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = new Long(array[i]); + result[i] = new Double(array[i]); } return result; } @@ -2005,7 +2017,7 @@ *

This method returns null if null array input.

* * @param array a Float array, may be null - * @return a float array + * @return a float array, null if null array input * @throws NullPointerException if array content is null */ public static float[] toPrimitive(final Float[] array) { @@ -2028,7 +2040,7 @@ * * @param array a Float array, may be null * @param valueForNull the value to insert if null found - * @return a float array + * @return a float array, null if null array input */ public static float[] toPrimitive(final Float[] array, final float valueForNull) { if (array == null) { @@ -2049,8 +2061,8 @@ * *

This method returns null if null array input.

* - * @param array a float array - * @return a Float array + * @param array a float array + * @return a Float array, null if null array input */ public static Float[] toObject(final float[] array) { if (array == null) { @@ -2065,70 +2077,70 @@ return result; } - // Double array converters + // Boolean array converters // ---------------------------------------------------------------------- /** - *

Converts an array of object Doubles to primitives.

+ *

Converts an array of object Booleans to primitives.

* *

This method returns null if null array input.

* - * @param array a Double array, may be null - * @return a double array + * @param array a Boolean array, may be null + * @return a boolean array, null if null array input * @throws NullPointerException if array content is null */ - public static double[] toPrimitive(final Double[] array) { + public static boolean[] toPrimitive(final Boolean[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_DOUBLE_ARRAY; + return EMPTY_BOOLEAN_ARRAY; } - final double[] result = new double[array.length]; + final boolean[] result = new boolean[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].doubleValue(); + result[i] = array[i].booleanValue(); } return result; } /** - *

Converts an array of object Doubles to primitives handling null.

+ *

Converts an array of object Booleans to primitives handling null.

* *

This method returns null if null array input.

* - * @param array a Double array, may be null + * @param array a Boolean array, may be null * @param valueForNull the value to insert if null found - * @return a double array + * @return a boolean array, null if null array input */ - public static double[] toPrimitive(final Double[] array, final double valueForNull) { + public static boolean[] toPrimitive(final Boolean[] array, final boolean valueForNull) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_DOUBLE_ARRAY; + return EMPTY_BOOLEAN_ARRAY; } - final double[] result = new double[array.length]; + final boolean[] result = new boolean[array.length]; for (int i = 0; i < array.length; i++) { - Double b = array[i]; - result[i] = (b == null ? valueForNull : b.doubleValue()); + Boolean b = array[i]; + result[i] = (b == null ? valueForNull : b.booleanValue()); } return result; } /** - *

Converts an array of primitive doubles to objects.

+ *

Converts an array of primitive booleans to objects.

* *

This method returns null if null array input.

* - * @param array a double array - * @return a Double array + * @param array a boolean array + * @return a Boolean array, null if null array input */ - public static Double[] toObject(final double[] array) { + public static Boolean[] toObject(final boolean[] array) { if (array == null) { return null; } else if (array.length == 0) { - return EMPTY_DOUBLE_OBJECT_ARRAY; + return EMPTY_BOOLEAN_OBJECT_ARRAY; } - final Double[] result = new Double[array.length]; + final Boolean[] result = new Boolean[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = new Double(array[i]); + result[i] = (array[i] ? Boolean.TRUE : Boolean.FALSE); } return result; } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org