Prefer Collections.addAll call with array over Set.addAll(Arrays.asList)
This commit is contained in:
parent
67a91cf6f9
commit
3531c104b0
|
|
@ -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.
|
||||
|
|
@ -18,7 +18,7 @@ package org.springframework.context.annotation;
|
|||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
|
@ -114,7 +114,7 @@ class ComponentScanAnnotationParser {
|
|||
for (String pkg : basePackagesArray) {
|
||||
String[] tokenized = StringUtils.tokenizeToStringArray(this.environment.resolvePlaceholders(pkg),
|
||||
ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
||||
basePackages.addAll(Arrays.asList(tokenized));
|
||||
Collections.addAll(basePackages, tokenized);
|
||||
}
|
||||
for (Class<?> clazz : componentScan.getClassArray("basePackageClasses")) {
|
||||
basePackages.add(ClassUtils.getPackageName(clazz));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.jmx.export;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
@ -321,7 +321,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
*/
|
||||
public void setExcludedBeans(String... excludedBeans) {
|
||||
this.excludedBeans.clear();
|
||||
this.excludedBeans.addAll(Arrays.asList(excludedBeans));
|
||||
Collections.addAll(this.excludedBeans, excludedBeans);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -868,9 +868,9 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
private void autodetect(Map<String, Object> beans, AutodetectCallback callback) {
|
||||
Assert.state(this.beanFactory != null, "No BeanFactory set");
|
||||
Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
|
||||
beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
|
||||
Collections.addAll(beanNames, this.beanFactory.getBeanDefinitionNames());
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
|
||||
Collections.addAll(beanNames, ((ConfigurableBeanFactory) this.beanFactory).getSingletonNames());
|
||||
}
|
||||
|
||||
for (String beanName : beanNames) {
|
||||
|
|
|
|||
|
|
@ -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,7 +16,7 @@
|
|||
|
||||
package org.springframework.jndi.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
|
@ -92,7 +92,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
|
|||
* (typically within the "java:comp/env/" namespace)
|
||||
*/
|
||||
public void setShareableResources(String... shareableResources) {
|
||||
this.shareableResources.addAll(Arrays.asList(shareableResources));
|
||||
Collections.addAll(this.shareableResources, shareableResources);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -18,7 +18,7 @@ package org.springframework.core;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
|
|
@ -61,7 +61,7 @@ public abstract class MethodIntrospector {
|
|||
handlerTypes.add(targetType);
|
||||
specificHandlerType = targetType;
|
||||
}
|
||||
handlerTypes.addAll(Arrays.asList(targetType.getInterfaces()));
|
||||
Collections.addAll(handlerTypes, targetType.getInterfaces());
|
||||
|
||||
for (Class<?> currentHandlerType : handlerTypes) {
|
||||
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
|
||||
|
|
|
|||
|
|
@ -125,8 +125,8 @@ public abstract class ClassUtils {
|
|||
|
||||
Set<Class<?>> primitiveTypes = new HashSet<>(32);
|
||||
primitiveTypes.addAll(primitiveWrapperTypeMap.values());
|
||||
primitiveTypes.addAll(Arrays.asList(boolean[].class, byte[].class, char[].class,
|
||||
double[].class, float[].class, int[].class, long[].class, short[].class));
|
||||
Collections.addAll(primitiveTypes, boolean[].class, byte[].class, char[].class,
|
||||
double[].class, float[].class, int[].class, long[].class, short[].class);
|
||||
primitiveTypes.add(void.class);
|
||||
for (Class<?> primitiveType : primitiveTypes) {
|
||||
primitiveTypeNameMap.put(primitiveType.getName(), primitiveType);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -22,6 +22,7 @@ import java.lang.reflect.Proxy;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -137,7 +138,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
return (m1pl < m2pl ? -1 : (m1pl > m2pl ? 1 : 0));
|
||||
return Integer.compare(m1pl, m2pl);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -228,14 +229,14 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
|||
}
|
||||
}
|
||||
// Also expose methods from java.lang.Class itself
|
||||
result.addAll(Arrays.asList(getMethods(Class.class)));
|
||||
Collections.addAll(result, getMethods(Class.class));
|
||||
return result;
|
||||
}
|
||||
else if (Proxy.isProxyClass(type)) {
|
||||
Set<Method> result = new LinkedHashSet<>();
|
||||
// Expose interface methods (not proxy-declared overrides) for proper vararg introspection
|
||||
for (Class<?> ifc : type.getInterfaces()) {
|
||||
result.addAll(Arrays.asList(getMethods(ifc)));
|
||||
Collections.addAll(result, getMethods(ifc));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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,7 +16,7 @@
|
|||
|
||||
package org.springframework.remoting.jaxws;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
|
@ -137,9 +137,9 @@ public abstract class AbstractJaxWsServiceExporter implements BeanFactoryAware,
|
|||
Assert.state(this.beanFactory != null, "No BeanFactory set");
|
||||
|
||||
Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
|
||||
beanNames.addAll(Arrays.asList(this.beanFactory.getBeanDefinitionNames()));
|
||||
Collections.addAll(beanNames, this.beanFactory.getBeanDefinitionNames());
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
beanNames.addAll(Arrays.asList(((ConfigurableBeanFactory) this.beanFactory).getSingletonNames()));
|
||||
Collections.addAll(beanNames, ((ConfigurableBeanFactory) this.beanFactory).getSingletonNames());
|
||||
}
|
||||
|
||||
for (String beanName : beanNames) {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -118,7 +118,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me
|
|||
* @param resolvers the resolvers to add
|
||||
*/
|
||||
public void addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers) {
|
||||
this.resolvers.addAll(Arrays.asList(resolvers));
|
||||
Collections.addAll(this.resolvers, resolvers);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
|
|||
*/
|
||||
public void register(Class<?>... annotatedClasses) {
|
||||
Assert.notEmpty(annotatedClasses, "At least one annotated class must be specified");
|
||||
this.annotatedClasses.addAll(Arrays.asList(annotatedClasses));
|
||||
Collections.addAll(this.annotatedClasses, annotatedClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,7 +164,7 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
|
|||
*/
|
||||
public void scan(String... basePackages) {
|
||||
Assert.notEmpty(basePackages, "At least one base package must be specified");
|
||||
this.basePackages.addAll(Arrays.asList(basePackages));
|
||||
Collections.addAll(this.basePackages, basePackages);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +16,6 @@
|
|||
|
||||
package org.springframework.web.method.annotation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -59,9 +58,9 @@ public class SessionAttributesHandler {
|
|||
|
||||
|
||||
/**
|
||||
* Create a new instance for a controller type. Session attribute names and
|
||||
* types are extracted from the {@code @SessionAttributes} annotation, if
|
||||
* present, on the given type.
|
||||
* Create a new session attributes handler. Session attribute names and types
|
||||
* are extracted from the {@code @SessionAttributes} annotation, if present,
|
||||
* on the given type.
|
||||
* @param handlerType the controller type
|
||||
* @param sessionAttributeStore used for session access
|
||||
*/
|
||||
|
|
@ -69,15 +68,15 @@ public class SessionAttributesHandler {
|
|||
Assert.notNull(sessionAttributeStore, "SessionAttributeStore may not be null");
|
||||
this.sessionAttributeStore = sessionAttributeStore;
|
||||
|
||||
SessionAttributes annotation =
|
||||
AnnotatedElementUtils.findMergedAnnotation(handlerType, SessionAttributes.class);
|
||||
if (annotation != null) {
|
||||
this.attributeNames.addAll(Arrays.asList(annotation.names()));
|
||||
this.attributeTypes.addAll(Arrays.asList(annotation.types()));
|
||||
SessionAttributes ann = AnnotatedElementUtils.findMergedAnnotation(handlerType, SessionAttributes.class);
|
||||
if (ann != null) {
|
||||
Collections.addAll(this.attributeNames, ann.names());
|
||||
Collections.addAll(this.attributeTypes, ann.types());
|
||||
}
|
||||
this.knownAttributeNames.addAll(this.attributeNames);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether the controller represented by this instance has declared any
|
||||
* session attributes through an {@link SessionAttributes} annotation.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
package org.springframework.web.reactive.result.method.annotation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -46,17 +45,16 @@ class SessionAttributesHandler {
|
|||
|
||||
|
||||
/**
|
||||
* Create a new instance for a controller type. Session attribute names and
|
||||
* types are extracted from the {@code @SessionAttributes} annotation, if
|
||||
* present, on the given type.
|
||||
* Create a new session attributes handler. Session attribute names and types
|
||||
* are extracted from the {@code @SessionAttributes} annotation, if present,
|
||||
* on the given type.
|
||||
* @param handlerType the controller type
|
||||
*/
|
||||
public SessionAttributesHandler(Class<?> handlerType) {
|
||||
SessionAttributes annotation =
|
||||
AnnotatedElementUtils.findMergedAnnotation(handlerType, SessionAttributes.class);
|
||||
if (annotation != null) {
|
||||
this.attributeNames.addAll(Arrays.asList(annotation.names()));
|
||||
this.attributeTypes.addAll(Arrays.asList(annotation.types()));
|
||||
SessionAttributes ann = AnnotatedElementUtils.findMergedAnnotation(handlerType, SessionAttributes.class);
|
||||
if (ann != null) {
|
||||
Collections.addAll(this.attributeNames, ann.names());
|
||||
Collections.addAll(this.attributeTypes, ann.types());
|
||||
}
|
||||
this.knownAttributeNames.addAll(this.attributeNames);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue