Merge pull request #13961 from dreis2211:optimize-stringbuilder-appends

* pr/13961:
  Optimize some StringBuilder.append() calls
pull/14003/head
Stephane Nicoll 6 years ago
commit 9de3d33e65

@ -230,7 +230,9 @@ abstract class ArchiveCommand extends OptionParsingCommand {
private String commaDelimitedClassNames(Class<?>[] classes) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < classes.length; i++) {
builder.append((i != 0) ? "," : "");
if (i != 0) {
builder.append(',');
}
builder.append(classes[i].getName());
}
return builder.toString();

@ -115,8 +115,10 @@ class PropertyMappingContextCustomizer implements ContextCustomizer {
private String getAnnotationsDescription(Set<Class<?>> annotations) {
StringBuilder result = new StringBuilder();
for (Class<?> annotation : annotations) {
result.append((result.length() != 0) ? ", " : "");
result.append("@" + ClassUtils.getShortName(annotation));
if (result.length() != 0) {
result.append(", ");
}
result.append('@').append(ClassUtils.getShortName(annotation));
}
result.insert(0, (annotations.size() != 1) ? "annotations " : "annotation ");
return result.toString();

@ -63,9 +63,11 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
}
StringBuilder fullName = new StringBuilder((prefix != null) ? prefix : "");
if (fullName.length() > 0 && name != null) {
fullName.append(".");
fullName.append('.');
}
if (name != null) {
fullName.append(ConfigurationMetadata.toDashedCase(name));
}
fullName.append((name != null) ? ConfigurationMetadata.toDashedCase(name) : "");
return fullName.toString();
}

@ -331,9 +331,10 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
try {
StringBuilder classpath = new StringBuilder();
for (URL ele : getClassPathUrls()) {
classpath = classpath
.append(((classpath.length() > 0) ? File.pathSeparator : "")
+ new File(ele.toURI()));
if (classpath.length() > 0) {
classpath.append(File.pathSeparator);
}
classpath.append(new File(ele.toURI()));
}
getLog().debug("Classpath for forked process: " + classpath);
args.add("-cp");

@ -216,7 +216,9 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
StringBuilder result = new StringBuilder();
for (int i = this.root.getNumberOfElements(); i < name
.getNumberOfElements(); i++) {
result.append((result.length() != 0) ? "." : "");
if (result.length() != 0) {
result.append('.');
}
result.append(name.getElement(i, Form.ORIGINAL));
}
return result.toString();

@ -394,7 +394,7 @@ public final class ConfigurationPropertyName
for (CharSequence element : elements) {
boolean indexed = isIndexed(element);
if (result.length() > 0 && !indexed) {
result.append(".");
result.append('.');
}
if (indexed) {
result.append(element);
@ -402,7 +402,9 @@ public final class ConfigurationPropertyName
else {
for (int i = 0; i < element.length(); i++) {
char ch = Character.toLowerCase(element.charAt(i));
result.append((ch != '_') ? ch : "");
if (ch != '_') {
result.append(ch);
}
}
}
}

@ -172,8 +172,10 @@ public class JettyWebServer implements WebServer {
private String getActualPortsDescription() {
StringBuilder ports = new StringBuilder();
for (Connector connector : this.server.getConnectors()) {
ports.append((ports.length() != 0) ? ", " : "");
ports.append(getLocalPort(connector) + getProtocols(connector));
if (ports.length() != 0) {
ports.append(", ");
}
ports.append(getLocalPort(connector)).append(getProtocols(connector));
}
return ports.toString();
}

@ -319,9 +319,11 @@ public class TomcatWebServer implements WebServer {
private String getPortsDescription(boolean localPort) {
StringBuilder ports = new StringBuilder();
for (Connector connector : this.tomcat.getService().findConnectors()) {
ports.append((ports.length() != 0) ? " " : "");
if (ports.length() != 0) {
ports.append(' ');
}
int port = localPort ? connector.getLocalPort() : connector.getPort();
ports.append(port + " (" + connector.getScheme() + ")");
ports.append(port).append(" (").append(connector.getScheme()).append(')');
}
return ports.toString();
}

Loading…
Cancel
Save