Skip to content

Commit cf2e0c7

Browse files
committed
Selected use of ArrayList instead of LinkedList in common places
See gh-25652
1 parent 589060d commit cf2e0c7

File tree

12 files changed

+48
-51
lines changed

12 files changed

+48
-51
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
package org.springframework.beans.factory.support;
1818

1919
import java.lang.reflect.Method;
20-
import java.util.LinkedList;
20+
import java.util.ArrayList;
2121
import java.util.List;
2222

2323
import org.springframework.lang.Nullable;
@@ -39,7 +39,7 @@ public class ReplaceOverride extends MethodOverride {
3939

4040
private final String methodReplacerBeanName;
4141

42-
private List<String> typeIdentifiers = new LinkedList<>();
42+
private final List<String> typeIdentifiers = new ArrayList<>();
4343

4444

4545
/**
@@ -70,6 +70,7 @@ public void addTypeIdentifier(String identifier) {
7070
this.typeIdentifiers.add(identifier);
7171
}
7272

73+
7374
@Override
7475
public boolean matches(Method method) {
7576
if (!method.getName().equals(getMethodName())) {

spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
import java.beans.PropertyEditor;
2020
import java.io.Serializable;
21+
import java.util.ArrayList;
2122
import java.util.Collections;
2223
import java.util.HashMap;
2324
import java.util.HashSet;
2425
import java.util.LinkedHashMap;
25-
import java.util.LinkedList;
2626
import java.util.List;
2727
import java.util.Map;
2828
import java.util.Set;
@@ -50,7 +50,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
5050

5151
private MessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
5252

53-
private final List<ObjectError> errors = new LinkedList<>();
53+
private final List<ObjectError> errors = new ArrayList<>();
5454

5555
private final Map<String, Class<?>> fieldTypes = new HashMap<>();
5656

@@ -145,7 +145,7 @@ public List<ObjectError> getAllErrors() {
145145

146146
@Override
147147
public List<ObjectError> getGlobalErrors() {
148-
List<ObjectError> result = new LinkedList<>();
148+
List<ObjectError> result = new ArrayList<>();
149149
for (ObjectError objectError : this.errors) {
150150
if (!(objectError instanceof FieldError)) {
151151
result.add(objectError);
@@ -167,7 +167,7 @@ public ObjectError getGlobalError() {
167167

168168
@Override
169169
public List<FieldError> getFieldErrors() {
170-
List<FieldError> result = new LinkedList<>();
170+
List<FieldError> result = new ArrayList<>();
171171
for (ObjectError objectError : this.errors) {
172172
if (objectError instanceof FieldError) {
173173
result.add((FieldError) objectError);
@@ -189,7 +189,7 @@ public FieldError getFieldError() {
189189

190190
@Override
191191
public List<FieldError> getFieldErrors(String field) {
192-
List<FieldError> result = new LinkedList<>();
192+
List<FieldError> result = new ArrayList<>();
193193
String fixedField = fixedField(field);
194194
for (ObjectError objectError : this.errors) {
195195
if (objectError instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) objectError)) {

spring-context/src/main/java/org/springframework/validation/AbstractErrors.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@
1818

1919
import java.io.Serializable;
2020
import java.util.ArrayDeque;
21+
import java.util.ArrayList;
2122
import java.util.Collections;
2223
import java.util.Deque;
23-
import java.util.LinkedList;
2424
import java.util.List;
2525
import java.util.NoSuchElementException;
2626

@@ -146,7 +146,7 @@ public int getErrorCount() {
146146

147147
@Override
148148
public List<ObjectError> getAllErrors() {
149-
List<ObjectError> result = new LinkedList<>();
149+
List<ObjectError> result = new ArrayList<>();
150150
result.addAll(getGlobalErrors());
151151
result.addAll(getFieldErrors());
152152
return Collections.unmodifiableList(result);
@@ -199,7 +199,7 @@ public int getFieldErrorCount(String field) {
199199
@Override
200200
public List<FieldError> getFieldErrors(String field) {
201201
List<FieldError> fieldErrors = getFieldErrors();
202-
List<FieldError> result = new LinkedList<>();
202+
List<FieldError> result = new ArrayList<>();
203203
String fixedField = fixedField(field);
204204
for (FieldError error : fieldErrors) {
205205
if (isMatchingFieldError(fixedField, error)) {

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.messaging.handler.invocation;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
20-
import java.util.LinkedList;
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.concurrent.ConcurrentHashMap;
@@ -37,7 +37,7 @@
3737
*/
3838
public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver {
3939

40-
private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
40+
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
4141

4242
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
4343
new ConcurrentHashMap<>(256);

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.messaging.handler.invocation.reactive;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
20-
import java.util.LinkedList;
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.concurrent.ConcurrentHashMap;
@@ -42,7 +42,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
4242

4343
protected final Log logger = LogFactory.getLog(getClass());
4444

45-
private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
45+
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
4646

4747
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
4848
new ConcurrentHashMap<>(256);
@@ -113,9 +113,8 @@ public boolean supportsParameter(MethodParameter parameter) {
113113
public Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message) {
114114
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
115115
if (resolver == null) {
116-
throw new IllegalArgumentException(
117-
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." +
118-
" supportsParameter should be called first.");
116+
throw new IllegalArgumentException("Unsupported parameter type [" +
117+
parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
119118
}
120119
return resolver.resolveArgument(parameter, message);
121120
}

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package org.springframework.messaging.simp.stomp;
1818

1919
import java.nio.charset.StandardCharsets;
20+
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.LinkedHashMap;
22-
import java.util.LinkedList;
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Map.Entry;
@@ -228,15 +228,14 @@ private interface Result {
228228
void add(byte b);
229229

230230
byte[] toByteArray();
231-
232231
}
233232

233+
234234
@SuppressWarnings("serial")
235-
private static class DefaultResult extends LinkedList<Object> implements Result {
235+
private static class DefaultResult extends ArrayList<Object> implements Result {
236236

237237
private int size;
238238

239-
240239
public void add(byte[] bytes) {
241240
this.size += bytes.length;
242241
super.add(bytes);

spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
package org.springframework.orm.jpa.persistenceunit;
1818

1919
import java.net.URL;
20-
import java.util.LinkedList;
20+
import java.util.ArrayList;
2121
import java.util.List;
2222
import java.util.Properties;
2323

@@ -61,16 +61,16 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
6161
@Nullable
6262
private DataSource jtaDataSource;
6363

64-
private final List<String> mappingFileNames = new LinkedList<>();
64+
private final List<String> mappingFileNames = new ArrayList<>();
6565

66-
private List<URL> jarFileUrls = new LinkedList<>();
66+
private final List<URL> jarFileUrls = new ArrayList<>();
6767

6868
@Nullable
6969
private URL persistenceUnitRootUrl;
7070

71-
private final List<String> managedClassNames = new LinkedList<>();
71+
private final List<String> managedClassNames = new ArrayList<>();
7272

73-
private final List<String> managedPackages = new LinkedList<>();
73+
private final List<String> managedPackages = new ArrayList<>();
7474

7575
private boolean excludeUnlistedClasses = false;
7676

spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424
import java.lang.reflect.Modifier;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
27-
import java.util.LinkedList;
2827
import java.util.List;
2928
import java.util.Map;
3029
import java.util.Properties;
@@ -423,7 +422,7 @@ private InjectionMetadata buildPersistenceMetadata(final Class<?> clazz) {
423422
Class<?> targetClass = clazz;
424423

425424
do {
426-
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
425+
final List<InjectionMetadata.InjectedElement> currElements = new ArrayList<>();
427426

428427
ReflectionUtils.doWithLocalFields(targetClass, field -> {
429428
if (field.isAnnotationPresent(PersistenceContext.class) ||

spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.transaction.config;
1818

19-
import java.util.LinkedList;
19+
import java.util.ArrayList;
2020
import java.util.List;
2121

2222
import org.w3c.dom.Element;
@@ -127,14 +127,14 @@ private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext p
127127
attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
128128
}
129129

130-
List<RollbackRuleAttribute> rollbackRules = new LinkedList<>();
130+
List<RollbackRuleAttribute> rollbackRules = new ArrayList<>(1);
131131
if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) {
132132
String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE);
133-
addRollbackRuleAttributesTo(rollbackRules,rollbackForValue);
133+
addRollbackRuleAttributesTo(rollbackRules, rollbackForValue);
134134
}
135135
if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) {
136136
String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE);
137-
addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue);
137+
addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue);
138138
}
139139
attribute.setRollbackRules(rollbackRules);
140140

spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.web.method.support;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
20-
import java.util.LinkedList;
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.concurrent.ConcurrentHashMap;
@@ -38,7 +38,7 @@
3838
*/
3939
public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver {
4040

41-
private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
41+
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
4242

4343
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
4444
new ConcurrentHashMap<>(256);

0 commit comments

Comments
 (0)