Use Collections.addAll(...) instead of for loops

Replace various for loops which add items to collections with calls
to Collections.addAll(...).

Fixes gh-2277
pull/1991/head
Phillip Webb 10 years ago
parent 4940ca37eb
commit 1f775793ee

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.metrics.reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.actuate.metrics.Metric;
@ -31,9 +32,7 @@ public class CompositeMetricReader implements MetricReader {
private final List<MetricReader> readers = new ArrayList<MetricReader>();
public CompositeMetricReader(MetricReader... readers) {
for (MetricReader reader : readers) {
this.readers.add(reader);
}
Collections.addAll(this.readers, readers);
}
@Override

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.metrics.writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.actuate.metrics.Metric;
@ -32,9 +33,7 @@ public class CompositeMetricWriter implements MetricWriter {
private final List<MetricWriter> writers = new ArrayList<MetricWriter>();
public CompositeMetricWriter(MetricWriter... writers) {
for (MetricWriter writer : writers) {
this.writers.add(writer);
}
Collections.addAll(this.writers, writers);
}
public CompositeMetricWriter(List<MetricWriter> writers) {

@ -241,9 +241,7 @@ public class OnBeanCondition extends SpringBootCondition implements
List<String> destination) {
List<String[]> valueList = (List) attributes.get(key);
for (String[] valueArray : valueList) {
for (String value : valueArray) {
destination.add(value);
}
Collections.addAll(destination, valueArray);
}
}

@ -19,6 +19,7 @@ package org.springframework.boot.loader;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -92,9 +93,7 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
}
}
}
for (URL url : urls) {
copy.add(url);
}
Collections.addAll(copy, urls);
return super.createClassLoader(copy.toArray(new URL[copy.size()]));
}

@ -18,6 +18,7 @@ package org.springframework.boot.context.embedded;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.Set;
@ -91,9 +92,7 @@ public class FilterRegistrationBean extends RegistrationBean {
Assert.notNull(servletRegistrationBeans,
"ServletRegistrationBeans must not be null");
this.filter = filter;
for (ServletRegistrationBean servletRegistrationBean : servletRegistrationBeans) {
this.servletRegistrationBeans.add(servletRegistrationBean);
}
Collections.addAll(this.servletRegistrationBeans, servletRegistrationBeans);
}
/**
@ -143,9 +142,7 @@ public class FilterRegistrationBean extends RegistrationBean {
ServletRegistrationBean... servletRegistrationBeans) {
Assert.notNull(servletRegistrationBeans,
"ServletRegistrationBeans must not be null");
for (ServletRegistrationBean servletRegistrationBean : servletRegistrationBeans) {
this.servletRegistrationBeans.add(servletRegistrationBean);
}
Collections.addAll(this.servletRegistrationBeans, servletRegistrationBeans);
}
/**
@ -205,9 +202,7 @@ public class FilterRegistrationBean extends RegistrationBean {
*/
public void addUrlPatterns(String... urlPatterns) {
Assert.notNull(urlPatterns, "UrlPatterns must not be null");
for (String urlPattern : urlPatterns) {
this.urlPatterns.add(urlPattern);
}
Collections.addAll(this.urlPatterns, urlPatterns);
}
/**

@ -17,6 +17,7 @@
package org.springframework.boot.yaml;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Properties;
@ -47,9 +48,7 @@ public class SpringProfileDocumentMatcher implements DocumentMatcher {
public void addActiveProfiles(String... profiles) {
LinkedHashSet<String> set = new LinkedHashSet<String>(
Arrays.asList(this.activeProfiles));
for (String profile : profiles) {
set.add(profile);
}
Collections.addAll(set, profiles);
this.activeProfiles = set.toArray(new String[set.size()]);
}

Loading…
Cancel
Save