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

@@ -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<Entry> state;
private final ArrayDeque<Entry> 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<Entry>) 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 {
}
}

View File

@@ -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<Object> result = new LinkedList<>();
List<Object> result = new ArrayList<>();
for (Object loaderObject : serviceLoader) {
result.add(loaderObject);
}

View File

@@ -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<Constructor<?>> ambiguousConstructors = null;
LinkedList<UnsatisfiedDependencyException> causes = null;
Deque<UnsatisfiedDependencyException> 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<UnsatisfiedDependencyException> causes = null;
Deque<UnsatisfiedDependencyException> 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;

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.
@@ -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<String> typeIdentifiers = new LinkedList<>();
private final List<String> 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())) {

View File

@@ -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<DefaultsDefinition> defaults = new LinkedList<>();
private final List<DefaultsDefinition> defaults = new ArrayList<>();
private final Map<String, ComponentDefinition> componentDefinitions = new LinkedHashMap<>(8);
private final Map<String, List<AliasDefinition>> aliasMap = new LinkedHashMap<>(8);
private final List<ImportDefinition> imports = new LinkedList<>();
private final List<ImportDefinition> imports = new ArrayList<>();
@Override

View File

@@ -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<? super Object> friends = new LinkedList<>();
private Collection<? super Object> friends = new ArrayList<>();
private Set<?> someSet = new HashSet<>();