Skip to content

Commit ac18e30

Browse files
quaffphilwebb
authored andcommitted
Use .isEmpty() where feasible
See gh-38739
1 parent d3af5cc commit ac18e30

File tree

18 files changed

+31
-31
lines changed

18 files changed

+31
-31
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void addClassifiedManagedDependencies(Node dependencyManagement) {
221221
.collect(Collectors.toSet());
222222
Node target = dependency;
223223
for (String classifier : classifiers) {
224-
if (classifier.length() > 0) {
224+
if (!classifier.isEmpty()) {
225225
if (target == null) {
226226
target = new Node(null, "dependency");
227227
target.appendNode("groupId", groupId);

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthEndpointSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private Object getContributor(String[] path, int pathOffset) {
127127
private String getName(String[] path, int pathOffset) {
128128
StringBuilder name = new StringBuilder();
129129
while (pathOffset < path.length) {
130-
name.append((name.length() != 0) ? "/" : "");
130+
name.append((!name.isEmpty()) ? "/" : "");
131131
name.append(path[pathOffset]);
132132
pathOffset++;
133133
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/OnBeanCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private String createOnBeanNoMatchReason(MatchResult matchResult) {
332332

333333
private void appendMessageForNoMatches(StringBuilder reason, Collection<String> unmatched, String description) {
334334
if (!unmatched.isEmpty()) {
335-
if (reason.length() > 0) {
335+
if (!reason.isEmpty()) {
336336
reason.append(" and ");
337337
}
338338
reason.append("did not find any beans ");
@@ -347,7 +347,7 @@ private String createOnMissingBeanNoMatchReason(MatchResult matchResult) {
347347
appendMessageForMatches(reason, matchResult.getMatchedAnnotations(), "annotated with");
348348
appendMessageForMatches(reason, matchResult.getMatchedTypes(), "of type");
349349
if (!matchResult.getMatchedNames().isEmpty()) {
350-
if (reason.length() > 0) {
350+
if (!reason.isEmpty()) {
351351
reason.append(" and ");
352352
}
353353
reason.append("found beans named ");
@@ -360,7 +360,7 @@ private void appendMessageForMatches(StringBuilder reason, Map<String, Collectio
360360
String description) {
361361
if (!matches.isEmpty()) {
362362
matches.forEach((key, value) -> {
363-
if (reason.length() > 0) {
363+
if (!reason.isEmpty()) {
364364
reason.append(" and ");
365365
}
366366
reason.append("found beans ");

spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private String toCommaDelimitedString(List<Object> list) {
345345
}
346346
StringBuilder result = new StringBuilder();
347347
for (Object item : list) {
348-
result.append((result.length() != 0) ? "," : "");
348+
result.append((!result.isEmpty()) ? "," : "");
349349
result.append(item);
350350
}
351351
return result.toString();

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONStringer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public JSONStringer endObject() throws JSONException {
173173
* @throws JSONException if processing of json failed
174174
*/
175175
JSONStringer open(Scope empty, String openBracket) throws JSONException {
176-
if (this.stack.isEmpty() && this.out.length() > 0) {
176+
if (this.stack.isEmpty() && !this.out.isEmpty()) {
177177
throw new JSONException("Nesting problem: multiple top-level roots");
178178
}
179179
beforeValue();
@@ -423,7 +423,7 @@ else if (context != Scope.NULL) {
423423
*/
424424
@Override
425425
public String toString() {
426-
return this.out.length() == 0 ? null : this.out.toString();
426+
return this.out.isEmpty() ? null : this.out.toString();
427427
}
428428

429429
}

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ItemMetadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ private String buildName(String prefix, String name) {
6565
fullName.append(prefix);
6666
}
6767
if (name != null) {
68-
if (fullName.length() > 0) {
68+
if (!fullName.isEmpty()) {
6969
fullName.append('.');
7070
}
7171
fullName.append(ConfigurationMetadata.toDashedCase(name));

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
227227
}
228228

229229
boolean hasReportedErrors() {
230-
return this.message.length() > 0;
230+
return !this.message.isEmpty();
231231
}
232232

233233
@Override

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private void addClasspath(List<String> args) throws MojoExecutionException {
329329
try {
330330
StringBuilder classpath = new StringBuilder();
331331
for (URL ele : getClassPathUrls()) {
332-
if (classpath.length() > 0) {
332+
if (!classpath.isEmpty()) {
333333
classpath.append(File.pathSeparator);
334334
}
335335
classpath.append(new File(ele.toURI()));

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CommandLineBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static class ClasspathBuilder {
9898
static String build(List<URL> classpathElements) {
9999
StringBuilder classpath = new StringBuilder();
100100
for (URL element : classpathElements) {
101-
if (classpath.length() > 0) {
101+
if (!classpath.isEmpty()) {
102102
classpath.append(File.pathSeparator);
103103
}
104104
classpath.append(toFile(element));

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/StartupInfoLogger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,7 +121,7 @@ private void appendContext(StringBuilder message) {
121121
}
122122
append(context, "started by ", () -> System.getProperty("user.name"));
123123
append(context, "in ", () -> System.getProperty("user.dir"));
124-
if (context.length() > 0) {
124+
if (!context.isEmpty()) {
125125
message.append(" (");
126126
message.append(context);
127127
message.append(")");
@@ -143,7 +143,7 @@ private void append(StringBuilder message, String prefix, Callable<Object> call,
143143
value = defaultValue;
144144
}
145145
if (StringUtils.hasLength(value)) {
146-
message.append((message.length() > 0) ? " " : "");
146+
message.append((!message.isEmpty()) ? " " : "");
147147
message.append(prefix);
148148
message.append(value);
149149
}

0 commit comments

Comments
 (0)