Consistent hasText checks for CharSequence vs String

Issue: SPR-15540
This commit is contained in:
Juergen Hoeller
2017-10-22 12:12:32 +02:00
parent 9288990603
commit 9a88ebdeba
2 changed files with 34 additions and 34 deletions

View File

@@ -139,17 +139,7 @@ public abstract class StringUtils {
* @see Character#isWhitespace
*/
public static boolean hasText(@Nullable CharSequence str) {
if (!hasLength(str)) {
return false;
}
int strLen = str.length();
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return true;
}
}
return false;
return (hasLength(str) && containsText(str));
}
/**
@@ -163,9 +153,19 @@ public abstract class StringUtils {
* @see #hasText(CharSequence)
*/
public static boolean hasText(@Nullable String str) {
return (str != null && !str.isEmpty() && hasText((CharSequence) str));
return (hasLength(str) && containsText(str));
}
private static boolean containsText(CharSequence str) {
int strLen = str.length();
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return true;
}
}
return false;
}
/**
* Check whether the given {@code CharSequence} contains any whitespace characters.
* @param str the {@code CharSequence} to check (may be {@code null})