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

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

+1-1
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);

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

+1-1
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
}

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

+3-3
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 ");

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

+1-1
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();

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

+2-2
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
}

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

+2-2
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));

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

+1-1
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

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

+1-1
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()));

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

+1-1
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));

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

+3-3
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
}

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DataObjectPropertyName.java

+2-2
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.
@@ -52,7 +52,7 @@ public static String toDashedForm(String name) {
5252
}
5353
else {
5454
ch = (ch != '_') ? ch : '-';
55-
if (Character.isUpperCase(ch) && result.length() > 0 && result.charAt(result.length() - 1) != '-') {
55+
if (Character.isUpperCase(ch) && !result.isEmpty() && result.charAt(result.length() - 1) != '-') {
5656
result.append('-');
5757
}
5858
result.append(Character.toLowerCase(ch));

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private boolean isScalarValue(ConfigurationPropertySource source, ConfigurationP
211211
private String getKeyName(ConfigurationPropertyName name) {
212212
StringBuilder result = new StringBuilder();
213213
for (int i = this.root.getNumberOfElements(); i < name.getNumberOfElements(); i++) {
214-
if (result.length() != 0) {
214+
if (!result.isEmpty()) {
215215
result.append('.');
216216
}
217217
result.append(name.getElement(i, Form.ORIGINAL));

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private String buildToString() {
543543
StringBuilder result = new StringBuilder(elements * 8);
544544
for (int i = 0; i < elements; i++) {
545545
boolean indexed = isIndexed(i);
546-
if (result.length() > 0 && !indexed) {
546+
if (!result.isEmpty() && !indexed) {
547547
result.append('.');
548548
}
549549
if (indexed) {
@@ -615,7 +615,7 @@ private static Elements elementsOf(CharSequence name, boolean returnNullIfInvali
615615
Assert.isTrue(returnNullIfInvalid, "Name must not be null");
616616
return null;
617617
}
618-
if (name.length() == 0) {
618+
if (name.isEmpty()) {
619619
return Elements.EMPTY;
620620
}
621621
if (name.charAt(0) == '.' || name.charAt(name.length() - 1) == '.') {
@@ -674,7 +674,7 @@ public static ConfigurationPropertyName adapt(CharSequence name, char separator)
674674
static ConfigurationPropertyName adapt(CharSequence name, char separator,
675675
Function<CharSequence, CharSequence> elementValueProcessor) {
676676
Assert.notNull(name, "Name must not be null");
677-
if (name.length() == 0) {
677+
if (name.isEmpty()) {
678678
return EMPTY;
679679
}
680680
Elements elements = new ElementsParser(name, separator).parse(elementValueProcessor);

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SystemEnvironmentPropertyMapper.java

+3-3
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.
@@ -57,7 +57,7 @@ private String convertName(ConfigurationPropertyName name) {
5757
private String convertName(ConfigurationPropertyName name, int numberOfElements) {
5858
StringBuilder result = new StringBuilder();
5959
for (int i = 0; i < numberOfElements; i++) {
60-
if (result.length() > 0) {
60+
if (!result.isEmpty()) {
6161
result.append('_');
6262
}
6363
result.append(name.getElement(i, Form.UNIFORM).toUpperCase(Locale.ENGLISH));
@@ -68,7 +68,7 @@ private String convertName(ConfigurationPropertyName name, int numberOfElements)
6868
private String convertLegacyName(ConfigurationPropertyName name) {
6969
StringBuilder result = new StringBuilder();
7070
for (int i = 0; i < name.getNumberOfElements(); i++) {
71-
if (result.length() > 0) {
71+
if (!result.isEmpty()) {
7272
result.append('_');
7373
}
7474
result.append(convertLegacyNameElement(name.getElement(i, Form.ORIGINAL)));

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/BasicJsonParser.java

+2-2
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.
@@ -158,7 +158,7 @@ else if (current == '\\') {
158158
}
159159
index++;
160160
}
161-
if (build.length() > 0) {
161+
if (!build.isEmpty()) {
162162
list.add(build.toString().trim());
163163
}
164164
return list;

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/ColorConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void format(LogEvent event, StringBuilder toAppendTo) {
130130
for (PatternFormatter formatter : this.formatters) {
131131
formatter.format(event, buf);
132132
}
133-
if (buf.length() > 0) {
133+
if (!buf.isEmpty()) {
134134
AnsiElement element = this.styling;
135135
if (element == null) {
136136
// Assume highlighting

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackLoggingSystem.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ private void reportConfigurationErrorsIfNecessary(LoggerContext loggerContext) {
258258
List<Throwable> suppressedExceptions = new ArrayList<>();
259259
for (Status status : loggerContext.getStatusManager().getCopyOfStatusList()) {
260260
if (status.getLevel() == Status.ERROR) {
261-
errors.append((errors.length() > 0) ? String.format("%n") : "");
261+
errors.append((!errors.isEmpty()) ? String.format("%n") : "");
262262
errors.append(status.toString());
263263
if (status.getThrowable() != null) {
264264
suppressedExceptions.add(status.getThrowable());
265265
}
266266
}
267267
}
268-
if (errors.length() == 0) {
268+
if (errors.isEmpty()) {
269269
if (!StatusUtil.contextHasStatusListener(loggerContext)) {
270270
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
271271
}

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ ConnectionFactory buildAndWrap(ConnectionFactoryOptions options) {
212212

213213
private ConnectionFactoryOptions delegateFactoryOptions(ConnectionFactoryOptions options) {
214214
String protocol = toString(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL));
215-
if (protocol.trim().length() == 0) {
215+
if (protocol.trim().isEmpty()) {
216216
throw new IllegalArgumentException(String.format("Protocol %s is not valid.", protocol));
217217
}
218218
String[] protocols = protocol.split(COLON, 2);

0 commit comments

Comments
 (0)