mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Make use of Collections.addAll instead of a for-loop where appropriate
Closes gh-2309
This commit is contained in:
parent
78432fc745
commit
966e8e557d
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()]));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user