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