From a9d8e8770aaa02c94b1976f513dece35de1c56aa Mon Sep 17 00:00:00 2001 From: Fredrik Westermarck Date: Mon, 19 Jan 2004 23:24:07 +0000 Subject: [PATCH] Using ArrayUtils.isEmpty() when testing arrays. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137758 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang/ArrayUtils.java | 18 +++++++++--------- .../org/apache/commons/lang/CharSetUtils.java | 12 ++++++------ src/java/org/apache/commons/lang/Validate.java | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/commons/lang/ArrayUtils.java b/src/java/org/apache/commons/lang/ArrayUtils.java index 7eb8d4b92..06658618a 100644 --- a/src/java/org/apache/commons/lang/ArrayUtils.java +++ b/src/java/org/apache/commons/lang/ArrayUtils.java @@ -82,7 +82,7 @@ import org.apache.commons.lang.builder.ToStringStyle; * @author Ashwin S * @author Fredrik Westermarck * @since 2.0 - * @version $Id: ArrayUtils.java,v 1.32 2004/01/19 21:50:06 fredrik Exp $ + * @version $Id: ArrayUtils.java,v 1.33 2004/01/19 23:24:07 fredrik Exp $ */ public class ArrayUtils { @@ -1765,7 +1765,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int indexOf(final double[] array, final double valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -1797,7 +1797,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int indexOf(final double[] array, final double valueToFind, int startIndex, double tolerance) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -1859,7 +1859,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -1893,7 +1893,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int lastIndexOf(final double[] array, final double valueToFind, int startIndex, double tolerance) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -1972,7 +1972,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int indexOf(final float[] array, final float valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -2015,7 +2015,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int lastIndexOf(final float[] array, final float valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -2075,7 +2075,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int indexOf(final boolean[] array, final boolean valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { @@ -2118,7 +2118,7 @@ public class ArrayUtils { * -1 if not found or null array input */ public static int lastIndexOf(final boolean[] array, final boolean valueToFind, int startIndex) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { return -1; } if (startIndex < 0) { diff --git a/src/java/org/apache/commons/lang/CharSetUtils.java b/src/java/org/apache/commons/lang/CharSetUtils.java index 7c1fd25a4..a83c739e5 100644 --- a/src/java/org/apache/commons/lang/CharSetUtils.java +++ b/src/java/org/apache/commons/lang/CharSetUtils.java @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2002-2003 The Apache Software Foundation. All rights + * Copyright (c) 2002-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,7 +66,7 @@ package org.apache.commons.lang; * @author Phil Steitz * @author Gary Gregory * @since 1.0 - * @version $Id: CharSetUtils.java,v 1.29 2003/11/04 21:16:34 fredrik Exp $ + * @version $Id: CharSetUtils.java,v 1.30 2004/01/19 23:24:07 fredrik Exp $ */ public class CharSetUtils { @@ -154,7 +154,7 @@ public class CharSetUtils { * @return modified String, null if null string input */ public static String squeeze(String str, String[] set) { - if (StringUtils.isEmpty(str) || set == null || set.length == 0) { + if (StringUtils.isEmpty(str) || ArrayUtils.isEmpty(set)) { return str; } CharSet chars = evaluateSet(set); @@ -220,7 +220,7 @@ public class CharSetUtils { * @return character count, zero if null string input */ public static int count(String str, String[] set) { - if (StringUtils.isEmpty(str) || set == null || set.length == 0) { + if (StringUtils.isEmpty(str) || ArrayUtils.isEmpty(set)) { return 0; } CharSet chars = evaluateSet(set); @@ -288,7 +288,7 @@ public class CharSetUtils { if (str == null) { return null; } - if (str.length() == 0 || set == null || set.length == 0) { + if (str.length() == 0 || ArrayUtils.isEmpty(set)) { return ""; } return modify(str, set, true); @@ -339,7 +339,7 @@ public class CharSetUtils { * @return modified String, null if null string input */ public static String delete(String str, String[] set) { - if (StringUtils.isEmpty(str) || set == null || set.length == 0) { + if (StringUtils.isEmpty(str) || ArrayUtils.isEmpty(set)) { return str; } return modify(str, set, false); diff --git a/src/java/org/apache/commons/lang/Validate.java b/src/java/org/apache/commons/lang/Validate.java index 5c57e0cc8..6d67047a3 100644 --- a/src/java/org/apache/commons/lang/Validate.java +++ b/src/java/org/apache/commons/lang/Validate.java @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2002-2003 The Apache Software Foundation. All rights + * Copyright (c) 2002-2004 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -72,7 +72,7 @@ import java.util.Map; * @author Stephen Colebourne * @author Gary Gregory * @since 2.0 - * @version $Id: Validate.java,v 1.6 2003/08/23 10:39:20 scolebourne Exp $ + * @version $Id: Validate.java,v 1.7 2004/01/19 23:24:07 fredrik Exp $ */ public class Validate { @@ -273,7 +273,7 @@ public class Validate { * @throws IllegalArgumentException if the array is empty */ public static void notEmpty(Object[] array, String message) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { throw new IllegalArgumentException(message); } } @@ -292,7 +292,7 @@ public class Validate { * @throws IllegalArgumentException if the array is empty */ public static void notEmpty(Object[] array) { - if (array == null || array.length == 0) { + if (ArrayUtils.isEmpty(array)) { throw new IllegalArgumentException("The validated array is empty"); } }