Use .isEmpty() where feasible
See gh-38739
This commit is contained in:
committed by
Phillip Webb
parent
d3af5cce73
commit
ac18e3015c
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user