Merge pull request #15589 from igor-suhorukov

* pr/15589:
  Polish "Avoid string concatenation inside StringBuilder append()"
  Avoid string concatenation inside StringBuilder append()
pull/15694/head
Stephane Nicoll 6 years ago
commit 168d2f897e

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -180,9 +180,9 @@ class DiscoveredJmxOperation extends AbstractDiscoveredOperation implements JmxO
public String toString() { public String toString() {
StringBuilder result = new StringBuilder(this.name); StringBuilder result = new StringBuilder(this.name);
if (this.description != null) { if (this.description != null) {
result.append(" (" + this.description + ")"); result.append(" (").append(this.description).append(")");
} }
result.append(":" + this.type); result.append(":").append(this.type);
return result.toString(); return result.toString();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -124,12 +124,12 @@ public final class WebOperationRequestPredicate {
StringBuilder result = new StringBuilder( StringBuilder result = new StringBuilder(
this.httpMethod + " to path '" + this.path + "'"); this.httpMethod + " to path '" + this.path + "'");
if (!CollectionUtils.isEmpty(this.consumes)) { if (!CollectionUtils.isEmpty(this.consumes)) {
result.append(" consumes: " result.append(" consumes: ")
+ StringUtils.collectionToCommaDelimitedString(this.consumes)); .append(StringUtils.collectionToCommaDelimitedString(this.consumes));
} }
if (!CollectionUtils.isEmpty(this.produces)) { if (!CollectionUtils.isEmpty(this.produces)) {
result.append(" produces: " result.append(" produces: ")
+ StringUtils.collectionToCommaDelimitedString(this.produces)); .append(StringUtils.collectionToCommaDelimitedString(this.produces));
} }
return result.toString(); return result.toString();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -386,14 +386,14 @@ public final class ConditionMessage {
items = style.applyTo(items); items = style.applyTo(items);
if ((this.condition == null || items.size() <= 1) if ((this.condition == null || items.size() <= 1)
&& StringUtils.hasLength(this.singular)) { && StringUtils.hasLength(this.singular)) {
message.append(" " + this.singular); message.append(" ").append(this.singular);
} }
else if (StringUtils.hasLength(this.plural)) { else if (StringUtils.hasLength(this.plural)) {
message.append(" " + this.plural); message.append(" ").append(this.plural);
} }
if (items != null && !items.isEmpty()) { if (items != null && !items.isEmpty()) {
message.append( message.append(" ")
" " + StringUtils.collectionToDelimitedString(items, ", ")); .append(StringUtils.collectionToDelimitedString(items, ", "));
} }
return this.condition.because(message.toString()); return this.condition.because(message.toString());
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -66,9 +66,9 @@ class ServiceCapabilitiesReportGenerator {
private String generateHelp(String url, InitializrServiceMetadata metadata) { private String generateHelp(String url, InitializrServiceMetadata metadata) {
String header = "Capabilities of " + url; String header = "Capabilities of " + url;
StringBuilder report = new StringBuilder(); StringBuilder report = new StringBuilder();
report.append(repeat("=", header.length()) + NEW_LINE); report.append(repeat("=", header.length())).append(NEW_LINE);
report.append(header + NEW_LINE); report.append(header).append(NEW_LINE);
report.append(repeat("=", header.length()) + NEW_LINE); report.append(repeat("=", header.length())).append(NEW_LINE);
report.append(NEW_LINE); report.append(NEW_LINE);
reportAvailableDependencies(metadata, report); reportAvailableDependencies(metadata, report);
report.append(NEW_LINE); report.append(NEW_LINE);
@ -80,13 +80,13 @@ class ServiceCapabilitiesReportGenerator {
private void reportAvailableDependencies(InitializrServiceMetadata metadata, private void reportAvailableDependencies(InitializrServiceMetadata metadata,
StringBuilder report) { StringBuilder report) {
report.append("Available dependencies:" + NEW_LINE); report.append("Available dependencies:").append(NEW_LINE);
report.append("-----------------------" + NEW_LINE); report.append("-----------------------").append(NEW_LINE);
List<Dependency> dependencies = getSortedDependencies(metadata); List<Dependency> dependencies = getSortedDependencies(metadata);
for (Dependency dependency : dependencies) { for (Dependency dependency : dependencies) {
report.append(dependency.getId() + " - " + dependency.getName()); report.append(dependency.getId()).append(" - ").append(dependency.getName());
if (dependency.getDescription() != null) { if (dependency.getDescription() != null) {
report.append(": " + dependency.getDescription()); report.append(": ").append(dependency.getDescription());
} }
report.append(NEW_LINE); report.append(NEW_LINE);
} }
@ -100,14 +100,14 @@ class ServiceCapabilitiesReportGenerator {
private void reportAvailableProjectTypes(InitializrServiceMetadata metadata, private void reportAvailableProjectTypes(InitializrServiceMetadata metadata,
StringBuilder report) { StringBuilder report) {
report.append("Available project types:" + NEW_LINE); report.append("Available project types:").append(NEW_LINE);
report.append("------------------------" + NEW_LINE); report.append("------------------------").append(NEW_LINE);
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>( SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>(
Comparator.comparing(Entry::getKey)); Comparator.comparing(Entry::getKey));
entries.addAll(metadata.getProjectTypes().entrySet()); entries.addAll(metadata.getProjectTypes().entrySet());
for (Entry<String, ProjectType> entry : entries) { for (Entry<String, ProjectType> entry : entries) {
ProjectType type = entry.getValue(); ProjectType type = entry.getValue();
report.append(entry.getKey() + " - " + type.getName()); report.append(entry.getKey()).append(" - ").append(type.getName());
if (!type.getTags().isEmpty()) { if (!type.getTags().isEmpty()) {
reportTags(report, type); reportTags(report, type);
} }
@ -124,7 +124,7 @@ class ServiceCapabilitiesReportGenerator {
report.append(" ["); report.append(" [");
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next(); Map.Entry<String, String> entry = iterator.next();
report.append(entry.getKey() + ":" + entry.getValue()); report.append(entry.getKey()).append(":").append(entry.getValue());
if (iterator.hasNext()) { if (iterator.hasNext()) {
report.append(", "); report.append(", ");
} }
@ -134,13 +134,14 @@ class ServiceCapabilitiesReportGenerator {
private void reportDefaults(StringBuilder report, private void reportDefaults(StringBuilder report,
InitializrServiceMetadata metadata) { InitializrServiceMetadata metadata) {
report.append("Defaults:" + NEW_LINE); report.append("Defaults:").append(NEW_LINE);
report.append("---------" + NEW_LINE); report.append("---------").append(NEW_LINE);
List<String> defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet()); List<String> defaultsKeys = new ArrayList<>(metadata.getDefaults().keySet());
Collections.sort(defaultsKeys); Collections.sort(defaultsKeys);
for (String defaultsKey : defaultsKeys) { for (String defaultsKey : defaultsKeys) {
String defaultsValue = metadata.getDefaults().get(defaultsKey); String defaultsValue = metadata.getDefaults().get(defaultsKey);
report.append(defaultsKey + ": " + defaultsValue + NEW_LINE); report.append(defaultsKey).append(": ").append(defaultsValue)
.append(NEW_LINE);
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -108,7 +108,7 @@ public final class Metadata {
private String createDescription() { private String createDescription() {
StringBuilder description = new StringBuilder(); StringBuilder description = new StringBuilder();
description.append("an item named '" + this.name + "'"); description.append("an item named '").append(this.name).append("'");
if (this.type != null) { if (this.type != null) {
description.append(" with dataType:").append(this.type); description.append(" with dataType:").append(this.type);
} }
@ -258,7 +258,7 @@ public final class Metadata {
private String createDescription() { private String createDescription() {
StringBuilder description = new StringBuilder(); StringBuilder description = new StringBuilder();
description.append("a hints name '" + this.name + "'"); description.append("a hints name '").append(this.name).append("'");
if (!this.valueConditions.isEmpty()) { if (!this.valueConditions.isEmpty()) {
description.append(" with values:").append(this.valueConditions); description.append(" with values:").append(this.valueConditions);
} }
@ -348,7 +348,7 @@ public final class Metadata {
private String createDescription() { private String createDescription() {
StringBuilder description = new StringBuilder(); StringBuilder description = new StringBuilder();
description.append("value hint at index '" + this.index + "'"); description.append("value hint at index '").append(this.index).append("'");
if (this.value != null) { if (this.value != null) {
description.append(" with value:").append(this.value); description.append(" with value:").append(this.value);
} }

@ -52,11 +52,11 @@ class UnresolvedDependenciesAnalyzer {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.append("\nDuring the build, one or more dependencies that were " message.append("\nDuring the build, one or more dependencies that were "
+ "declared without a version failed to resolve:\n"); + "declared without a version failed to resolve:\n");
this.dependenciesWithNoVersion this.dependenciesWithNoVersion.forEach((dependency) -> message.append(" ")
.forEach((dependency) -> message.append(" " + dependency + "\n")); .append(dependency).append("\n"));
message.append("\nDid you forget to apply the " message.append("\nDid you forget to apply the "
+ "io.spring.dependency-management plugin to the " + project.getName() + "io.spring.dependency-management plugin to the ");
+ " project?\n"); message.append(project.getName()).append(" project?\n");
logger.warn(message.toString()); logger.warn(message.toString());
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -88,7 +88,7 @@ class StartupInfoLogger {
message.append(stopWatch.getTotalTimeSeconds()); message.append(stopWatch.getTotalTimeSeconds());
try { try {
double uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0; double uptime = ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0;
message.append(" seconds (JVM running for " + uptime + ")"); message.append(" seconds (JVM running for ").append(uptime).append(")");
} }
catch (Throwable ex) { catch (Throwable ex) {
// No JVM time available // No JVM time available

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -58,8 +58,8 @@ public class ConfigurationPropertiesBindException extends BeanCreationException
private static String getMessage(Object bean, ConfigurationProperties annotation) { private static String getMessage(Object bean, ConfigurationProperties annotation) {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.append("Could not bind properties to '" message.append("Could not bind properties to '");
+ ClassUtils.getShortName(bean.getClass()) + "' : "); message.append(ClassUtils.getShortName(bean.getClass())).append("' : ");
message.append("prefix=").append(annotation.prefix()); message.append("prefix=").append(annotation.prefix());
message.append(", ignoreInvalidFields=").append(annotation.ignoreInvalidFields()); message.append(", ignoreInvalidFields=").append(annotation.ignoreInvalidFields());
message.append(", ignoreUnknownFields=").append(annotation.ignoreUnknownFields()); message.append(", ignoreUnknownFields=").append(annotation.ignoreUnknownFields());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ public class BindValidationException extends RuntimeException {
private static String getMessage(ValidationErrors errors) { private static String getMessage(ValidationErrors errors) {
StringBuilder message = new StringBuilder("Binding validation errors"); StringBuilder message = new StringBuilder("Binding validation errors");
if (errors != null) { if (errors != null) {
message.append(" on " + errors.getName()); message.append(" on ").append(errors.getName());
errors.getAllErrors().forEach( errors.getAllErrors().forEach(
(error) -> message.append(String.format("%n - %s", error))); (error) -> message.append(String.format("%n - %s", error)));
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -84,8 +84,9 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
InvalidConfigurationPropertyValueException cause, InvalidConfigurationPropertyValueException cause,
List<Descriptor> descriptors) { List<Descriptor> descriptors) {
Descriptor mainDescriptor = descriptors.get(0); Descriptor mainDescriptor = descriptors.get(0);
message.append("Invalid value '" + mainDescriptor.getValue() message.append("Invalid value '").append(mainDescriptor.getValue())
+ "' for configuration property '" + cause.getName() + "'"); .append("' for configuration property '");
message.append(cause.getName()).append("'");
mainDescriptor.appendOrigin(message); mainDescriptor.appendOrigin(message);
message.append("."); message.append(".");
} }
@ -111,8 +112,8 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
+ "property %s:%n%n", + "property %s:%n%n",
(others.size() > 1) ? "sources" : "source")); (others.size() > 1) ? "sources" : "source"));
for (Descriptor other : others) { for (Descriptor other : others) {
message.append("\t- In '" + other.getPropertySource() + "'"); message.append("\t- In '").append(other.getPropertySource()).append("'");
message.append(" with the value '" + other.getValue() + "'"); message.append(" with the value '").append(other.getValue()).append("'");
other.appendOrigin(message); other.appendOrigin(message);
message.append(String.format(".%n")); message.append(String.format(".%n"));
} }
@ -153,7 +154,7 @@ class InvalidConfigurationPropertyValueFailureAnalyzer
public void appendOrigin(StringBuilder message) { public void appendOrigin(StringBuilder message) {
if (this.origin != null) { if (this.origin != null) {
message.append(" (originating from '" + this.origin + "')"); message.append(" (originating from '").append(this.origin).append("')");
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,7 +55,7 @@ public class YamlPropertySourceLoaderTests {
StringBuilder yaml = new StringBuilder(); StringBuilder yaml = new StringBuilder();
List<String> expected = new ArrayList<>(); List<String> expected = new ArrayList<>();
for (char c = 'a'; c <= 'z'; c++) { for (char c = 'a'; c <= 'z'; c++) {
yaml.append(c + ": value" + c + "\n"); yaml.append(c).append(": value").append(c).append("\n");
expected.add(String.valueOf(c)); expected.add(String.valueOf(c));
} }
ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes()); ByteArrayResource resource = new ByteArrayResource(yaml.toString().getBytes());

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -1260,7 +1260,8 @@ public abstract class AbstractServletWebServerFactoryTests {
Object existing = session.getAttribute("boot"); Object existing = session.getAttribute("boot");
session.setAttribute("boot", value); session.setAttribute("boot", value);
PrintWriter writer = response.getWriter(); PrintWriter writer = response.getWriter();
writer.append(String.valueOf(existing) + ":" + value); writer.append(String.valueOf(existing)).append(":")
.append(String.valueOf(value));
} }
}, "/session"); }, "/session");

Loading…
Cancel
Save