Prefer Collections.addAll call with array over Set.addAll(Arrays.asList)

This commit is contained in:
Juergen Hoeller
2018-02-25 00:21:39 +01:00
parent 67a91cf6f9
commit 3531c104b0
13 changed files with 59 additions and 70 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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.