LANG-1293: Add StringUtils#isAllEmpty and #isAllBlank methods
This commit is contained in:
parent
31a9fa0cce
commit
6b9c331588
|
@ -310,6 +310,29 @@ public class StringUtils {
|
||||||
return !isAnyEmpty(css);
|
return !isAnyEmpty(css);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Checks if all of the CharSequences are empty ("") or null.</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 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
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Checks if a CharSequence is empty (""), null or whitespace only.</p>
|
* <p>Checks if a CharSequence is empty (""), null or whitespace only.</p>
|
||||||
*
|
*
|
||||||
|
@ -455,6 +478,31 @@ public class StringUtils {
|
||||||
return !isAnyBlank(css);
|
return !isAnyBlank(css);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Checks if all of the CharSequences are empty (""), null or whitespace only.</p>
|
||||||
|
*
|
||||||
|
* </p>Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* 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
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @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
|
// Trim
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -81,6 +81,21 @@ public class StringUtilsEmptyBlankTest {
|
||||||
assertTrue(StringUtils.isNoneEmpty("foo", "bar"));
|
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
|
@Test
|
||||||
public void testIsBlank() {
|
public void testIsBlank() {
|
||||||
assertTrue(StringUtils.isBlank(null));
|
assertTrue(StringUtils.isBlank(null));
|
||||||
|
@ -137,4 +152,18 @@ public class StringUtilsEmptyBlankTest {
|
||||||
assertFalse(StringUtils.isNoneBlank(" ", "bar"));
|
assertFalse(StringUtils.isNoneBlank(" ", "bar"));
|
||||||
assertTrue(StringUtils.isNoneBlank("foo", "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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue