Use StringJoiner where possible to simplify String joining
This commit is contained in:
parent
766a23bd93
commit
dc8fb8bc5e
|
@ -33,6 +33,7 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
@ -724,15 +725,11 @@ class ConfigurationClassParser {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder("[");
|
StringJoiner joiner = new StringJoiner("->", "[", "]");
|
||||||
Iterator<ConfigurationClass> iterator = iterator();
|
for (ConfigurationClass configurationClass : this) {
|
||||||
while (iterator.hasNext()) {
|
joiner.add(configurationClass.getSimpleName());
|
||||||
builder.append(iterator.next().getSimpleName());
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
builder.append("->");
|
|
||||||
}
|
}
|
||||||
}
|
return joiner.toString();
|
||||||
return builder.append(']').toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -946,7 +943,7 @@ class ConfigurationClassParser {
|
||||||
return new AssignableTypeFilter(clazz).match((MetadataReader) this.source, metadataReaderFactory);
|
return new AssignableTypeFilter(clazz).match((MetadataReader) this.source, metadataReaderFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationClass asConfigClass(ConfigurationClass importedBy) throws IOException {
|
public ConfigurationClass asConfigClass(ConfigurationClass importedBy) {
|
||||||
if (this.source instanceof Class) {
|
if (this.source instanceof Class) {
|
||||||
return new ConfigurationClass((Class<?>) this.source, importedBy);
|
return new ConfigurationClass((Class<?>) this.source, importedBy);
|
||||||
}
|
}
|
||||||
|
@ -1014,7 +1011,7 @@ class ConfigurationClassParser {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<SourceClass> getAnnotations() throws IOException {
|
public Set<SourceClass> getAnnotations() {
|
||||||
Set<SourceClass> result = new LinkedHashSet<>();
|
Set<SourceClass> result = new LinkedHashSet<>();
|
||||||
for (String className : this.metadata.getAnnotationTypes()) {
|
for (String className : this.metadata.getAnnotationTypes()) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
@ -656,16 +657,11 @@ public abstract class ClassUtils {
|
||||||
if (CollectionUtils.isEmpty(classes)) {
|
if (CollectionUtils.isEmpty(classes)) {
|
||||||
return "[]";
|
return "[]";
|
||||||
}
|
}
|
||||||
StringBuilder sb = new StringBuilder("[");
|
StringJoiner sj = new StringJoiner(", ", "[", "]");
|
||||||
for (Iterator<Class<?>> it = classes.iterator(); it.hasNext(); ) {
|
for (Class<?> clazz : classes) {
|
||||||
Class<?> clazz = it.next();
|
sj.add(clazz.getName());
|
||||||
sb.append(clazz.getName());
|
|
||||||
if (it.hasNext()) {
|
|
||||||
sb.append(", ");
|
|
||||||
}
|
}
|
||||||
}
|
return sj.toString();
|
||||||
sb.append("]");
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,6 +39,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.StringJoiner;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -1505,17 +1506,13 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||||
* @return a combined result with comma delimitation
|
* @return a combined result with comma delimitation
|
||||||
*/
|
*/
|
||||||
protected String toCommaDelimitedString(List<String> headerValues) {
|
protected String toCommaDelimitedString(List<String> headerValues) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringJoiner joiner = new StringJoiner(", ");
|
||||||
for (Iterator<String> it = headerValues.iterator(); it.hasNext();) {
|
for (String val : headerValues) {
|
||||||
String val = it.next();
|
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
builder.append(val);
|
joiner.add(val);
|
||||||
if (it.hasNext()) {
|
|
||||||
builder.append(", ");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return joiner.toString();
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue