Make use of Collections.addAll instead of a for-loop where appropriate

Closes gh-2309
This commit is contained in:
Andy Wilkinson 2015-01-19 13:20:46 +00:00
parent 78432fc745
commit 966e8e557d
3 changed files with 5 additions and 10 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.condition;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -101,9 +102,7 @@ class OnClassCondition extends SpringBootCondition {
private void addAll(List<String> list, List<Object> itemsToAdd) {
if (itemsToAdd != null) {
for (Object item : itemsToAdd) {
for (String arrayItem : (String[]) item) {
list.add(arrayItem.toString());
}
Collections.addAll(list, (String[]) item);
}
}
}

View File

@ -455,12 +455,9 @@ public class SpringApplication {
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
protected void configureProfiles(ConfigurableEnvironment environment, String[] args) {
Set<String> profiles = new LinkedHashSet<String>();
environment.getActiveProfiles(); // ensure they are initialized
// But these ones should go first (last wins in a property key clash)
for (String profile : this.profiles) {
profiles.add(profile);
}
Set<String> profiles = new LinkedHashSet<String>(this.profiles);
profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
environment.setActiveProfiles(profiles.toArray(new String[profiles.size()]));
}

View File

@ -16,6 +16,7 @@
package org.springframework.boot.context.web;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
@ -73,9 +74,7 @@ public class SpringBootServletInitializerTests {
private Matcher<? super Set<Object>> equalToSet(Object... items) {
Set<Object> set = new LinkedHashSet<Object>();
for (Object item : items) {
set.add(item);
}
Collections.addAll(set, items);
return equalTo(set);
}