You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2003/07/19 22:17:12 UTC
cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang BooleanUtils.java ClassUtils.java ArrayUtils.java
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 @@
* <p><code>BooleanUtils</code> contains utility methods for working for
* boolean and Boolean objects.</p>
*
+ * <p>This class tries to handle <code>null</code> input gracefully.
+ * An exception will not be thrown for a <code>null</code> input.
+ * Each method documents its behaviour in more detail.</p>
+ *
* @author Stephen Colebourne
* @author Matthew Hawthorne
* @since 2.0
@@ -84,7 +88,7 @@
* <p>If <code>null</code> is passed in, <code>null</code> will be returned.</p>
*
* @param bool the Boolean to negate, may be null
- * @return the negated Boolean, or <code>null</code> if <code>null</code> passed in
+ * @return the negated Boolean, or <code>null</code> if <code>null</code> input
*/
public static Boolean negate(Boolean bool) {
if (bool == null) {
@@ -112,7 +116,8 @@
* by returning <code>false</code>.</p>
*
* @param bool the boolean to convert
- * @return <code>true</code> or <code>false</code>
+ * @return <code>true</code> or <code>false</code>,
+ * <code>null</code> returns <code>false</code>
*/
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,
- * <code>null</code> if <code>null</code>
+ * <code>null</code> if <code>null</code> input
*/
public static Boolean toBooleanObject(Integer value) {
if (value == null) {
@@ -392,8 +397,8 @@
* Otherwise, <code>null</code> is returned.</p>
*
* @param str the String to check
- * @return the Boolean value of the string, <code>null</code>
- * if no match or <code>null</code> input
+ * @return the Boolean value of the string,
+ * <code>null</code> if no match or <code>null</code> input
*/
public static Boolean toBooleanObject(String str) {
if ("true".equalsIgnoreCase(str)) {
@@ -423,8 +428,8 @@
* (case sensitive), may be <code>null</code>
* @param nullString the String to match for <code>null</code>
* (case sensitive), may be <code>null</code>
- * @return the Boolean value of the string, <code>null</code>
- * if no match or <code>null</code> input
+ * @return the Boolean value of the string,
+ * <code>null</code> if no match or <code>null</code> 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 @@
/**
* <p>Provides utility methods for working for classes without using reflection.</p>
*
+ * <p>This class throws exceptions for invalid <code>null</code> inputs.
+ * Each method documents its behaviour in more detail.</p>
+ *
* @author Stephen Colebourne
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @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 @@
/**
* <p><code>ArrayUtils</code> contains utility methods for working with
* arrays.</p>
+ *
+ * <p>This class tries to handle <code>null</code> input gracefully.
+ * An exception will not be thrown for a <code>null</code>
+ * array input. However, an Object array that contains a <code>null</code>
+ * element may throw an exception. Each method documents its behaviour.</p>
*
* @author Stephen Colebourne
* @author Moritz Petersen
@@ -172,7 +177,7 @@
* <p>The format is that of Java source code, for example <code>{a,b}</code>.</p>
*
* @param array the array to get a toString for, may be <code>null</code>
- * @return a String representation of the array, '{}' if <code>null</code> 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 @@
* <p>Multi-dimensional primitive arrays are also handled correctly by this method.</p>
*
* @param array the array to get a hashCode for, may be <code>null</code>
- * @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 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to shallow clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static Object[] clone(final Object[] array) {
if (array == null) {
@@ -305,8 +309,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static long[] clone(final long[] array) {
if (array == null) {
@@ -322,8 +325,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static int[] clone(int[] array) {
if (array == null) {
@@ -339,8 +341,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static short[] clone(final short[] array) {
if (array == null) {
@@ -356,8 +357,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static char[] clone(final char[] array) {
if (array == null) {
@@ -373,8 +373,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static byte[] clone(final byte[] array) {
if (array == null) {
@@ -390,8 +389,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static double[] clone(final double[] array) {
if (array == null) {
@@ -407,8 +405,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static float[] clone(final float[] array) {
if (array == null) {
@@ -424,8 +421,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array the array to clone, may be <code>null</code>
- * @return the cloned array, or <code>null</code> if <code>null</code>
- * passed in
+ * @return the cloned array, <code>null</code> if <code>null</code> input
*/
public static boolean[] clone(final boolean[] array) {
if (array == null) {
@@ -623,7 +619,7 @@
*
* <p>There is no special handling for multi-dimensional arrays.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -646,7 +642,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -669,7 +665,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -692,7 +688,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -715,7 +711,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -738,7 +734,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -761,7 +757,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -784,7 +780,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -807,7 +803,7 @@
/**
* <p>Reverses the order of the given array.</p>
*
- * <p>This method returns <code>null</code> if <code>null</code> array input.</p>
+ * <p>This method does nothing if <code>null</code> array input.</p>
*
* @param array the array to reverse, may be <code>null</code>
*/
@@ -839,7 +835,8 @@
*
* @param array the array to search through for the object, may be <code>null</code>
* @param objectToFind the object to find, may be <code>null</code>
- * @return the index of the object within the array, or <code>-1</code> if not found
+ * @return the index of the object within the array,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @param objectToFind the object to find, may be <code>null</code>
* @param startIndex the index to start searching at
- * @return the index of the object within the array starting at the
- * given index, or <code>-1</code> if not found
+ * @return the index of the object within the array starting at the index,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @param objectToFind the object to find, may be <code>null</code>
- * @return the last index of the object to find, or <code>-1</code> if not found
+ * @return the last index of the object within the array,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @param objectToFind the object to find, may be <code>null</code>
* @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 <code>-1</code> if not found
+ * @return the last index of the object within the array,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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 <code>null</code>
* @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,
+ * <code>-1</code> if not found or <code>null</code> 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
// ----------------------------------------------------------------------
/**
- * <p>Converts an array of object Booleans to primitives.</p>
+ * <p>Converts an array of object Longs to primitives.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Boolean</code> array, may be <code>null</code>
- * @return a <code>boolean</code> array
+ * @param array a <code>Long</code> array, may be <code>null</code>
+ * @return a <code>long</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
- 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;
}
-
+
/**
- * <p>Converts an array of object Booleans to primitives handling <code>null</code>.</p>
+ * <p>Converts an array of object Long to primitives handling <code>null</code>.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Boolean</code> array, may be <code>null</code>
+ * @param array a <code>Long</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>boolean</code> array
+ * @return a <code>long</code> array, <code>null</code> 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;
}
-
+
/**
- * <p>Converts an array of primitive booleans to objects.</p>
+ * <p>Converts an array of primitive longs to objects.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>boolean</code> array
- * @return a <code>Boolean</code> array
+ * @param array a <code>long</code> array
+ * @return a <code>Long</code> array, <code>null</code> 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
// ----------------------------------------------------------------------
/**
- * <p>Converts an array of object Bytes to primitives.</p>
+ * <p>Converts an array of object Integers to primitives.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Byte</code> array, may be <code>null</code>
- * @return a <code>byte</code> array
+ * @param array a <code>Integer</code> array, may be <code>null</code>
+ * @return an <code>int</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
- 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;
}
/**
- * <p>Converts an array of object Bytes to primitives handling <code>null</code>.</p>
+ * <p>Converts an array of object Integer to primitives handling <code>null</code>.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Byte</code> array, may be <code>null</code>
+ * @param array a <code>Integer</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>byte</code> array
+ * @return an <code>int</code> array, <code>null</code> 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;
}
/**
- * <p>Converts an array of primitive bytes to objects.</p>
+ * <p>Converts an array of primitive ints to objects.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>byte</code> array
- * @return a <code>Byte</code> array
+ * @param array an <code>int</code> array
+ * @return an <code>Integer</code> array, <code>null</code> 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 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array a <code>Short</code> array, may be <code>null</code>
- * @return a <code>byte</code> array
+ * @return a <code>byte</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
public static short[] toPrimitive(final Short[] array) {
@@ -1824,7 +1836,7 @@
*
* @param array a <code>Short</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>byte</code> array
+ * @return a <code>byte</code> array, <code>null</code> if null array input
*/
public static short[] toPrimitive(final Short[] array, final short valueForNull) {
if (array == null) {
@@ -1846,7 +1858,7 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array a <code>short</code> array
- * @return a <code>Short</code> array
+ * @return a <code>Short</code> array, <code>null</code> 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
// ----------------------------------------------------------------------
/**
- * <p>Converts an array of object Integers to primitives.</p>
+ * <p>Converts an array of object Bytes to primitives.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Integer</code> array, may be <code>null</code>
- * @return an <code>int</code> array
+ * @param array a <code>Byte</code> array, may be <code>null</code>
+ * @return a <code>byte</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
- 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;
}
/**
- * <p>Converts an array of object Integer to primitives handling <code>null</code>.</p>
+ * <p>Converts an array of object Bytes to primitives handling <code>null</code>.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Integer</code> array, may be <code>null</code>
+ * @param array a <code>Byte</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return an <code>int</code> array
+ * @return a <code>byte</code> array, <code>null</code> 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;
}
/**
- * <p>Converts an array of primitive ints to objects.</p>
+ * <p>Converts an array of primitive bytes to objects.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array an <code>int</code> array
- * @return an <code>Integer</code> array
+ * @param array a <code>byte</code> array
+ * @return a <code>Byte</code> array, <code>null</code> 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
// ----------------------------------------------------------------------
/**
- * <p>Converts an array of object Longs to primitives.</p>
+ * <p>Converts an array of object Doubles to primitives.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Long</code> array, may be <code>null</code>
- * @return a <code>long</code> array
+ * @param array a <code>Double</code> array, may be <code>null</code>
+ * @return a <code>double</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
- 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;
}
-
+
/**
- * <p>Converts an array of object Long to primitives handling <code>null</code>.</p>
+ * <p>Converts an array of object Doubles to primitives handling <code>null</code>.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Long</code> array, may be <code>null</code>
+ * @param array a <code>Double</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>long</code> array
+ * @return a <code>double</code> array, <code>null</code> 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;
}
-
+
/**
- * <p>Converts an array of primitive longs to objects.</p>
+ * <p>Converts an array of primitive doubles to objects.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>long</code> array
- * @return a <code>Long</code> array
+ * @param array a <code>double</code> array
+ * @return a <code>Double</code> array, <code>null</code> 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 @@
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
* @param array a <code>Float</code> array, may be <code>null</code>
- * @return a <code>float</code> array
+ * @return a <code>float</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
public static float[] toPrimitive(final Float[] array) {
@@ -2028,7 +2040,7 @@
*
* @param array a <code>Float</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>float</code> array
+ * @return a <code>float</code> array, <code>null</code> if null array input
*/
public static float[] toPrimitive(final Float[] array, final float valueForNull) {
if (array == null) {
@@ -2049,8 +2061,8 @@
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>float</code> array
- * @return a <code>Float</code> array
+ * @param array a <code>float</code> array
+ * @return a <code>Float</code> array, <code>null</code> 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
// ----------------------------------------------------------------------
/**
- * <p>Converts an array of object Doubles to primitives.</p>
+ * <p>Converts an array of object Booleans to primitives.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Double</code> array, may be <code>null</code>
- * @return a <code>double</code> array
+ * @param array a <code>Boolean</code> array, may be <code>null</code>
+ * @return a <code>boolean</code> array, <code>null</code> if null array input
* @throws NullPointerException if array content is <code>null</code>
*/
- 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;
}
/**
- * <p>Converts an array of object Doubles to primitives handling <code>null</code>.</p>
+ * <p>Converts an array of object Booleans to primitives handling <code>null</code>.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>Double</code> array, may be <code>null</code>
+ * @param array a <code>Boolean</code> array, may be <code>null</code>
* @param valueForNull the value to insert if <code>null</code> found
- * @return a <code>double</code> array
+ * @return a <code>boolean</code> array, <code>null</code> 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;
}
/**
- * <p>Converts an array of primitive doubles to objects.</p>
+ * <p>Converts an array of primitive booleans to objects.</p>
*
* <p>This method returns <code>null</code> if <code>null</code> array input.</p>
*
- * @param array a <code>double</code> array
- * @return a <code>Double</code> array
+ * @param array a <code>boolean</code> array
+ * @return a <code>Boolean</code> array, <code>null</code> 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