diff --git a/src/java/org/apache/commons/lang/StringUtils.java b/src/java/org/apache/commons/lang/StringUtils.java index 699afa70d..73bfe83f3 100644 --- a/src/java/org/apache/commons/lang/StringUtils.java +++ b/src/java/org/apache/commons/lang/StringUtils.java @@ -98,7 +98,7 @@ import org.apache.commons.lang.math.NumberUtils; * @author Arun Mammen Thomas * @author Gary Gregory * @since 1.0 - * @version $Id: StringUtils.java,v 1.69 2003/07/20 00:17:29 scolebourne Exp $ + * @version $Id: StringUtils.java,v 1.70 2003/07/20 00:37:09 scolebourne Exp $ */ public class StringUtils { // Performance testing notes (JDK 1.4, Jul03, scolebourne) @@ -147,7 +147,106 @@ public class StringUtils { public StringUtils() { } - // Empty + // Empty checks + //----------------------------------------------------------------------- + + /** + *

Checks if a String is empty ("") or null. + * null returns false

+ * + *
+     * StringUtils.isEmpty(null)      = true
+     * StringUtils.isEmpty("")        = true
+     * StringUtils.isEmpty(" ")       = false
+     * StringUtils.isEmpty("bob")     = false
+     * StringUtils.isEmpty("  bob  ") = false
+     * 
+ * + *

NOTE: This method changed in version 2.0. + * It no longer trims the String. + * That functionality is available in isBlank().

+ * + * @param str the String to check, may be null + * @return true if the String is empty or null + */ + public static boolean isEmpty(String str) { + return (str == null || str.length() == 0); + } + + /** + *

Checks if a String is not empty ("") and not null.

+ * + *
+     * StringUtils.isNotEmpty(null)      = false
+     * StringUtils.isNotEmpty("")        = false
+     * StringUtils.isNotEmpty(" ")       = true
+     * StringUtils.isNotEmpty("bob")     = true
+     * StringUtils.isNotEmpty("  bob  ") = true
+     * 
+ * + * @param str the String to check, may be null + * @return true if the String is not empty and not null + */ + public static boolean isNotEmpty(String str) { + return (str != null && str.length() > 0); + } + + /** + *

Checks if a String is whitespace, empty ("") or null.

+ * + *
+     * StringUtils.isBlank(null)      = true
+     * StringUtils.isBlank("")        = true
+     * StringUtils.isBlank(" ")       = true
+     * StringUtils.isBlank("bob")     = false
+     * StringUtils.isBlank("  bob  ") = false
+     * 
+ * + * @param str the String to check, may be null + * @return true if the String is null, empty or whitespace + */ + public static boolean isBlank(String str) { + int strLen; + if (str == null || (strLen = str.length()) == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if ((Character.isWhitespace(str.charAt(i)) == false) ) { + return false; + } + } + return true; + } + + /** + *

Checks if a String is not empty ("") and not null.

+ * + *
+     * StringUtils.isNotBlank(null)      = false
+     * StringUtils.isNotBlank("")        = false
+     * StringUtils.isNotBlank(" ")       = false
+     * StringUtils.isNotBlank("bob")     = true
+     * StringUtils.isNotBlank("  bob  ") = true
+     * 
+ * + * @param str the String to check, may be null + * @return true if the String is + * not empty and not null and not whitespace + */ + public static boolean isNotBlank(String str) { + int strLen; + if (str == null || (strLen = str.length()) == 0) { + return false; + } + for (int i = 0; i < strLen; i++) { + if ((Character.isWhitespace(str.charAt(i)) == false) ) { + return true; + } + } + return false; + } + + // Trim //----------------------------------------------------------------------- /** @@ -250,105 +349,263 @@ public class StringUtils { return (str == null ? "" : str.trim()); } - // Empty checks + // Stripping //----------------------------------------------------------------------- - + /** - *

Checks if a String is empty ("") or null. - * null returns false

+ *

Strips whitespace from the start and end of a String.

+ * + *

This is similar to {@link #trim(String)} but removes whitespace. + * Whitespace is defined by {@link Character#isWhitespace(char)}.

+ * + *

A null input String returns null.

* *
-     * StringUtils.isEmpty(null)      = true
-     * StringUtils.isEmpty("")        = true
-     * StringUtils.isEmpty(" ")       = false
-     * StringUtils.isEmpty("bob")     = false
-     * StringUtils.isEmpty("  bob  ") = false
+     * StringUtils.strip(null)     = null
+     * StringUtils.strip("")       = ""
+     * StringUtils.strip("   ")    = ""
+     * StringUtils.strip("abc")    = "abc"
+     * StringUtils.strip("  abc")  = "abc"
+     * StringUtils.strip("abc  ")  = "abc"
+     * StringUtils.strip(" abc ")  = "abc"
+     * StringUtils.strip(" ab c ") = "ab c"
      * 
- * - *

NOTE: This method changed in version 2.0. - * It no longer trims the String. - * That functionality is available in isBlank().

* - * @param str the String to check, may be null - * @return true if the String is empty or null + * @param str the String to remove whitespace from, may be null + * @return the stripped String, null if null String input */ - public static boolean isEmpty(String str) { - return (str == null || str.length() == 0); + public static String strip(String str) { + return strip(str, null); + } + + /** + *

Strips whitespace from the start and end of a String returning + * null if the String is empty ("") after the strip.

+ * + *

This is similar to {@link #trimToNull(String)} but removes whitespace. + * Whitespace is defined by {@link Character#isWhitespace(char)}.

+ * + *
+     * StringUtils.strip(null)     = null
+     * StringUtils.strip("")       = null
+     * StringUtils.strip("   ")    = null
+     * StringUtils.strip("abc")    = "abc"
+     * StringUtils.strip("  abc")  = "abc"
+     * StringUtils.strip("abc  ")  = "abc"
+     * StringUtils.strip(" abc ")  = "abc"
+     * StringUtils.strip(" ab c ") = "ab c"
+     * 
+ * + * @param str the String to be stripped, may be null + * @return the stripped String, + * null if whitespace, empty or null String input + */ + public static String stripToNull(String str) { + if (str == null) { + return null; + } + str = strip(str, null); + return (str.length() == 0 ? null : str); + } + + /** + *

Strips whitespace from the start and end of a String returning + * an empty String if null input.

+ * + *

This is similar to {@link #trimToEmpty(String)} but removes whitespace. + * Whitespace is defined by {@link Character#isWhitespace(char)}.

+ * + *
+     * StringUtils.strip(null)     = ""
+     * StringUtils.strip("")       = ""
+     * StringUtils.strip("   ")    = ""
+     * StringUtils.strip("abc")    = "abc"
+     * StringUtils.strip("  abc")  = "abc"
+     * StringUtils.strip("abc  ")  = "abc"
+     * StringUtils.strip(" abc ")  = "abc"
+     * StringUtils.strip(" ab c ") = "ab c"
+     * 
+ * + * @param str the String to be stripped, may be null + * @return the trimmed String, or an empty String if null input + */ + public static String stripToEmpty(String str) { + return (str == null ? "" : strip(str, null)); + } + + /** + *

Strips any of a set of characters from the start and end of a String. + * This is similar to {@link String#trim()} but allows the characters + * to be stripped to be controlled.

+ * + *

A null input String returns null.

+ * + *

If the stripChars String is null, whitespace is + * stripped as defined by {@link Character#isWhitespace(char)}. + * Alternatively use {@link #strip(String)}.

+ * + *
+     * StringUtils.strip(null, null)       = null
+     * StringUtils.strip("abc", null)      = "abc"
+     * StringUtils.strip("  abc", null)    = "abc"
+     * StringUtils.strip("abc  ", null)    = "abc"
+     * StringUtils.strip(" abc ", null)    = "abc"
+     * StringUtils.strip("  abcyx", "xyz") = "  abc"
+     * 
+ * + * @param str the String to remove characters from, may be null + * @param stripChars the characters to remove, null treated as whitespace + * @return the stripped String, null if null String input + */ + public static String strip(String str, String stripChars) { + if (str == null || str.length() == 0) { + return str; + } + str = stripStart(str, stripChars); + return stripEnd(str, stripChars); } /** - *

Checks if a String is not empty ("") and not null.

+ *

Strips any of a set of characters from the start of a String.

+ * + *

A null input String returns null.

+ * + *

If the stripChars String is null, whitespace is + * stripped as defined by {@link Character#isWhitespace(char)}.

* *
-     * StringUtils.isNotEmpty(null)      = false
-     * StringUtils.isNotEmpty("")        = false
-     * StringUtils.isNotEmpty(" ")       = true
-     * StringUtils.isNotEmpty("bob")     = true
-     * StringUtils.isNotEmpty("  bob  ") = true
+     * StringUtils.strip(null, null)       = null
+     * StringUtils.strip("abc", null)      = "abc"
+     * StringUtils.strip("  abc", null)    = "abc"
+     * StringUtils.strip("abc  ", null)    = "abc  "
+     * StringUtils.strip(" abc ", null)    = "abc "
+     * StringUtils.strip("yxabc  ", "xyz") = "abc  "
      * 
- * - * @param str the String to check, may be null - * @return true if the String is not empty and not null - */ - public static boolean isNotEmpty(String str) { - return (str != null && str.length() > 0); - } - - /** - *

Checks if a String is whitespace, empty ("") or null.

* - *
-     * StringUtils.isBlank(null)      = true
-     * StringUtils.isBlank("")        = true
-     * StringUtils.isBlank(" ")       = true
-     * StringUtils.isBlank("bob")     = false
-     * StringUtils.isBlank("  bob  ") = false
-     * 
- * - * @param str the String to check, may be null - * @return true if the String is null, empty or whitespace + * @param str the String to remove characters from, may be null + * @param stripChars the characters to remove, null treated as whitespace + * @return the stripped String, null if null String input */ - public static boolean isBlank(String str) { + public static String stripStart(String str, String stripChars) { int strLen; if (str == null || (strLen = str.length()) == 0) { - return true; + return str; } - for (int i = 0; i < strLen; i++) { - if ((Character.isWhitespace(str.charAt(i)) == false) ) { - return false; + int start = 0; + if (stripChars == null) { + while ((start != strLen) && Character.isWhitespace(str.charAt(start))) { + start++; + } + } else { + while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) { + start++; } } - return true; + return str.substring(start); } /** - *

Checks if a String is not empty ("") and not null.

+ *

Strips any of a set of characters from the end of a String.

+ * + *

A null input String returns null.

+ * + *

If the stripChars String is null, whitespace is + * stripped as defined by {@link Character#isWhitespace(char)}.

* *
-     * StringUtils.isNotBlank(null)      = false
-     * StringUtils.isNotBlank("")        = false
-     * StringUtils.isNotBlank(" ")       = false
-     * StringUtils.isNotBlank("bob")     = true
-     * StringUtils.isNotBlank("  bob  ") = true
+     * StringUtils.strip(null, null)       = null
+     * StringUtils.strip("abc", null)      = "abc"
+     * StringUtils.strip("  abc", null)    = "  abc"
+     * StringUtils.strip("abc  ", null)    = "abc"
+     * StringUtils.strip(" abc ", null)    = " abc"
+     * StringUtils.strip("  abcyx", "xyz") = "  abc"
      * 
- * - * @param str the String to check, may be null - * @return true if the String is - * not empty and not null and not whitespace + * + * @param str the String to remove characters from, may be null + * @param stripChars the characters to remove, null treated as whitespace + * @return the stripped String, null if null String input */ - public static boolean isNotBlank(String str) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { - return false; + public static String stripEnd(String str, String stripChars) { + int end; + if (str == null || (end = str.length()) == 0) { + return str; } - for (int i = 0; i < strLen; i++) { - if ((Character.isWhitespace(str.charAt(i)) == false) ) { - return true; + + if (stripChars == null) { + while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { + end--; + } + } else { + while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) { + end--; } } - return false; + return str.substring(0, end); } + // StripAll + //----------------------------------------------------------------------- + + /** + *

Strips whitespace from the start and end of every String in an array. + * Whitespace is defined by {@link Character#isWhitespace(char)}.

+ * + *

A new array is returned each time, except for length zero. + * A null array will return null. + * An empty array will return itself. + * A null array entry will be ignored.

+ * + *
+     * StringUtils.stripAll(null)             = null
+     * StringUtils.stripAll([])               = []
+     * StringUtils.stripAll(["abc", "  abc"]) = ["abc", "abc"]
+     * StringUtils.stripAll(["abc  ", null])  = ["abc", null]
+     * 
+ * + * @param str the array to remove whitespace from, may be null + * @return the stripped Strings, null if null array input + */ + public static String[] stripAll(String[] strs) { + return stripAll(strs, null); + } + + /** + *

Strips any of a set of characters from the start and end of every + * String in an array.

+ * Whitespace is defined by {@link Character#isWhitespace(char)}.

+ * + *

A new array is returned each time, except for length zero. + * A null array will return null. + * An empty array will return itself. + * A null array entry will be ignored. + * A null stripChars will strip whitespace as defined by + * {@link Character#isWhitespace(char)}.

+ * + *
+     * StringUtils.stripAll(null, null)             = null
+     * StringUtils.stripAll([], null)               = []
+     * StringUtils.stripAll(["abc", "  abc"], null) = ["abc", "abc"]
+     * StringUtils.stripAll(["abc  ", null], null)  = ["abc", null]
+     * StringUtils.stripAll(["abc  ", null], "yz")  = ["abc  ", null]
+     * StringUtils.stripAll(["yabcz", null], "yz")  = ["abc", null]
+     * 
+ * + * @param str the array to remove characters from, may be null + * @param stripChars the characters to remove, null treated as whitespace + * @return the stripped Strings, null if null array input + */ + public static String[] stripAll(String[] strs, String stripChars) { + int strsLen; + if (strs == null || (strsLen = strs.length) == 0) { + return strs; + } + String[] newArr = new String[strsLen]; + for (int i = 0; i < strsLen; i++) { + newArr[i] = strip(strs[i], stripChars); + } + return newArr; + } + // Equals //----------------------------------------------------------------------- @@ -2508,260 +2765,6 @@ public class StringUtils { return str; } - // Stripping - //----------------------------------------------------------------------- - - /** - *

Strips whitespace from the start and end of a String.

- * - *

This is similar to {@link String#trim()} but instead removes whitespace. - * Whitespace is defined by {@link Character#isWhitespace(char)}.

- * - *

A null input String returns null.

- * - *
-     * StringUtils.strip(null)     = null
-     * StringUtils.strip("")       = ""
-     * StringUtils.strip("   ")    = ""
-     * StringUtils.strip("abc")    = "abc"
-     * StringUtils.strip("  abc")  = "abc"
-     * StringUtils.strip("abc  ")  = "abc"
-     * StringUtils.strip(" abc ")  = "abc"
-     * StringUtils.strip(" ab c ") = "ab c"
-     * 
- * - * @param str the String to remove whitespace from, may be null - * @return the stripped String, null if null String input - */ - public static String strip(String str) { - return strip(str, null); - } - - /** - *

Strips whitespace from the start and end of a String returning - * null if the String is empty ("") after the strip.

- * - *

This is similar to {@link #trimToNull()} but instead removes whitespace. - * Whitespace is defined by {@link Character#isWhitespace(char)}.

- * - *
-     * StringUtils.strip(null)     = null
-     * StringUtils.strip("")       = null
-     * StringUtils.strip("   ")    = null
-     * StringUtils.strip("abc")    = "abc"
-     * StringUtils.strip("  abc")  = "abc"
-     * StringUtils.strip("abc  ")  = "abc"
-     * StringUtils.strip(" abc ")  = "abc"
-     * StringUtils.strip(" ab c ") = "ab c"
-     * 
- * - * @param str the String to be stripped, may be null - * @return the stripped String, - * null if whitespace, empty or null String input - */ - public static String stripToNull(String str) { - if (str == null) { - return null; - } - str = strip(str, null); - return (str.length() == 0 ? null : str); - } - - /** - *

Strips whitespace from the start and end of a String returning - * an empty String if null input.

- * - *

This is similar to {@link #trimToEmpty()} but instead removes whitespace. - * Whitespace is defined by {@link Character#isWhitespace(char)}.

- * - *
-     * StringUtils.strip(null)     = ""
-     * StringUtils.strip("")       = ""
-     * StringUtils.strip("   ")    = ""
-     * StringUtils.strip("abc")    = "abc"
-     * StringUtils.strip("  abc")  = "abc"
-     * StringUtils.strip("abc  ")  = "abc"
-     * StringUtils.strip(" abc ")  = "abc"
-     * StringUtils.strip(" ab c ") = "ab c"
-     * 
- * - * @param str the String to be stripped, may be null - * @return the trimmed String, or an empty String if null input - */ - public static String stripToEmpty(String str) { - return (str == null ? "" : strip(str, null)); - } - - /** - *

Strips any of a set of characters from the start and end of a String. - * This is similar to {@link String#trim()} but allows the characters - * to be stripped to be controlled.

- * - *

A null input String returns null.

- * - *

If the stripChars String is null, whitespace is - * stripped as defined by {@link Character#isWhitespace(char)}. - * Alternatively use {@link #strip(String)}.

- * - *
-     * StringUtils.strip(null, null)       = null
-     * StringUtils.strip("abc", null)      = "abc"
-     * StringUtils.strip("  abc", null)    = "abc"
-     * StringUtils.strip("abc  ", null)    = "abc"
-     * StringUtils.strip(" abc ", null)    = "abc"
-     * StringUtils.strip("  abcyx", "xyz") = "  abc"
-     * 
- * - * @param str the String to remove characters from, may be null - * @param stripChars the characters to remove, null treated as whitespace - * @return the stripped String, null if null String input - */ - public static String strip(String str, String stripChars) { - if (str == null || str.length() == 0) { - return str; - } - str = stripStart(str, stripChars); - return stripEnd(str, stripChars); - } - - /** - *

Strips any of a set of characters from the start of a String.

- * - *

A null input String returns null.

- * - *

If the stripChars String is null, whitespace is - * stripped as defined by {@link Character#isWhitespace(char)}.

- * - *
-     * StringUtils.strip(null, null)       = null
-     * StringUtils.strip("abc", null)      = "abc"
-     * StringUtils.strip("  abc", null)    = "abc"
-     * StringUtils.strip("abc  ", null)    = "abc  "
-     * StringUtils.strip(" abc ", null)    = "abc "
-     * StringUtils.strip("yxabc  ", "xyz") = "abc  "
-     * 
- * - * @param str the String to remove characters from, may be null - * @param stripChars the characters to remove, null treated as whitespace - * @return the stripped String, null if null String input - */ - public static String stripStart(String str, String stripChars) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { - return str; - } - int start = 0; - if (stripChars == null) { - while ((start != strLen) && Character.isWhitespace(str.charAt(start))) { - start++; - } - } else { - while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) { - start++; - } - } - return str.substring(start); - } - - /** - *

Strips any of a set of characters from the end of a String.

- * - *

A null input String returns null.

- * - *

If the stripChars String is null, whitespace is - * stripped as defined by {@link Character#isWhitespace(char)}.

- * - *
-     * StringUtils.strip(null, null)       = null
-     * StringUtils.strip("abc", null)      = "abc"
-     * StringUtils.strip("  abc", null)    = "  abc"
-     * StringUtils.strip("abc  ", null)    = "abc"
-     * StringUtils.strip(" abc ", null)    = " abc"
-     * StringUtils.strip("  abcyx", "xyz") = "  abc"
-     * 
- * - * @param str the String to remove characters from, may be null - * @param stripChars the characters to remove, null treated as whitespace - * @return the stripped String, null if null String input - */ - public static String stripEnd(String str, String stripChars) { - int end; - if (str == null || (end = str.length()) == 0) { - return str; - } - - if (stripChars == null) { - while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) { - end--; - } - } else { - while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) { - end--; - } - } - return str.substring(0, end); - } - - /** - *

Strips whitespace from the start and end of every String in an array. - * Whitespace is defined by {@link Character#isWhitespace(char)}.

- * - *

A new array is returned each time, except for length zero. - * A null array will return null. - * An empty array will return itself. - * A null array entry will be ignored.

- * - *
-     * StringUtils.stripAll(null)             = null
-     * StringUtils.stripAll([])               = []
-     * StringUtils.stripAll(["abc", "  abc"]) = ["abc", "abc"]
-     * StringUtils.stripAll(["abc  ", null])  = ["abc", null]
-     * 
- * - * @param str the array to remove whitespace from, may be null - * @return the stripped Strings, null if null array input - */ - public static String[] stripAll(String[] strs) { - return stripAll(strs, null); - } - - /** - *

Strips any of a set of characters from the start and end of every - * String in an array.

- * Whitespace is defined by {@link Character#isWhitespace(char)}.

- * - *

A new array is returned each time, except for length zero. - * A null array will return null. - * An empty array will return itself. - * A null array entry will be ignored. - * A null stripChars will strip whitespace as defined by - * {@link Character#isWhitespace(char)}.

- * - *
-     * StringUtils.stripAll(null, null)             = null
-     * StringUtils.stripAll([], null)               = []
-     * StringUtils.stripAll(["abc", "  abc"], null) = ["abc", "abc"]
-     * StringUtils.stripAll(["abc  ", null], null)  = ["abc", null]
-     * StringUtils.stripAll(["abc  ", null], "yz")  = ["abc  ", null]
-     * StringUtils.stripAll(["yabcz", null], "yz")  = ["abc", null]
-     * 
- * - * @param str the array to remove characters from, may be null - * @param stripChars the characters to remove, null treated as whitespace - * @return the stripped Strings, null if null array input - */ - public static String[] stripAll(String[] strs, String stripChars) { - int strsLen; - if (strs == null || (strsLen = strs.length) == 0) { - return strs; - } - String[] newArr = new String[strsLen]; - for (int i = 0; i < strsLen; i++) { - newArr[i] = strip(strs[i], stripChars); - } - return newArr; - } - // Case conversion //----------------------------------------------------------------------- diff --git a/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java b/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java index 07d421dfa..92c6d8247 100644 --- a/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java +++ b/src/test/org/apache/commons/lang/StringUtilsTrimEmptyTest.java @@ -63,7 +63,7 @@ import junit.textui.TestRunner; * * @author Stephen Colebourne * @author Ringo De Smet - * @version $Id: StringUtilsTrimEmptyTest.java,v 1.14 2003/07/20 00:17:29 scolebourne Exp $ + * @version $Id: StringUtilsTrimEmptyTest.java,v 1.15 2003/07/20 00:37:09 scolebourne Exp $ */ public class StringUtilsTrimEmptyTest extends TestCase { private static final String FOO = "foo"; @@ -91,7 +91,39 @@ public class StringUtilsTrimEmptyTest extends TestCase { } //----------------------------------------------------------------------- + public void testIsEmpty() { + assertEquals(true, StringUtils.isEmpty(null)); + assertEquals(true, StringUtils.isEmpty("")); + assertEquals(false, StringUtils.isEmpty(" ")); + assertEquals(false, StringUtils.isEmpty("foo")); + assertEquals(false, StringUtils.isEmpty(" foo ")); + } + public void testIsNotEmpty() { + assertEquals(false, StringUtils.isNotEmpty(null)); + assertEquals(false, StringUtils.isNotEmpty("")); + assertEquals(true, StringUtils.isNotEmpty(" ")); + assertEquals(true, StringUtils.isNotEmpty("foo")); + assertEquals(true, StringUtils.isNotEmpty(" foo ")); + } + + public void testIsBlank() { + assertEquals(true, StringUtils.isBlank(null)); + assertEquals(true, StringUtils.isBlank("")); + assertEquals(true, StringUtils.isBlank(StringUtilsTest.WHITESPACE)); + assertEquals(false, StringUtils.isBlank("foo")); + assertEquals(false, StringUtils.isBlank(" foo ")); + } + + public void testIsNotBlank() { + assertEquals(false, StringUtils.isNotBlank(null)); + assertEquals(false, StringUtils.isNotBlank("")); + assertEquals(false, StringUtils.isNotBlank(StringUtilsTest.WHITESPACE)); + assertEquals(true, StringUtils.isNotBlank("foo")); + assertEquals(true, StringUtils.isNotBlank(" foo ")); + } + + //----------------------------------------------------------------------- public void testClean() { assertEquals(FOO, StringUtils.clean(FOO + " ")); assertEquals(FOO, StringUtils.clean(" " + FOO + " ")); @@ -138,38 +170,7 @@ public class StringUtilsTrimEmptyTest extends TestCase { assertEquals("", StringUtils.trimToEmpty(null)); } - public void testIsEmpty() { - assertEquals(true, StringUtils.isEmpty(null)); - assertEquals(true, StringUtils.isEmpty("")); - assertEquals(false, StringUtils.isEmpty(" ")); - assertEquals(false, StringUtils.isEmpty("foo")); - assertEquals(false, StringUtils.isEmpty(" foo ")); - } - - public void testIsNotEmpty() { - assertEquals(false, StringUtils.isNotEmpty(null)); - assertEquals(false, StringUtils.isNotEmpty("")); - assertEquals(true, StringUtils.isNotEmpty(" ")); - assertEquals(true, StringUtils.isNotEmpty("foo")); - assertEquals(true, StringUtils.isNotEmpty(" foo ")); - } - - public void testIsBlank() { - assertEquals(true, StringUtils.isBlank(null)); - assertEquals(true, StringUtils.isBlank("")); - assertEquals(true, StringUtils.isBlank(StringUtilsTest.WHITESPACE)); - assertEquals(false, StringUtils.isBlank("foo")); - assertEquals(false, StringUtils.isBlank(" foo ")); - } - - public void testIsNotBlank() { - assertEquals(false, StringUtils.isNotBlank(null)); - assertEquals(false, StringUtils.isNotBlank("")); - assertEquals(false, StringUtils.isNotBlank(StringUtilsTest.WHITESPACE)); - assertEquals(true, StringUtils.isNotBlank("foo")); - assertEquals(true, StringUtils.isNotBlank(" foo ")); - } - + //----------------------------------------------------------------------- public void testStrip_String() { assertEquals(null, StringUtils.strip(null)); assertEquals("", StringUtils.strip(""));