Use .isEmpty() where feasible

See gh-38739
This commit is contained in:
Yanming Zhou 2023-12-19 22:27:26 -08:00 committed by Phillip Webb
parent d3af5cce73
commit ac18e3015c
18 changed files with 31 additions and 31 deletions

View File

@ -221,7 +221,7 @@ public class BomPlugin implements Plugin<Project> {
.collect(Collectors.toSet());
Node target = dependency;
for (String classifier : classifiers) {
if (classifier.length() > 0) {
if (!classifier.isEmpty()) {
if (target == null) {
target = new Node(null, "dependency");
target.appendNode("groupId", groupId);

View File

@ -127,7 +127,7 @@ abstract class HealthEndpointSupport<C, T> {
private String getName(String[] path, int pathOffset) {
StringBuilder name = new StringBuilder();
while (pathOffset < path.length) {
name.append((name.length() != 0) ? "/" : "");
name.append((!name.isEmpty()) ? "/" : "");
name.append(path[pathOffset]);
pathOffset++;
}

View File

@ -332,7 +332,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
private void appendMessageForNoMatches(StringBuilder reason, Collection<String> unmatched, String description) {
if (!unmatched.isEmpty()) {
if (reason.length() > 0) {
if (!reason.isEmpty()) {
reason.append(" and ");
}
reason.append("did not find any beans ");
@ -347,7 +347,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
appendMessageForMatches(reason, matchResult.getMatchedAnnotations(), "annotated with");
appendMessageForMatches(reason, matchResult.getMatchedTypes(), "of type");
if (!matchResult.getMatchedNames().isEmpty()) {
if (reason.length() > 0) {
if (!reason.isEmpty()) {
reason.append(" and ");
}
reason.append("found beans named ");
@ -360,7 +360,7 @@ class OnBeanCondition extends FilteringSpringBootCondition implements Configurat
String description) {
if (!matches.isEmpty()) {
matches.forEach((key, value) -> {
if (reason.length() > 0) {
if (!reason.isEmpty()) {
reason.append(" and ");
}
reason.append("found beans ");

View File

@ -345,7 +345,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
}
StringBuilder result = new StringBuilder();
for (Object item : list) {
result.append((result.length() != 0) ? "," : "");
result.append((!result.isEmpty()) ? "," : "");
result.append(item);
}
return result.toString();

View File

@ -173,7 +173,7 @@ public class JSONStringer {
* @throws JSONException if processing of json failed
*/
JSONStringer open(Scope empty, String openBracket) throws JSONException {
if (this.stack.isEmpty() && this.out.length() > 0) {
if (this.stack.isEmpty() && !this.out.isEmpty()) {
throw new JSONException("Nesting problem: multiple top-level roots");
}
beforeValue();
@ -423,7 +423,7 @@ public class JSONStringer {
*/
@Override
public String toString() {
return this.out.length() == 0 ? null : this.out.toString();
return this.out.isEmpty() ? null : this.out.toString();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@ -65,7 +65,7 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
fullName.append(prefix);
}
if (name != null) {
if (fullName.length() > 0) {
if (!fullName.isEmpty()) {
fullName.append('.');
}
fullName.append(ConfigurationMetadata.toDashedCase(name));

View File

@ -227,7 +227,7 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
}
boolean hasReportedErrors() {
return this.message.length() > 0;
return !this.message.isEmpty();
}
@Override

View File

@ -329,7 +329,7 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
try {
StringBuilder classpath = new StringBuilder();
for (URL ele : getClassPathUrls()) {
if (classpath.length() > 0) {
if (!classpath.isEmpty()) {
classpath.append(File.pathSeparator);
}
classpath.append(new File(ele.toURI()));

View File

@ -98,7 +98,7 @@ final class CommandLineBuilder {
static String build(List<URL> classpathElements) {
StringBuilder classpath = new StringBuilder();
for (URL element : classpathElements) {
if (classpath.length() > 0) {
if (!classpath.isEmpty()) {
classpath.append(File.pathSeparator);
}
classpath.append(toFile(element));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@ -121,7 +121,7 @@ class StartupInfoLogger {
}
append(context, "started by ", () -> System.getProperty("user.name"));
append(context, "in ", () -> System.getProperty("user.dir"));
if (context.length() > 0) {
if (!context.isEmpty()) {
message.append(" (");
message.append(context);
message.append(")");
@ -143,7 +143,7 @@ class StartupInfoLogger {
value = defaultValue;
}
if (StringUtils.hasLength(value)) {
message.append((message.length() > 0) ? " " : "");
message.append((!message.isEmpty()) ? " " : "");
message.append(prefix);
message.append(value);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@ -52,7 +52,7 @@ public abstract class DataObjectPropertyName {
}
else {
ch = (ch != '_') ? ch : '-';
if (Character.isUpperCase(ch) && result.length() > 0 && result.charAt(result.length() - 1) != '-') {
if (Character.isUpperCase(ch) && !result.isEmpty() && result.charAt(result.length() - 1) != '-') {
result.append('-');
}
result.append(Character.toLowerCase(ch));

View File

@ -211,7 +211,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
private String getKeyName(ConfigurationPropertyName name) {
StringBuilder result = new StringBuilder();
for (int i = this.root.getNumberOfElements(); i < name.getNumberOfElements(); i++) {
if (result.length() != 0) {
if (!result.isEmpty()) {
result.append('.');
}
result.append(name.getElement(i, Form.ORIGINAL));

View File

@ -543,7 +543,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
StringBuilder result = new StringBuilder(elements * 8);
for (int i = 0; i < elements; i++) {
boolean indexed = isIndexed(i);
if (result.length() > 0 && !indexed) {
if (!result.isEmpty() && !indexed) {
result.append('.');
}
if (indexed) {
@ -615,7 +615,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
Assert.isTrue(returnNullIfInvalid, "Name must not be null");
return null;
}
if (name.length() == 0) {
if (name.isEmpty()) {
return Elements.EMPTY;
}
if (name.charAt(0) == '.' || name.charAt(name.length() - 1) == '.') {
@ -674,7 +674,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
static ConfigurationPropertyName adapt(CharSequence name, char separator,
Function<CharSequence, CharSequence> elementValueProcessor) {
Assert.notNull(name, "Name must not be null");
if (name.length() == 0) {
if (name.isEmpty()) {
return EMPTY;
}
Elements elements = new ElementsParser(name, separator).parse(elementValueProcessor);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@ -57,7 +57,7 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
private String convertName(ConfigurationPropertyName name, int numberOfElements) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < numberOfElements; i++) {
if (result.length() > 0) {
if (!result.isEmpty()) {
result.append('_');
}
result.append(name.getElement(i, Form.UNIFORM).toUpperCase(Locale.ENGLISH));
@ -68,7 +68,7 @@ final class SystemEnvironmentPropertyMapper implements PropertyMapper {
private String convertLegacyName(ConfigurationPropertyName name) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < name.getNumberOfElements(); i++) {
if (result.length() > 0) {
if (!result.isEmpty()) {
result.append('_');
}
result.append(convertLegacyNameElement(name.getElement(i, Form.ORIGINAL)));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@ -158,7 +158,7 @@ public class BasicJsonParser extends AbstractJsonParser {
}
index++;
}
if (build.length() > 0) {
if (!build.isEmpty()) {
list.add(build.toString().trim());
}
return list;

View File

@ -130,7 +130,7 @@ public final class ColorConverter extends LogEventPatternConverter {
for (PatternFormatter formatter : this.formatters) {
formatter.format(event, buf);
}
if (buf.length() > 0) {
if (!buf.isEmpty()) {
AnsiElement element = this.styling;
if (element == null) {
// Assume highlighting

View File

@ -258,14 +258,14 @@ public class LogbackLoggingSystem extends AbstractLoggingSystem implements BeanF
List<Throwable> suppressedExceptions = new ArrayList<>();
for (Status status : loggerContext.getStatusManager().getCopyOfStatusList()) {
if (status.getLevel() == Status.ERROR) {
errors.append((errors.length() > 0) ? String.format("%n") : "");
errors.append((!errors.isEmpty()) ? String.format("%n") : "");
errors.append(status.toString());
if (status.getThrowable() != null) {
suppressedExceptions.add(status.getThrowable());
}
}
}
if (errors.length() == 0) {
if (errors.isEmpty()) {
if (!StatusUtil.contextHasStatusListener(loggerContext)) {
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}

View File

@ -212,7 +212,7 @@ public final class ConnectionFactoryBuilder {
private ConnectionFactoryOptions delegateFactoryOptions(ConnectionFactoryOptions options) {
String protocol = toString(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL));
if (protocol.trim().length() == 0) {
if (protocol.trim().isEmpty()) {
throw new IllegalArgumentException(String.format("Protocol %s is not valid.", protocol));
}
String[] protocols = protocol.split(COLON, 2);