Skip to content

Simplify hasText and containsElement methods for better clarity #33572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static Object unwrapOptional(@Nullable Object obj) {
* @return whether the element has been found in the given array
*/
public static boolean containsElement(@Nullable Object[] array, Object element) {
if (array == null) {
if (isEmpty(array)) {
return false;
}
for (Object arrayEle : array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,11 @@ public static boolean hasLength(@Nullable String str) {
*/
@Contract("null -> false")
public static boolean hasText(@Nullable CharSequence str) {
if (str == null) {
return false;
}

int strLen = str.length();
if (strLen == 0) {
if (isEmpty(str)) {
return false;
}

for (int i = 0; i < strLen; i++) {
for (int i = 0; i < str.length(); i++) {
if (!Character.isWhitespace(str.charAt(i))) {
return true;
}
Expand Down
Loading