From 6b9c3315885f8f9e4be19db9ef05257035b97bca Mon Sep 17 00:00:00 2001
From: Martin Checks if all of the CharSequences are empty ("") or null. Checks if a CharSequence is empty (""), null or whitespace only. Checks if all of the CharSequences are empty (""), null or whitespace only.
+ * StringUtils.isAllEmpty(null) = true
+ * StringUtils.isAllEmpty(null, "") = true
+ * StringUtils.isAllEmpty(new String[] {}) = true
+ * StringUtils.isAllEmpty(null, "foo") = false
+ * StringUtils.isAllEmpty("", "bar") = false
+ * StringUtils.isAllEmpty("bob", "") = false
+ * StringUtils.isAllEmpty(" bob ", null) = false
+ * StringUtils.isAllEmpty(" ", "bar") = false
+ * StringUtils.isAllEmpty("foo", "bar") = false
+ *
+ *
+ * @param css the CharSequences to check, may be null or empty
+ * @return {@code true} if all of the CharSequences are empty or null
+ * @since 3.6
+ */
+ public static boolean isAllEmpty(final CharSequence... css) {
+ return !isAnyNotEmpty(css);
+ }
+
/**
*
+ * StringUtils.isAllBlank(null) = true + * StringUtils.isAllBlank(null, "foo") = false + * StringUtils.isAllBlank(null, null) = true + * StringUtils.isAllBlank("", "bar") = false + * StringUtils.isAllBlank("bob", "") = false + * StringUtils.isAllBlank(" bob ", null) = false + * StringUtils.isAllBlank(" ", "bar") = false + * StringUtils.isAllBlank("foo", "bar") = false + * StringUtils.isAllBlank(new String[] {}) = true + *+ * + * @param css the CharSequences to check, may be null or empty + * @return {@code true} if all of the CharSequences are empty or null or whitespace only + * @since 3.6 + */ + public static boolean isAllBlank(final CharSequence... css) { + return !isAnyNotBlank(css); + } + // Trim //----------------------------------------------------------------------- /** diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java index 769a138ff..b04d0daef 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsEmptyBlankTest.java @@ -81,6 +81,21 @@ public class StringUtilsEmptyBlankTest { assertTrue(StringUtils.isNoneEmpty("foo", "bar")); } + @Test + public void testIsAllEmpty() { + assertTrue(StringUtils.isAllEmpty()); + assertTrue(StringUtils.isAllEmpty(new String[]{})); + assertTrue(StringUtils.isAllEmpty((String) null)); + assertTrue(StringUtils.isAllEmpty((String[]) null)); + assertFalse(StringUtils.isAllEmpty(null, "foo")); + assertFalse(StringUtils.isAllEmpty("", "bar")); + assertFalse(StringUtils.isAllEmpty("bob", "")); + assertFalse(StringUtils.isAllEmpty(" bob ", null)); + assertFalse(StringUtils.isAllEmpty(" ", "bar")); + assertFalse(StringUtils.isAllEmpty("foo", "bar")); + assertTrue(StringUtils.isAllEmpty("", null)); + } + @Test public void testIsBlank() { assertTrue(StringUtils.isBlank(null)); @@ -137,4 +152,18 @@ public class StringUtilsEmptyBlankTest { assertFalse(StringUtils.isNoneBlank(" ", "bar")); assertTrue(StringUtils.isNoneBlank("foo", "bar")); } + + @Test + public void testIsAllBlank() { + assertTrue(StringUtils.isAllBlank((String) null)); + assertTrue(StringUtils.isAllBlank((String[]) null)); + assertTrue(StringUtils.isAllBlank(null, null)); + assertTrue(StringUtils.isAllBlank(null, " ")); + assertFalse(StringUtils.isAllBlank(null, "foo")); + assertFalse(StringUtils.isAllBlank("", "bar")); + assertFalse(StringUtils.isAllBlank("bob", "")); + assertFalse(StringUtils.isAllBlank(" bob ", null)); + assertFalse(StringUtils.isAllBlank(" ", "bar")); + assertFalse(StringUtils.isAllBlank("foo", "bar")); + } }