Replace remaining usage of LinkedList with ArrayList/ArrayDeque

Closes gh-25650
This commit is contained in:
Juergen Hoeller
2020-08-26 18:32:08 +02:00
parent d198c4426f
commit 874574513c
65 changed files with 239 additions and 239 deletions

View File

@@ -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<MultipartParser.Token> {
}
private void switchToFile(DataBuffer current, long byteCount) {
List<DataBuffer> content = new LinkedList<>(this.content);
List<DataBuffer> content = new ArrayList<>(this.content);
content.add(current);
this.releaseOnDispose = false;

View File

@@ -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<Module> modules) {
this.modules = new LinkedList<>(modules);
this.modules = new ArrayList<>(modules);
this.findModulesViaServiceLoader = false;
this.findWellKnownModules = false;
return this;

View File

@@ -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<HttpMethod> supportedMethods = new LinkedList<>();
List<HttpMethod> supportedMethods = new ArrayList<>(this.supportedMethods.length);
for (String value : this.supportedMethods) {
HttpMethod resolved = HttpMethod.resolve(value);
if (resolved != null) {

View File

@@ -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<Class<?>> webAppInitializerClasses, ServletContext servletContext)
throws ServletException {
List<WebApplicationInitializer> initializers = new LinkedList<>();
List<WebApplicationInitializer> 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...

View File

@@ -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<Object>) 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<Object>) messageConverter).write(

View File

@@ -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<Object> contributors = new LinkedList<>();
private final List<Object> 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());
}

View File

@@ -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<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
new ConcurrentHashMap<>(256);

View File

@@ -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<Part> getParts(HttpServletRequest request, String name) throws MultipartException {
try {
List<Part> parts = new LinkedList<>();
List<Part> parts = new ArrayList<>(1);
for (Part part : request.getParts()) {
if (part.getName().equals(name)) {
parts.add(part);

View File

@@ -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<PathComponentBuilder> builders = new LinkedList<>();
private final Deque<PathComponentBuilder> 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<String> pathSegments = new LinkedList<>();
private final List<String> pathSegments = new ArrayList<>();
public void append(String... pathSegments) {
for (String pathSegment : pathSegments) {

View File

@@ -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<String> variableNames = new LinkedList<>();
private final List<String> variableNames = new ArrayList<>();
RegexPathElement(int pos, char[] regex, boolean caseSensitive, char[] completePattern, char separator) {