Prefer Collections.addAll call with array over Set.addAll(Arrays.asList)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.test.context.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.test.context.ContextConfigurationAttributes;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Utility methods for working with {@link ApplicationContextInitializer
|
||||
* ApplicationContextInitializers}.
|
||||
* Utility methods for working with
|
||||
* {@link ApplicationContextInitializer ApplicationContextInitializers}.
|
||||
*
|
||||
* <p>Although {@code ApplicationContextInitializerUtils} was first introduced
|
||||
* in Spring Framework 4.1, the initial implementations of methods in this class
|
||||
@@ -46,21 +46,15 @@ abstract class ApplicationContextInitializerUtils {
|
||||
private static final Log logger = LogFactory.getLog(ApplicationContextInitializerUtils.class);
|
||||
|
||||
|
||||
private ApplicationContextInitializerUtils() {
|
||||
/* no-op */
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the set of merged {@code ApplicationContextInitializer} classes for the
|
||||
* supplied list of {@code ContextConfigurationAttributes}.
|
||||
*
|
||||
* <p>Note that the {@link ContextConfiguration#inheritInitializers inheritInitializers}
|
||||
* flag of {@link ContextConfiguration @ContextConfiguration} will be taken into
|
||||
* consideration. Specifically, if the {@code inheritInitializers} flag is set to
|
||||
* {@code true} for a given level in the class hierarchy represented by the provided
|
||||
* configuration attributes, context initializer classes defined at the given level
|
||||
* will be merged with those defined in higher levels of the class hierarchy.
|
||||
*
|
||||
* @param configAttributesList the list of configuration attributes to process; must
|
||||
* not be {@code null} or <em>empty</em>; must be ordered <em>bottom-up</em>
|
||||
* (i.e., as if we were traversing up the class hierarchy)
|
||||
@@ -70,19 +64,15 @@ abstract class ApplicationContextInitializerUtils {
|
||||
*/
|
||||
static Set<Class<? extends ApplicationContextInitializer<?>>> resolveInitializerClasses(
|
||||
List<ContextConfigurationAttributes> configAttributesList) {
|
||||
Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty");
|
||||
|
||||
final Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses = //
|
||||
new HashSet<>();
|
||||
Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes List must not be empty");
|
||||
Set<Class<? extends ApplicationContextInitializer<?>>> initializerClasses = new LinkedHashSet<>();
|
||||
|
||||
for (ContextConfigurationAttributes configAttributes : configAttributesList) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace(String.format("Processing context initializers for context configuration attributes %s",
|
||||
configAttributes));
|
||||
logger.trace("Processing context initializers for configuration attributes " + configAttributes);
|
||||
}
|
||||
|
||||
initializerClasses.addAll(Arrays.asList(configAttributes.getInitializers()));
|
||||
|
||||
Collections.addAll(initializerClasses, configAttributes.getInitializers());
|
||||
if (!configAttributes.isInheritInitializers()) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.test.web.servlet.htmlunit;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -65,9 +65,10 @@ public final class HostRequestMatcher implements WebRequestMatcher {
|
||||
* @param hosts the hosts to match on
|
||||
*/
|
||||
public HostRequestMatcher(String... hosts) {
|
||||
this.hosts.addAll(Arrays.asList(hosts));
|
||||
Collections.addAll(this.hosts, hosts);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean matches(WebRequest request) {
|
||||
URL url = request.getUrl();
|
||||
|
||||
Reference in New Issue
Block a user