diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java index 48c9e48ab97..22be8cc7126 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java @@ -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)); diff --git a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java index 5606e0039e8..4d574355dc0 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java @@ -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 beans, AutodetectCallback callback) { Assert.state(this.beanFactory != null, "No BeanFactory set"); Set 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) { diff --git a/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java b/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java index 42927b64bf4..db0aa772d04 100644 --- a/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java +++ b/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java @@ -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); } diff --git a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java index 28d817e08a2..d220814653c 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java +++ b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java @@ -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); diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index daabe589e5a..788678682bc 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -125,8 +125,8 @@ public abstract class ClassUtils { Set> 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); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java index 4d1f5242aad..df7860a5fda 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java @@ -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 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; } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java index e429169bd31..bf6faf2d8d1 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/ApplicationContextInitializerUtils.java @@ -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}. * *

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}. - * *

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 empty; must be ordered bottom-up * (i.e., as if we were traversing up the class hierarchy) @@ -70,19 +64,15 @@ abstract class ApplicationContextInitializerUtils { */ static Set>> resolveInitializerClasses( List configAttributesList) { - Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes list must not be empty"); - final Set>> initializerClasses = // - new HashSet<>(); + Assert.notEmpty(configAttributesList, "ContextConfigurationAttributes List must not be empty"); + Set>> 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; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcher.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcher.java index 3a06cd8a269..a540725d064 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcher.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HostRequestMatcher.java @@ -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(); diff --git a/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java b/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java index 782122bf2dc..346f3a897b1 100644 --- a/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java +++ b/spring-web/src/main/java/org/springframework/remoting/jaxws/AbstractJaxWsServiceExporter.java @@ -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 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) { diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java index 0913a603507..3b910adcb80 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManager.java @@ -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 diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java index 115a39a669a..2ffb43c4cd5 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java @@ -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); } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java index 96c5323c39d..ee90f4f95f1 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java @@ -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. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java index a03c35e7002..97c10f61e0a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionAttributesHandler.java @@ -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); }