Browse Source

Consistently use CharSequence.isEmpty() for emptiness checks

Closes gh-33577
pull/33582/head
Tran Ngoc Nhan 1 year ago committed by Sam Brannen
parent
commit
c85050eb43
  1. 2
      spring-core/src/main/java/org/springframework/cglib/core/TypeUtils.java
  2. 4
      spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java
  3. 2
      spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
  4. 4
      spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java
  5. 6
      spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java
  6. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java

2
spring-core/src/main/java/org/springframework/cglib/core/TypeUtils.java

@ -97,7 +97,7 @@ public class TypeUtils { @@ -97,7 +97,7 @@ public class TypeUtils {
}
public static String upperFirst(String s) {
if (s == null || s.length() == 0) {
if (s == null || s.isEmpty()) {
return s;
}
return Character.toUpperCase(s.charAt(0)) + s.substring(1);

4
spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -153,7 +153,7 @@ public final class BindMarkersFactoryResolver { @@ -153,7 +153,7 @@ public final class BindMarkersFactoryResolver {
builder.append(ch);
}
}
if (builder.length() == 0) {
if (builder.isEmpty()) {
return "";
}
return "_" + builder.toString();

2
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

@ -877,7 +877,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { @@ -877,7 +877,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
@Override
@Nullable
public PathComponent build() {
if (this.path.length() == 0) {
if (this.path.isEmpty()) {
return null;
}
String sanitized = getSanitizedPath(this.path);

4
spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -73,7 +73,7 @@ class CaptureVariablePathElement extends PathElement { @@ -73,7 +73,7 @@ class CaptureVariablePathElement extends PathElement {
return false;
}
String candidateCapture = matchingContext.pathElementValue(pathIndex);
if (candidateCapture.length() == 0) {
if (candidateCapture.isEmpty()) {
return false;
}

6
spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -66,7 +66,7 @@ class WildcardPathElement extends PathElement { @@ -66,7 +66,7 @@ class WildcardPathElement extends PathElement {
}
else {
return (matchingContext.isMatchOptionalTrailingSeparator() && // if optional slash is on...
segmentData != null && segmentData.length() > 0 && // and there is at least one character to match the *...
segmentData != null && !segmentData.isEmpty() && // and there is at least one character to match the *...
(pathIndex + 1) == matchingContext.pathLength && // and the next path element is the end of the candidate...
matchingContext.isSeparator(pathIndex)); // and the final element is a separator
}
@ -74,7 +74,7 @@ class WildcardPathElement extends PathElement { @@ -74,7 +74,7 @@ class WildcardPathElement extends PathElement {
}
else {
// Within a path (e.g. /aa/*/bb) there must be at least one character to match the wildcard
if (segmentData == null || segmentData.length() == 0) {
if (segmentData == null || segmentData.isEmpty()) {
return false;
}
return (this.next != null && this.next.matches(pathIndex, matchingContext));

4
spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -323,7 +323,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { @@ -323,7 +323,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
StringBuilder qs = new StringBuilder();
for (Param param : params) {
if (!usedParams.contains(param.getName()) && StringUtils.hasLength(param.getName())) {
if (includeQueryStringDelimiter && qs.length() == 0) {
if (includeQueryStringDelimiter && qs.isEmpty()) {
qs.append('?');
}
else {

Loading…
Cancel
Save