Browse Source

Selected use of ArrayList instead of LinkedList in common places

See gh-25652
pull/25798/head
Juergen Hoeller 5 years ago
parent
commit
cf2e0c7959
  1. 7
      spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java
  2. 10
      spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java
  3. 8
      spring-context/src/main/java/org/springframework/validation/AbstractErrors.java
  4. 6
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java
  5. 11
      spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java
  6. 7
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java
  7. 12
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java
  8. 5
      spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java
  9. 10
      spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java
  10. 6
      spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java
  11. 6
      spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java
  12. 11
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -39,7 +39,7 @@ public class ReplaceOverride extends MethodOverride {
private final String methodReplacerBeanName;
private List<String> typeIdentifiers = new LinkedList<>();
private final List<String> typeIdentifiers = new ArrayList<>();
/**
@ -70,6 +70,7 @@ public class ReplaceOverride extends MethodOverride { @@ -70,6 +70,7 @@ public class ReplaceOverride extends MethodOverride {
this.typeIdentifiers.add(identifier);
}
@Override
public boolean matches(Method method) {
if (!method.getName().equals(getMethodName())) {

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

@ -18,11 +18,11 @@ package org.springframework.validation; @@ -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 @@ -50,7 +50,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
private MessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
private final List<ObjectError> errors = new LinkedList<>();
private final List<ObjectError> errors = new ArrayList<>();
private final Map<String, Class<?>> fieldTypes = new HashMap<>();
@ -145,7 +145,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi @@ -145,7 +145,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public List<ObjectError> getGlobalErrors() {
List<ObjectError> result = new LinkedList<>();
List<ObjectError> 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 @@ -167,7 +167,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public List<FieldError> getFieldErrors() {
List<FieldError> result = new LinkedList<>();
List<FieldError> 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 @@ -189,7 +189,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public List<FieldError> getFieldErrors(String field) {
List<FieldError> result = new LinkedList<>();
List<FieldError> result = new ArrayList<>();
String fixedField = fixedField(field);
for (ObjectError objectError : this.errors) {
if (objectError instanceof FieldError && isMatchingFieldError(fixedField, (FieldError) objectError)) {

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

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -146,7 +146,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
@Override
public List<ObjectError> getAllErrors() {
List<ObjectError> result = new LinkedList<>();
List<ObjectError> result = new ArrayList<>();
result.addAll(getGlobalErrors());
result.addAll(getFieldErrors());
return Collections.unmodifiableList(result);
@ -199,7 +199,7 @@ public abstract class AbstractErrors implements Errors, Serializable { @@ -199,7 +199,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
@Override
public List<FieldError> getFieldErrors(String field) {
List<FieldError> fieldErrors = getFieldErrors();
List<FieldError> result = new LinkedList<>();
List<FieldError> result = new ArrayList<>();
String fixedField = fixedField(field);
for (FieldError error : fieldErrors) {
if (isMatchingFieldError(fixedField, error)) {

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -37,7 +37,7 @@ import org.springframework.messaging.Message;
*/
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);

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 @@ -42,7 +42,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
protected final Log logger = LogFactory.getLog(getClass());
private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
new ConcurrentHashMap<>(256);
@ -113,9 +113,8 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu @@ -113,9 +113,8 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu
public Mono<Object> 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);
}

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

@ -17,9 +17,9 @@ @@ -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 { @@ -228,15 +228,14 @@ public class StompEncoder {
void add(byte b);
byte[] toByteArray();
}
@SuppressWarnings("serial")
private static class DefaultResult extends LinkedList<Object> implements Result {
private static class DefaultResult extends ArrayList<Object> implements Result {
private int size;
public void add(byte[] bytes) {
this.size += bytes.length;
super.add(bytes);

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -61,16 +61,16 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
@Nullable
private DataSource jtaDataSource;
private final List<String> mappingFileNames = new LinkedList<>();
private final List<String> mappingFileNames = new ArrayList<>();
private List<URL> jarFileUrls = new LinkedList<>();
private final List<URL> jarFileUrls = new ArrayList<>();
@Nullable
private URL persistenceUnitRootUrl;
private final List<String> managedClassNames = new LinkedList<>();
private final List<String> managedClassNames = new ArrayList<>();
private final List<String> managedPackages = new LinkedList<>();
private final List<String> managedPackages = new ArrayList<>();
private boolean excludeUnlistedClasses = false;

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

@ -1,5 +1,5 @@ @@ -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.
@ -24,7 +24,6 @@ import java.lang.reflect.Method; @@ -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;
@ -423,7 +422,7 @@ public class PersistenceAnnotationBeanPostProcessor @@ -423,7 +422,7 @@ public class PersistenceAnnotationBeanPostProcessor
Class<?> targetClass = clazz;
do {
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
final List<InjectionMetadata.InjectedElement> currElements = new ArrayList<>();
ReflectionUtils.doWithLocalFields(targetClass, field -> {
if (field.isAnnotationPresent(PersistenceContext.class) ||

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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;
@ -127,14 +127,14 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser { @@ -127,14 +127,14 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
}
List<RollbackRuleAttribute> rollbackRules = new LinkedList<>();
List<RollbackRuleAttribute> 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);

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

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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);

6
spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java

@ -16,7 +16,7 @@ @@ -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 { @@ -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 { @@ -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) {

11
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 @@ -43,7 +43,7 @@ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentRes
protected final Log logger = LogFactory.getLog(getClass());
private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();
private final List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>();
private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache =
new ConcurrentHashMap<>(256);
@ -116,9 +116,8 @@ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentRes @@ -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);
}

Loading…
Cancel
Save