Skip to content

Commit

Permalink
Selected use of ArrayList instead of LinkedList in common places
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Aug 27, 2020
1 parent 589060d commit cf2e0c7
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 51 deletions.
@@ -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.
Expand All @@ -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;
Expand All @@ -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<>();


/**
Expand Down Expand Up @@ -70,6 +70,7 @@ public void addTypeIdentifier(String identifier) {
this.typeIdentifiers.add(identifier);
}


@Override
public boolean matches(Method method) {
if (!method.getName().equals(getMethodName())) {
Expand Down
Expand Up @@ -18,11 +18,11 @@

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;
Expand Down Expand Up @@ -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<>();

Expand Down Expand Up @@ -145,7 +145,7 @@ public List<ObjectError> getAllErrors() {

@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);
Expand All @@ -167,7 +167,7 @@ public ObjectError getGlobalError() {

@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);
Expand All @@ -189,7 +189,7 @@ public FieldError getFieldError() {

@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)) {
Expand Down
@@ -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.
Expand All @@ -18,9 +18,9 @@

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;

Expand Down Expand Up @@ -146,7 +146,7 @@ public int getErrorCount() {

@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);
Expand Down Expand Up @@ -199,7 +199,7 @@ public int getFieldErrorCount(String field) {
@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)) {
Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -37,7 +37,7 @@
*/
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);
Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -113,9 +113,8 @@ public boolean supportsParameter(MethodParameter parameter) {
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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -228,15 +228,14 @@ private interface Result {
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);
Expand Down
@@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
@@ -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.
Expand All @@ -24,7 +24,6 @@
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;
Expand Down Expand Up @@ -423,7 +422,7 @@ private InjectionMetadata buildPersistenceMetadata(final Class<?> clazz) {
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) ||
Expand Down
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -127,14 +127,14 @@ private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext p
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);

Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -38,7 +38,7 @@
*/
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);
Expand Down
Expand Up @@ -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;
Expand All @@ -40,15 +40,15 @@ class RegexPathElement extends PathElement {
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";


private char[] regex;
private final char[] regex;

private final boolean caseSensitive;

private final Pattern pattern;

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) {
Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -116,9 +116,8 @@ public Mono<Object> resolveArgument(

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);
}
Expand Down

0 comments on commit cf2e0c7

Please sign in to comment.