Use StringJoiner where possible to simplify String joining
Closes gh-23237
This commit is contained in:
committed by
Sam Brannen
parent
8f5b2b2231
commit
9f81ffa5ae
@@ -18,6 +18,7 @@ package org.springframework.beans;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -85,12 +86,9 @@ public class PropertyBatchUpdateException extends BeansException {
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
StringBuilder sb = new StringBuilder("Failed properties: ");
|
||||
for (int i = 0; i < this.propertyAccessExceptions.length; i++) {
|
||||
sb.append(this.propertyAccessExceptions[i].getMessage());
|
||||
if (i < this.propertyAccessExceptions.length - 1) {
|
||||
sb.append("; ");
|
||||
}
|
||||
StringJoiner sb = new StringJoiner("; ", "Failed properties: ", "");
|
||||
for (PropertyAccessException exception : this.propertyAccessExceptions) {
|
||||
sb.add(exception.getMessage());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.core.SerializableTypeWrapper.FieldTypeProvider;
|
||||
import org.springframework.core.SerializableTypeWrapper.MethodParameterTypeProvider;
|
||||
@@ -1518,18 +1519,15 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
StringBuilder result = new StringBuilder(this.rawType.getTypeName());
|
||||
String typeName = this.rawType.getTypeName();
|
||||
if (this.typeArguments.length > 0) {
|
||||
result.append('<');
|
||||
for (int i = 0; i < this.typeArguments.length; i++) {
|
||||
if (i > 0) {
|
||||
result.append(", ");
|
||||
}
|
||||
result.append(this.typeArguments[i].getTypeName());
|
||||
StringJoiner result = new StringJoiner(", ", "<", ">");
|
||||
for (Type argument : this.typeArguments) {
|
||||
result.add(argument.getTypeName());
|
||||
}
|
||||
result.append('>');
|
||||
return typeName + result.toString();
|
||||
}
|
||||
return result.toString();
|
||||
return typeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -911,14 +911,10 @@ public abstract class ClassUtils {
|
||||
}
|
||||
Class<?> clazz = value.getClass();
|
||||
if (Proxy.isProxyClass(clazz)) {
|
||||
StringBuilder result = new StringBuilder(clazz.getName());
|
||||
result.append(" implementing ");
|
||||
Class<?>[] ifcs = clazz.getInterfaces();
|
||||
for (int i = 0; i < ifcs.length; i++) {
|
||||
result.append(ifcs[i].getName());
|
||||
if (i < ifcs.length - 1) {
|
||||
result.append(',');
|
||||
}
|
||||
String prefix = clazz.getName() + " implementing ";
|
||||
StringJoiner result = new StringJoiner(",", prefix, "");
|
||||
for (Class<?> ifc : clazz.getInterfaces()) {
|
||||
result.add(ifc.getName());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.springframework.http.server.PathContainer;
|
||||
import org.springframework.http.server.PathContainer.Element;
|
||||
@@ -465,13 +466,13 @@ public class PathPattern implements Comparable<PathPattern> {
|
||||
}
|
||||
|
||||
String toChainString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
StringJoiner buf = new StringJoiner(" ");
|
||||
PathElement pe = this.head;
|
||||
while (pe != null) {
|
||||
buf.append(pe.toString()).append(" ");
|
||||
buf.add(pe.toString());
|
||||
pe = pe.next;
|
||||
}
|
||||
return buf.toString().trim();
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user