diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java index 1295af52b34..9fa04a33e92 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.aop.framework; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.util.Assert; @@ -34,7 +34,7 @@ public class ProxyCreatorSupport extends AdvisedSupport { private AopProxyFactory aopProxyFactory; - private final List listeners = new LinkedList<>(); + private final List listeners = new ArrayList<>(); /** Set to true when the first AOP proxy has been created. */ private boolean active = false; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java index 36375ef84fd..0222cfa9512 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java @@ -16,12 +16,12 @@ package org.springframework.beans.factory.parsing; -import java.util.LinkedList; +import java.util.ArrayDeque; import org.springframework.lang.Nullable; /** - * Simple {@link LinkedList}-based structure for tracking the logical position during + * Simple {@link ArrayDeque}-based structure for tracking the logical position during * a parsing process. {@link Entry entries} are added to the LinkedList at * each point during the parse phase in a reader-specific manner. * @@ -30,6 +30,7 @@ import org.springframework.lang.Nullable; * error messages. * * @author Rob Harrop + * @author Juergen Hoeller * @since 2.0 */ public final class ParseState { @@ -40,25 +41,24 @@ public final class ParseState { private static final char TAB = '\t'; /** - * Internal {@link LinkedList} storage. + * Internal {@link ArrayDeque} storage. */ - private final LinkedList state; + private final ArrayDeque state; /** * Create a new {@code ParseState} with an empty {@link LinkedList}. */ public ParseState() { - this.state = new LinkedList<>(); + this.state = new ArrayDeque<>(); } /** * Create a new {@code ParseState} whose {@link LinkedList} is a {@link Object#clone clone} * of that of the passed in {@code ParseState}. */ - @SuppressWarnings("unchecked") private ParseState(ParseState other) { - this.state = (LinkedList) other.state.clone(); + this.state = other.state.clone(); } @@ -100,15 +100,17 @@ public final class ParseState { @Override public String toString() { StringBuilder sb = new StringBuilder(); - for (int x = 0; x < this.state.size(); x++) { - if (x > 0) { + int i = 0; + for (ParseState.Entry entry : this.state) { + if (i > 0) { sb.append('\n'); - for (int y = 0; y < x; y++) { + for (int j = 0; j < i; j++) { sb.append(TAB); } sb.append("-> "); } - sb.append(this.state.get(x)); + sb.append(entry); + i++; } return sb.toString(); } @@ -118,7 +120,6 @@ public final class ParseState { * Marker interface for entries into the {@link ParseState}. */ public interface Entry { - } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java index b18883bab77..6e97d2f29c8 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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.beans.factory.serviceloader; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; @@ -35,7 +35,7 @@ public class ServiceListFactoryBean extends AbstractServiceLoaderBasedFactoryBea @Override protected Object getObjectToExpose(ServiceLoader serviceLoader) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (Object loaderObject : serviceLoader) { result.add(loaderObject); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java index d5d9b9f871d..f49690677a9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java @@ -24,12 +24,13 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -199,7 +200,7 @@ class ConstructorResolver { AutowireUtils.sortConstructors(candidates); int minTypeDiffWeight = Integer.MAX_VALUE; Set> ambiguousConstructors = null; - LinkedList causes = null; + Deque causes = null; for (Constructor candidate : candidates) { int parameterCount = candidate.getParameterCount(); @@ -233,7 +234,7 @@ class ConstructorResolver { } // Swallow and try next constructor. if (causes == null) { - causes = new LinkedList<>(); + causes = new ArrayDeque<>(1); } causes.add(ex); continue; @@ -511,7 +512,7 @@ class ConstructorResolver { } } - LinkedList causes = null; + Deque causes = null; for (Method candidate : candidates) { int parameterCount = candidate.getParameterCount(); @@ -544,7 +545,7 @@ class ConstructorResolver { } // Swallow and try next overloaded factory method. if (causes == null) { - causes = new LinkedList<>(); + causes = new ArrayDeque<>(1); } causes.add(ex); continue; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index c94ce671762..ea8c3495c54 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.beans.factory.support; import java.lang.reflect.Method; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.lang.Nullable; @@ -39,7 +39,7 @@ public class ReplaceOverride extends MethodOverride { private final String methodReplacerBeanName; - private List typeIdentifiers = new LinkedList<>(); + private final List typeIdentifiers = new ArrayList<>(); /** @@ -70,6 +70,7 @@ public class ReplaceOverride extends MethodOverride { this.typeIdentifiers.add(identifier); } + @Override public boolean matches(Method method) { if (!method.getName().equals(getMethodName())) { diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/CollectingReaderEventListener.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/CollectingReaderEventListener.java index a4684998a36..cd213a406db 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/CollectingReaderEventListener.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/CollectingReaderEventListener.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -36,13 +35,13 @@ import org.springframework.beans.factory.parsing.ReaderEventListener; */ public class CollectingReaderEventListener implements ReaderEventListener { - private final List defaults = new LinkedList<>(); + private final List defaults = new ArrayList<>(); private final Map componentDefinitions = new LinkedHashMap<>(8); private final Map> aliasMap = new LinkedHashMap<>(8); - private final List imports = new LinkedList<>(); + private final List imports = new ArrayList<>(); @Override diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index 6e9529b2b55..ed54d0d05f4 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -77,7 +76,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt private Float myFloat = Float.valueOf(0.0f); - private Collection friends = new LinkedList<>(); + private Collection friends = new ArrayList<>(); private Set someSet = new HashSet<>(); diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java index 485ad6c8af1..1d6db6c820f 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.scheduling.commonj; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.naming.NamingException; @@ -62,7 +62,8 @@ public class TimerManagerFactoryBean extends TimerManagerAccessor @Nullable private ScheduledTimerListener[] scheduledTimerListeners; - private final List timers = new LinkedList<>(); + @Nullable + private List timers; /** @@ -87,6 +88,7 @@ public class TimerManagerFactoryBean extends TimerManagerAccessor super.afterPropertiesSet(); if (this.scheduledTimerListeners != null) { + this.timers = new ArrayList<>(this.scheduledTimerListeners.length); TimerManager timerManager = obtainTimerManager(); for (ScheduledTimerListener scheduledTask : this.scheduledTimerListeners) { Timer timer; @@ -144,15 +146,17 @@ public class TimerManagerFactoryBean extends TimerManagerAccessor @Override public void destroy() { // Cancel all registered timers. - for (Timer timer : this.timers) { - try { - timer.cancel(); - } - catch (Throwable ex) { - logger.debug("Could not cancel CommonJ Timer", ex); + if (this.timers != null) { + for (Timer timer : this.timers) { + try { + timer.cancel(); + } + catch (Throwable ex) { + logger.debug("Could not cancel CommonJ Timer", ex); + } } + this.timers.clear(); } - this.timers.clear(); // Stop the TimerManager itself. super.destroy(); diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java index 434cd49a3b1..de60cbb9ca5 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,6 @@ package org.springframework.scheduling.quartz; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -228,7 +227,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { } else { // Create empty list for easier checks when registering triggers. - this.jobDetails = new LinkedList<>(); + this.jobDetails = new ArrayList<>(); } // Register Calendars. diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index b7db35e0aee..92c39cd0292 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -21,7 +21,6 @@ import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -403,7 +402,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker Cache.ValueWrapper cacheHit = findCachedItem(contexts.get(CacheableOperation.class)); // Collect puts from any @Cacheable miss, if no cached item is found - List cachePutRequests = new LinkedList<>(); + List cachePutRequests = new ArrayList<>(); if (cacheHit == null) { collectPutRequests(contexts.get(CacheableOperation.class), CacheOperationExpressionEvaluator.NO_RESULT, cachePutRequests); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java index 765b5caf77d..05ea7a5159a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java @@ -18,9 +18,9 @@ package org.springframework.context.annotation; import java.io.IOException; import java.lang.annotation.Annotation; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -93,9 +93,9 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC private String resourcePattern = DEFAULT_RESOURCE_PATTERN; - private final List includeFilters = new LinkedList<>(); + private final List includeFilters = new ArrayList<>(); - private final List excludeFilters = new LinkedList<>(); + private final List excludeFilters = new ArrayList<>(); @Nullable private Environment environment; diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java index 49869101d2c..0512d51de34 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -21,9 +21,9 @@ import java.io.InputStream; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -55,7 +55,7 @@ public class ShadowingClassLoader extends DecoratingClassLoader { private final ClassLoader enclosingClassLoader; - private final List classFileTransformers = new LinkedList<>(); + private final List classFileTransformers = new ArrayList<>(1); private final Map> classCache = new HashMap<>(); diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java index eb8b3104685..b8857b15b50 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java @@ -18,11 +18,11 @@ package org.springframework.validation; import java.beans.PropertyEditor; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -50,7 +50,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi private MessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); - private final List errors = new LinkedList<>(); + private final List errors = new ArrayList<>(); private final Map> fieldTypes = new HashMap<>(); @@ -145,7 +145,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi @Override public List getGlobalErrors() { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (ObjectError objectError : this.errors) { if (!(objectError instanceof FieldError)) { result.add(objectError); @@ -167,7 +167,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi @Override public List getFieldErrors() { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (ObjectError objectError : this.errors) { if (objectError instanceof FieldError) { result.add((FieldError) objectError); @@ -189,7 +189,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi @Override public List getFieldErrors(String field) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); String fixedField = fixedField(field); for (ObjectError objectError : this.errors) { if (objectError instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) objectError)) { diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java index 355f0872621..9556dc3a286 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,9 +18,9 @@ package org.springframework.validation; import java.io.Serializable; import java.util.ArrayDeque; +import java.util.ArrayList; import java.util.Collections; import java.util.Deque; -import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; @@ -146,7 +146,7 @@ public abstract class AbstractErrors implements Errors, Serializable { @Override public List getAllErrors() { - List result = new LinkedList<>(); + List result = new ArrayList<>(); result.addAll(getGlobalErrors()); result.addAll(getFieldErrors()); return Collections.unmodifiableList(result); @@ -199,7 +199,7 @@ public abstract class AbstractErrors implements Errors, Serializable { @Override public List getFieldErrors(String field) { List fieldErrors = getFieldErrors(); - List result = new LinkedList<>(); + List result = new ArrayList<>(); String fixedField = fixedField(field); for (FieldError error : fieldErrors) { if (isMatchingFieldError(fixedField, error)) { diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/SimpleMapScope.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/SimpleMapScope.java index 9365c2b319b..3b29b783bfd 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/SimpleMapScope.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/SimpleMapScope.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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,9 +17,9 @@ package org.springframework.context.testfixture; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -34,7 +34,7 @@ public class SimpleMapScope implements Scope, Serializable { private final Map map = new HashMap<>(); - private final List callbacks = new LinkedList<>(); + private final List callbacks = new ArrayList<>(); public SimpleMapScope() { diff --git a/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java index cef91dfc61c..8701e36354e 100644 --- a/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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.Constructor; import java.lang.reflect.Method; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.lang.Nullable; @@ -36,7 +36,7 @@ import org.springframework.lang.Nullable; */ public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscoverer { - private final List parameterNameDiscoverers = new LinkedList<>(); + private final List parameterNameDiscoverers = new ArrayList<>(2); /** diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index e8263d9526c..b48bff2f520 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -17,12 +17,13 @@ package org.springframework.core.convert.support; import java.lang.reflect.Array; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; +import java.util.Deque; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -651,7 +652,7 @@ public class GenericConversionService implements ConfigurableConversionService { */ private static class ConvertersForPair { - private final LinkedList converters = new LinkedList<>(); + private final Deque converters = new ArrayDeque<>(1); public void add(GenericConverter converter) { this.converters.addFirst(converter); diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index fe8cd7d58ef..e1e06b4719d 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -16,9 +16,9 @@ package org.springframework.util; +import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -655,7 +655,7 @@ public class AntPathMatcher implements PathMatcher { @Nullable private final Pattern pattern; - private final List variableNames = new LinkedList<>(); + private final List variableNames = new ArrayList<>(); public AntPathStringMatcher(String pattern) { this(pattern, true); diff --git a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java index f8e484fae71..eeeca3ceeff 100644 --- a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java +++ b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -20,8 +20,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.security.MessageDigest; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Iterator; -import java.util.LinkedList; import org.springframework.lang.Nullable; @@ -50,7 +51,7 @@ public class FastByteArrayOutputStream extends OutputStream { // The buffers used to store the content bytes - private final LinkedList buffers = new LinkedList<>(); + private final Deque buffers = new ArrayDeque<>(); // The size, in bytes, to use when allocating the first byte[] private final int initialBlockSize; diff --git a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java index cf0742ff6cb..11c7970b33d 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java @@ -17,14 +17,14 @@ package org.springframework.util; import java.io.Serializable; +import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; /** * Simple implementation of {@link MultiValueMap} that wraps a {@link LinkedHashMap}, - * storing multiple values in a {@link LinkedList}. + * storing multiple values in an {@link ArrayList}. * *

This Map implementation is generally not thread-safe. It is primarily designed * for data structures exposed from request objects, for use in a single thread only. @@ -75,7 +75,7 @@ public class LinkedMultiValueMap extends MultiValueMapAdapter implem /** * Create a deep copy of this Map. * @return a copy of this Map, including a copy of each value-holding List entry - * (consistently using an independent modifiable {@link LinkedList} for each entry) + * (consistently using an independent modifiable {@link ArrayList} for each entry) * along the lines of {@code MultiValueMap.addAll} semantics * @since 4.2 * @see #addAll(MultiValueMap) @@ -83,7 +83,7 @@ public class LinkedMultiValueMap extends MultiValueMapAdapter implem */ public LinkedMultiValueMap deepCopy() { LinkedMultiValueMap copy = new LinkedMultiValueMap<>(size()); - forEach((key, values) -> copy.put(key, new LinkedList<>(values))); + forEach((key, values) -> copy.put(key, new ArrayList<>(values))); return copy; } diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java index 88611dbe27b..c5f0ab33b08 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java @@ -17,8 +17,8 @@ package org.springframework.util; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -56,13 +56,13 @@ class MultiValueMapAdapter implements MultiValueMap, Serializable { @Override public void add(K key, @Nullable V value) { - List values = this.targetMap.computeIfAbsent(key, k -> new LinkedList<>()); + List values = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(1)); values.add(value); } @Override public void addAll(K key, List values) { - List currentValues = this.targetMap.computeIfAbsent(key, k -> new LinkedList<>()); + List currentValues = this.targetMap.computeIfAbsent(key, k -> new ArrayList<>(1)); currentValues.addAll(values); } @@ -75,7 +75,7 @@ class MultiValueMapAdapter implements MultiValueMap, Serializable { @Override public void set(K key, @Nullable V value) { - List values = new LinkedList<>(); + List values = new ArrayList<>(1); values.add(value); this.targetMap.put(key, values); } diff --git a/spring-core/src/main/java/org/springframework/util/StopWatch.java b/spring-core/src/main/java/org/springframework/util/StopWatch.java index 2828919bcb7..8076ed042d1 100644 --- a/spring-core/src/main/java/org/springframework/util/StopWatch.java +++ b/spring-core/src/main/java/org/springframework/util/StopWatch.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.util; import java.text.NumberFormat; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -55,7 +55,7 @@ public class StopWatch { private boolean keepTaskList = true; - private final List taskList = new LinkedList<>(); + private final List taskList = new ArrayList<>(1); /** Start time of the current task. */ private long startTimeNanos; diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 123c71d5e2f..7867cda6713 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -18,14 +18,15 @@ package org.springframework.util; import java.io.ByteArrayOutputStream; import java.nio.charset.Charset; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.Enumeration; import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Properties; @@ -693,7 +694,7 @@ public abstract class StringUtils { } String[] pathArray = delimitedListToStringArray(pathToUse, FOLDER_SEPARATOR); - LinkedList pathElements = new LinkedList<>(); + Deque pathElements = new ArrayDeque<>(); int tops = 0; for (int i = pathArray.length - 1; i >= 0; i--) { @@ -712,7 +713,7 @@ public abstract class StringUtils { } else { // Normal path element found. - pathElements.add(0, element); + pathElements.addFirst(element); } } } @@ -723,11 +724,11 @@ public abstract class StringUtils { } // Remaining top paths need to be retained. for (int i = 0; i < tops; i++) { - pathElements.add(0, TOP_PATH); + pathElements.addFirst(TOP_PATH); } // If nothing else left, at least explicitly point to current path. if (pathElements.size() == 1 && pathElements.getLast().isEmpty() && !prefix.endsWith(FOLDER_SEPARATOR)) { - pathElements.add(0, CURRENT_PATH); + pathElements.addFirst(CURRENT_PATH); } return prefix + collectionToDelimitedString(pathElements, FOLDER_SEPARATOR); diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java index 6a783ff8bd3..d3be92bbcd5 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.util.concurrent; -import java.util.LinkedList; +import java.util.ArrayDeque; import java.util.Queue; import org.springframework.lang.Nullable; @@ -36,9 +36,9 @@ import org.springframework.util.Assert; */ public class ListenableFutureCallbackRegistry { - private final Queue> successCallbacks = new LinkedList<>(); + private final Queue> successCallbacks = new ArrayDeque<>(1); - private final Queue failureCallbacks = new LinkedList<>(); + private final Queue failureCallbacks = new ArrayDeque<>(1); private State state = State.NEW; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java index 15e5fdd4da8..dafb615271e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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.expression.spel.support; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import org.springframework.expression.EvaluationException; @@ -41,7 +41,7 @@ public class StandardTypeLocator implements TypeLocator { @Nullable private final ClassLoader classLoader; - private final List knownPackagePrefixes = new LinkedList<>(); + private final List knownPackagePrefixes = new ArrayList<>(1); /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java index bd3cbd5215b..69e88ae0f79 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -20,8 +20,8 @@ import java.sql.CallableStatement; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -57,7 +57,7 @@ public class CallableStatementCreatorFactory { */ public CallableStatementCreatorFactory(String callString) { this.callString = callString; - this.declaredParameters = new LinkedList<>(); + this.declaredParameters = new ArrayList<>(); } /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java index c7aab55d29e..f07ee04cd0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -21,10 +21,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -66,7 +66,7 @@ public class PreparedStatementCreatorFactory { */ public PreparedStatementCreatorFactory(String sql) { this.sql = sql; - this.declaredParameters = new LinkedList<>(); + this.declaredParameters = new ArrayList<>(); } /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java index bad3d20f7e2..339611df684 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,6 @@ package org.springframework.jdbc.core; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import org.springframework.lang.Nullable; @@ -186,7 +185,7 @@ public class SqlParameter { */ public static List sqlTypesToAnonymousParameterList(@Nullable int... types) { if (types == null) { - return new LinkedList<>(); + return new ArrayList<>(); } List result = new ArrayList<>(types.length); for (int type : types) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java index 67c4ca6e011..c3db79762a5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/RdbmsOperation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,9 +18,9 @@ package org.springframework.jdbc.object; import java.sql.ResultSet; import java.sql.Types; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -79,7 +79,7 @@ public abstract class RdbmsOperation implements InitializingBean { @Nullable private String sql; - private final List declaredParameters = new LinkedList<>(); + private final List declaredParameters = new ArrayList<>(); /** * Has this operation been compiled? Compilation means at diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java index 4da866456bb..d1c26195edb 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java @@ -16,8 +16,8 @@ package org.springframework.jdbc.support; +import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -47,7 +47,7 @@ public class GeneratedKeyHolder implements KeyHolder { * Create a new GeneratedKeyHolder with a default list. */ public GeneratedKeyHolder() { - this.keyList = new LinkedList<>(); + this.keyList = new ArrayList<>(1); } /** diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index 2f876fb2496..22d827b38f5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -20,10 +20,11 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -94,7 +95,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { private volatile boolean active = true; - private final ConcurrentMap> cachedSessions = new ConcurrentHashMap<>(); + private final ConcurrentMap> cachedSessions = new ConcurrentHashMap<>(); /** @@ -186,7 +187,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { this.active = false; synchronized (this.cachedSessions) { - for (LinkedList sessionList : this.cachedSessions.values()) { + for (Deque sessionList : this.cachedSessions.values()) { synchronized (sessionList) { for (Session session : sessionList) { try { @@ -216,7 +217,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { return null; } - LinkedList sessionList = this.cachedSessions.computeIfAbsent(mode, k -> new LinkedList<>()); + Deque sessionList = this.cachedSessions.computeIfAbsent(mode, k -> new ArrayDeque<>()); Session session = null; synchronized (sessionList) { if (!sessionList.isEmpty()) { @@ -247,7 +248,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { * @param sessionList the List of cached Sessions that the given Session belongs to * @return the wrapped Session */ - protected Session getCachedSessionProxy(Session target, LinkedList sessionList) { + protected Session getCachedSessionProxy(Session target, Deque sessionList) { List> classes = new ArrayList<>(3); classes.add(SessionProxy.class); if (target instanceof QueueSession) { @@ -268,7 +269,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { private final Session target; - private final LinkedList sessionList; + private final Deque sessionList; private final Map cachedProducers = new HashMap<>(); @@ -276,7 +277,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { private boolean transactionOpen = false; - public CachedSessionInvocationHandler(Session target, LinkedList sessionList) { + public CachedSessionInvocationHandler(Session target, Deque sessionList) { this.target = target; this.sessionList = sessionList; } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java index 6bf7b80641f..a8e9c86dbe1 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/JmsResourceHolder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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,8 +17,9 @@ package org.springframework.jms.connection; import java.lang.reflect.Method; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.HashMap; -import java.util.LinkedList; import java.util.Map; import javax.jms.Connection; @@ -58,11 +59,11 @@ public class JmsResourceHolder extends ResourceHolderSupport { private boolean frozen = false; - private final LinkedList connections = new LinkedList<>(); + private final Deque connections = new ArrayDeque<>(); - private final LinkedList sessions = new LinkedList<>(); + private final Deque sessions = new ArrayDeque<>(); - private final Map> sessionsPerConnection = new HashMap<>(); + private final Map> sessionsPerConnection = new HashMap<>(); /** @@ -155,8 +156,8 @@ public class JmsResourceHolder extends ResourceHolderSupport { if (!this.sessions.contains(session)) { this.sessions.add(session); if (connection != null) { - LinkedList sessions = - this.sessionsPerConnection.computeIfAbsent(connection, k -> new LinkedList<>()); + Deque sessions = + this.sessionsPerConnection.computeIfAbsent(connection, k -> new ArrayDeque<>()); sessions.add(session); } } @@ -223,7 +224,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { */ @Nullable public S getSession(Class sessionType, @Nullable Connection connection) { - LinkedList sessions = + Deque sessions = (connection != null ? this.sessionsPerConnection.get(connection) : this.sessions); return CollectionUtils.findValueOfType(sessions, sessionType); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java index d4a06ac4a26..b7e1734bb99 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/AbstractJmsListeningContainer.java @@ -16,8 +16,8 @@ package org.springframework.jms.listener; +import java.util.ArrayList; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import javax.jms.Connection; @@ -83,7 +83,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess private volatile boolean running; - private final List pausedTasks = new LinkedList<>(); + private final List pausedTasks = new ArrayList<>(); protected final Object lifecycleMonitor = new Object(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java index 937befe33e6..7bde7fb3d37 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.messaging.handler.invocation; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -37,7 +37,7 @@ import org.springframework.messaging.Message; */ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver { - private final List argumentResolvers = new LinkedList<>(); + private final List argumentResolvers = new ArrayList<>(); private final Map argumentResolverCache = new ConcurrentHashMap<>(256); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java index 6822b29f634..3009a05e561 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.messaging.handler.invocation.reactive; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -42,7 +42,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu protected final Log logger = LogFactory.getLog(getClass()); - private final List argumentResolvers = new LinkedList<>(); + private final List argumentResolvers = new ArrayList<>(); private final Map argumentResolverCache = new ConcurrentHashMap<>(256); @@ -113,9 +113,8 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu public Mono resolveArgument(MethodParameter parameter, Message message) { HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); if (resolver == null) { - throw new IllegalArgumentException( - "Unsupported parameter type [" + parameter.getParameterType().getName() + "]." + - " supportsParameter should be called first."); + throw new IllegalArgumentException("Unsupported parameter type [" + + parameter.getParameterType().getName() + "]. supportsParameter should be called first."); } return resolver.resolveArgument(parameter, message); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java index a9c163ac691..175043f586d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java @@ -17,9 +17,9 @@ package org.springframework.messaging.simp.stomp; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -228,15 +228,14 @@ public class StompEncoder { void add(byte b); byte[] toByteArray(); - } + @SuppressWarnings("serial") - private static class DefaultResult extends LinkedList implements Result { + private static class DefaultResult extends ArrayList implements Result { private int size; - public void add(byte[] bytes) { this.size += bytes.length; super.add(bytes); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java index 2e84545a3dc..ea38f8f85f5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java @@ -17,11 +17,11 @@ package org.springframework.messaging.simp.stomp; import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -446,13 +446,13 @@ public class StompHeaders implements MultiValueMap, Serializable */ @Override public void add(String headerName, @Nullable String headerValue) { - List headerValues = this.headers.computeIfAbsent(headerName, k -> new LinkedList<>()); + List headerValues = this.headers.computeIfAbsent(headerName, k -> new ArrayList<>(1)); headerValues.add(headerValue); } @Override public void addAll(String headerName, List headerValues) { - List currentValues = this.headers.computeIfAbsent(headerName, k -> new LinkedList<>()); + List currentValues = this.headers.computeIfAbsent(headerName, k -> new ArrayList<>(1)); currentValues.addAll(headerValues); } @@ -471,7 +471,7 @@ public class StompHeaders implements MultiValueMap, Serializable */ @Override public void set(String headerName, @Nullable String headerValue) { - List headerValues = new LinkedList<>(); + List headerValues = new ArrayList<>(1); headerValues.add(headerValue); this.headers.put(headerName, headerValues); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java index 4243f78c5e9..6d0b0eda780 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.messaging.support; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -166,7 +166,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { map = new LinkedMultiValueMap<>(3); setHeader(NATIVE_HEADERS, map); } - List values = new LinkedList<>(); + List values = new ArrayList<>(1); values.add(value); if (!ObjectUtils.nullSafeEquals(values, getHeader(name))) { setModified(true); @@ -187,7 +187,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { nativeHeaders = new LinkedMultiValueMap<>(3); setHeader(NATIVE_HEADERS, nativeHeaders); } - List values = nativeHeaders.computeIfAbsent(name, k -> new LinkedList<>()); + List values = nativeHeaders.computeIfAbsent(name, k -> new ArrayList<>(1)); values.add(value); setModified(true); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java index c7ce1c16251..8e2fd410d54 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,10 +18,10 @@ package org.springframework.orm.jpa.persistenceunit; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -498,7 +498,7 @@ public class DefaultPersistenceUnitManager * as defined in the JPA specification. */ private List readPersistenceUnitInfos() { - List infos = new LinkedList<>(); + List infos = new ArrayList<>(1); String defaultName = this.defaultPersistenceUnitName; boolean buildDefaultUnit = (this.packagesToScan != null || this.mappingResources != null); boolean foundDefaultUnit = false; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java index c4c2b1938e5..b006f76bfaf 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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.orm.jpa.persistenceunit; import java.net.URL; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -61,16 +61,16 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { @Nullable private DataSource jtaDataSource; - private final List mappingFileNames = new LinkedList<>(); + private final List mappingFileNames = new ArrayList<>(); - private List jarFileUrls = new LinkedList<>(); + private final List jarFileUrls = new ArrayList<>(); @Nullable private URL persistenceUnitRootUrl; - private final List managedClassNames = new LinkedList<>(); + private final List managedClassNames = new ArrayList<>(); - private final List managedPackages = new LinkedList<>(); + private final List managedPackages = new ArrayList<>(); private boolean excludeUnlistedClasses = false; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java index 5a7083ab452..092285cd25f 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java @@ -19,7 +19,7 @@ package org.springframework.orm.jpa.persistenceunit; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.persistence.SharedCacheMode; @@ -123,7 +123,7 @@ final class PersistenceUnitReader { */ public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) { ErrorHandler handler = new SimpleSaxErrorHandler(logger); - List infos = new LinkedList<>(); + List infos = new ArrayList<>(1); String resourceLocation = null; try { for (String location : persistenceXmlLocations) { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java index 1406ebfad60..d9ff7afc141 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java @@ -24,7 +24,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -403,7 +402,7 @@ public class PersistenceAnnotationBeanPostProcessor Class targetClass = clazz; do { - final LinkedList currElements = new LinkedList<>(); + final List currElements = new ArrayList<>(); ReflectionUtils.doWithLocalFields(targetClass, field -> { if (field.isAnnotationPresent(PersistenceContext.class) || diff --git a/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java b/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java index 23de6e133b1..ad477ed7440 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/AbstractRequestExpectationManager.java @@ -18,11 +18,11 @@ package org.springframework.test.web.client; import java.io.IOException; import java.net.URI; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashMap; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -48,9 +48,9 @@ import org.springframework.util.Assert; */ public abstract class AbstractRequestExpectationManager implements RequestExpectationManager { - private final List expectations = new LinkedList<>(); + private final List expectations = new ArrayList<>(); - private final List requests = new LinkedList<>(); + private final List requests = new ArrayList<>(); private final Map requestFailures = new LinkedHashMap<>(); @@ -81,7 +81,7 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect @SuppressWarnings("deprecation") @Override public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOException { - RequestExpectation expectation = null; + RequestExpectation expectation; synchronized (this.requests) { if (this.requests.isEmpty()) { afterExpectationsDeclared(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java b/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java index c6e4b58f4e8..d1fc550fa17 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.client; import java.io.IOException; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.springframework.http.client.ClientHttpRequest; @@ -36,7 +36,7 @@ public class DefaultRequestExpectation implements RequestExpectation { private final RequestCount requestCount; - private final List requestMatchers = new LinkedList<>(); + private final List requestMatchers = new ArrayList<>(1); @Nullable private ResponseCreator responseCreator; diff --git a/spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java b/spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java index 171b6261090..e81b294baac 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java @@ -16,7 +16,7 @@ package org.springframework.transaction.config; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; @@ -122,14 +122,14 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE))); } - List rollbackRules = new LinkedList<>(); + List rollbackRules = new ArrayList<>(1); if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) { String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE); - addRollbackRuleAttributesTo(rollbackRules,rollbackForValue); + addRollbackRuleAttributesTo(rollbackRules, rollbackForValue); } if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) { String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE); - addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue); + addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue); } attribute.setRollbackRules(rollbackRules); diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java index a6e5d04882b..ecb231abec5 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,6 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import org.apache.commons.logging.Log; @@ -116,7 +115,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i */ public List getRollbackRules() { if (this.rollbackRules == null) { - this.rollbackRules = new LinkedList<>(); + this.rollbackRules = new ArrayList<>(); } return this.rollbackRules; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java index 5ac8b724570..39aa9149faa 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartGenerator.java @@ -23,8 +23,8 @@ import java.nio.channels.WritableByteChannel; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; @@ -479,7 +479,7 @@ final class PartGenerator extends BaseSubscriber { } private void switchToFile(DataBuffer current, long byteCount) { - List content = new LinkedList<>(this.content); + List content = new ArrayList<>(this.content); content.add(current); this.releaseOnDispose = false; diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index cfbde4fbf17..586bbf7db4a 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -21,7 +21,6 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -557,7 +556,7 @@ public class Jackson2ObjectMapperBuilder { * @see com.fasterxml.jackson.databind.Module */ public Jackson2ObjectMapperBuilder modules(List modules) { - this.modules = new LinkedList<>(modules); + this.modules = new ArrayList<>(modules); this.findModulesViaServiceLoader = false; this.findWellKnownModules = false; return this; diff --git a/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java index 1d76e991a57..0e61da306db 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,9 +16,9 @@ package org.springframework.web; +import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -117,7 +117,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException { if (this.supportedMethods == null) { return null; } - List supportedMethods = new LinkedList<>(); + List supportedMethods = new ArrayList<>(this.supportedMethods.length); for (String value : this.supportedMethods) { HttpMethod resolved = HttpMethod.resolve(value); if (resolved != null) { diff --git a/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java b/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java index ee3b4509e31..da3cd91c3d8 100644 --- a/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java +++ b/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,8 @@ package org.springframework.web; import java.lang.reflect.Modifier; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.ServiceLoader; import java.util.Set; @@ -142,9 +143,10 @@ public class SpringServletContainerInitializer implements ServletContainerInitia public void onStartup(@Nullable Set> webAppInitializerClasses, ServletContext servletContext) throws ServletException { - List initializers = new LinkedList<>(); + List initializers = Collections.emptyList(); if (webAppInitializerClasses != null) { + initializers = new ArrayList<>(webAppInitializerClasses.size()); for (Class waiClass : webAppInitializerClasses) { // Be defensive: Some servlet containers provide us with invalid classes, // no matter what @HandlesTypes says... diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 0071fabd384..3170f800e5d 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -21,7 +21,6 @@ import java.lang.reflect.Type; import java.net.URI; import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -949,7 +948,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat HttpHeaders httpHeaders = httpRequest.getHeaders(); HttpHeaders requestHeaders = this.requestEntity.getHeaders(); if (!requestHeaders.isEmpty()) { - requestHeaders.forEach((key, values) -> httpHeaders.put(key, new LinkedList<>(values))); + requestHeaders.forEach((key, values) -> httpHeaders.put(key, new ArrayList<>(values))); } if (httpHeaders.getContentLength() < 0) { httpHeaders.setContentLength(0L); @@ -968,7 +967,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat (GenericHttpMessageConverter) messageConverter; if (genericConverter.canWrite(requestBodyType, requestBodyClass, requestContentType)) { if (!requestHeaders.isEmpty()) { - requestHeaders.forEach((key, values) -> httpHeaders.put(key, new LinkedList<>(values))); + requestHeaders.forEach((key, values) -> httpHeaders.put(key, new ArrayList<>(values))); } logBody(requestBody, requestContentType, genericConverter); genericConverter.write(requestBody, requestBodyType, requestContentType, httpRequest); @@ -977,7 +976,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } else if (messageConverter.canWrite(requestBodyClass, requestContentType)) { if (!requestHeaders.isEmpty()) { - requestHeaders.forEach((key, values) -> httpHeaders.put(key, new LinkedList<>(values))); + requestHeaders.forEach((key, values) -> httpHeaders.put(key, new ArrayList<>(values))); } logBody(requestBody, requestContentType, messageConverter); ((HttpMessageConverter) messageConverter).write( diff --git a/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java b/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java index e47ef428b3f..18a3726920c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/CompositeUriComponentsContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,9 +16,10 @@ package org.springframework.web.method.support; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -34,11 +35,12 @@ import org.springframework.web.util.UriComponentsBuilder; * use for formatting method argument values to Strings. * * @author Rossen Stoyanchev + * @author Juergen Hoeller * @since 4.0 */ public class CompositeUriComponentsContributor implements UriComponentsContributor { - private final List contributors = new LinkedList<>(); + private final List contributors; private final ConversionService conversionService; @@ -53,7 +55,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut * or {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}. */ public CompositeUriComponentsContributor(UriComponentsContributor... contributors) { - Collections.addAll(this.contributors, contributors); + this.contributors = Arrays.asList((Object[]) contributors); this.conversionService = new DefaultFormattingConversionService(); } @@ -85,9 +87,7 @@ public class CompositeUriComponentsContributor implements UriComponentsContribut * need to be formatted as Strings before being added to the URI */ public CompositeUriComponentsContributor(@Nullable Collection contributors, @Nullable ConversionService cs) { - if (contributors != null) { - this.contributors.addAll(contributors); - } + this.contributors = (contributors != null ? new ArrayList<>(contributors) : Collections.emptyList()); this.conversionService = (cs != null ? cs : new DefaultFormattingConversionService()); } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java index 2b1cba3b050..60a27b9ae5b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.web.method.support; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -38,7 +38,7 @@ import org.springframework.web.context.request.NativeWebRequest; */ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver { - private final List argumentResolvers = new LinkedList<>(); + private final List argumentResolvers = new ArrayList<>(); private final Map argumentResolverCache = new ConcurrentHashMap<>(256); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletPartUtils.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletPartUtils.java index b0e7c5e26fe..6a9da0981c5 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletPartUtils.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StandardServletPartUtils.java @@ -16,7 +16,7 @@ package org.springframework.web.multipart.support; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -65,7 +65,7 @@ public abstract class StandardServletPartUtils { */ public static List getParts(HttpServletRequest request, String name) throws MultipartException { try { - List parts = new LinkedList<>(); + List parts = new ArrayList<>(1); for (Part part : request.getParts()) { if (part.getName().equals(name)) { parts.add(part); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 6ed5f225846..cf93e43567d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -20,10 +20,11 @@ import java.net.InetSocketAddress; import java.net.URI; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; +import java.util.Deque; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.regex.Matcher; @@ -908,7 +909,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private static class CompositePathComponentBuilder implements PathComponentBuilder { - private final LinkedList builders = new LinkedList<>(); + private final Deque builders = new ArrayDeque<>(); public void addPathSegments(String... pathSegments) { if (!ObjectUtils.isEmpty(pathSegments)) { @@ -1024,7 +1025,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private static class PathSegmentComponentBuilder implements PathComponentBuilder { - private final List pathSegments = new LinkedList<>(); + private final List pathSegments = new ArrayList<>(); public void append(String... pathSegments) { for (String pathSegment : pathSegments) { diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java index dd55d5c39c4..f326a87e134 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java @@ -16,7 +16,7 @@ package org.springframework.web.util.pattern; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,7 +40,7 @@ class RegexPathElement extends PathElement { private static final String DEFAULT_VARIABLE_PATTERN = "(.*)"; - private char[] regex; + private final char[] regex; private final boolean caseSensitive; @@ -48,7 +48,7 @@ class RegexPathElement extends PathElement { private int wildcardCount; - private final List variableNames = new LinkedList<>(); + private final List variableNames = new ArrayList<>(); RegexPathElement(int pos, char[] regex, boolean caseSensitive, char[] completePattern, char separator) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java index 5af5d2679d7..1161c1c8e4a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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.web.reactive.result.method; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -43,7 +43,7 @@ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentRes protected final Log logger = LogFactory.getLog(getClass()); - private final List argumentResolvers = new LinkedList<>(); + private final List argumentResolvers = new ArrayList<>(); private final Map argumentResolverCache = new ConcurrentHashMap<>(256); @@ -116,9 +116,8 @@ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentRes HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); if (resolver == null) { - throw new IllegalArgumentException( - "Unsupported parameter type [" + parameter.getParameterType().getName() + "]." + - " supportsParameter should be called first."); + throw new IllegalArgumentException("Unsupported parameter type [" + + parameter.getParameterType().getName() + "]. supportsParameter should be called first."); } return resolver.resolveArgument(parameter, bindingContext, exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index c419fb491ed..95d6357717d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -86,7 +86,7 @@ public class InvocableHandlerMethod extends HandlerMethod { * Configure the argument resolvers to use to use for resolving method * argument values against a {@code ServerWebExchange}. */ - public void setArgumentResolvers(List resolvers) { + public void setArgumentResolvers(List resolvers) { this.resolvers.addResolvers(resolvers); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java index 26a9e0cb64c..b43bf7149ae 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,6 @@ package org.springframework.web.reactive.result.method; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -62,7 +61,7 @@ public class SyncInvocableHandlerMethod extends HandlerMethod { * argument values against a {@code ServerWebExchange}. */ public void setArgumentResolvers(List resolvers) { - this.delegate.setArgumentResolvers(new ArrayList<>(resolvers)); + this.delegate.setArgumentResolvers(resolvers); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 3a11cf8c78e..bc7fc189e6c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -897,7 +896,7 @@ public class DispatcherServlet extends FrameworkServlet { return strategies; } else { - return new LinkedList<>(); + return Collections.emptyList(); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java index a0f154d7905..d740a3c2cc6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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.web.servlet.support; +import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; @@ -127,7 +127,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { * Return a list of expired FlashMap instances contained in the given list. */ private List getExpiredFlashMaps(List allMaps) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (FlashMap map : allMaps) { if (map.isExpired()) { result.add(map); @@ -142,7 +142,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { */ @Nullable private FlashMap getMatchingFlashMap(List allMaps, HttpServletRequest request) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (FlashMap flashMap : allMaps) { if (isFlashMapForRequest(flashMap, request)) { result.add(flashMap); @@ -213,7 +213,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { } else { List allFlashMaps = retrieveFlashMaps(request); - allFlashMaps = (allFlashMaps != null ? allFlashMaps : new LinkedList<>()); + allFlashMaps = (allFlashMaps != null ? allFlashMaps : new ArrayList<>(1)); allFlashMaps.add(flashMap); updateFlashMaps(allFlashMaps, request, response); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java index 5ea3668ae17..b1bac467d7c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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,9 +17,9 @@ package org.springframework.web.servlet.tags; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import javax.servlet.jsp.JspException; @@ -255,7 +255,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { @Override protected final int doStartTagInternal() throws JspException, IOException { - this.nestedArguments = new LinkedList<>(); + this.nestedArguments = new ArrayList<>(); return EVAL_BODY_INCLUDE; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index 219b554cb78..08c64a25901 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -18,9 +18,9 @@ package org.springframework.web.servlet.tags; import java.io.IOException; import java.nio.charset.UnsupportedCharsetException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -229,7 +229,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { @Override public int doStartTagInternal() throws JspException { - this.params = new LinkedList<>(); + this.params = new ArrayList<>(); this.templateParams = new HashSet<>(); return EVAL_BODY_INCLUDE; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java index 040c0bfcbde..84486456eb8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/ResourceBundleViewResolver.java @@ -16,8 +16,8 @@ package org.springframework.web.servlet.view; +import java.util.ArrayList; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -230,10 +230,9 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver } // Build list of ResourceBundle references for Locale. - List bundles = new LinkedList<>(); + List bundles = new ArrayList<>(this.basenames.length); for (String basename : this.basenames) { - ResourceBundle bundle = getBundle(basename, locale); - bundles.add(bundle); + bundles.add(getBundle(basename, locale)); } // Try to find cached factory for ResourceBundle list: diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java index 41bab671ed9..dbbdf0f22e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/tiles3/TilesConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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.web.servlet.view.tiles3; +import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import javax.el.ArrayELResolver; @@ -311,7 +311,7 @@ public class TilesConfigurer implements ServletContextAware, InitializingBean, D @Override protected List getSources(ApplicationContext applicationContext) { if (definitions != null) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); for (String definition : definitions) { Collection resources = applicationContext.getResources(definition); if (resources != null) {