Skip to content

Commit 8745745

Browse files
committed
Replace remaining usage of LinkedList with ArrayList/ArrayDeque
Closes spring-projectsgh-25650
1 parent d198c44 commit 8745745

65 files changed

Lines changed: 239 additions & 239 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java

Lines changed: 3 additions & 3 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.aop.framework;
1818

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

2222
import org.springframework.util.Assert;
@@ -34,7 +34,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
3434

3535
private AopProxyFactory aopProxyFactory;
3636

37-
private final List<AdvisedSupportListener> listeners = new LinkedList<>();
37+
private final List<AdvisedSupportListener> listeners = new ArrayList<>();
3838

3939
/** Set to true when the first AOP proxy has been created. */
4040
private boolean active = false;

spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
package org.springframework.beans.factory.parsing;
1818

19-
import java.util.LinkedList;
19+
import java.util.ArrayDeque;
2020

2121
import org.springframework.lang.Nullable;
2222

2323
/**
24-
* Simple {@link LinkedList}-based structure for tracking the logical position during
24+
* Simple {@link ArrayDeque}-based structure for tracking the logical position during
2525
* a parsing process. {@link Entry entries} are added to the LinkedList at
2626
* each point during the parse phase in a reader-specific manner.
2727
*
@@ -30,6 +30,7 @@
3030
* error messages.
3131
*
3232
* @author Rob Harrop
33+
* @author Juergen Hoeller
3334
* @since 2.0
3435
*/
3536
public final class ParseState {
@@ -40,25 +41,24 @@ public final class ParseState {
4041
private static final char TAB = '\t';
4142

4243
/**
43-
* Internal {@link LinkedList} storage.
44+
* Internal {@link ArrayDeque} storage.
4445
*/
45-
private final LinkedList<Entry> state;
46+
private final ArrayDeque<Entry> state;
4647

4748

4849
/**
4950
* Create a new {@code ParseState} with an empty {@link LinkedList}.
5051
*/
5152
public ParseState() {
52-
this.state = new LinkedList<>();
53+
this.state = new ArrayDeque<>();
5354
}
5455

5556
/**
5657
* Create a new {@code ParseState} whose {@link LinkedList} is a {@link Object#clone clone}
5758
* of that of the passed in {@code ParseState}.
5859
*/
59-
@SuppressWarnings("unchecked")
6060
private ParseState(ParseState other) {
61-
this.state = (LinkedList<Entry>) other.state.clone();
61+
this.state = other.state.clone();
6262
}
6363

6464

@@ -100,15 +100,17 @@ public ParseState snapshot() {
100100
@Override
101101
public String toString() {
102102
StringBuilder sb = new StringBuilder();
103-
for (int x = 0; x < this.state.size(); x++) {
104-
if (x > 0) {
103+
int i = 0;
104+
for (ParseState.Entry entry : this.state) {
105+
if (i > 0) {
105106
sb.append('\n');
106-
for (int y = 0; y < x; y++) {
107+
for (int j = 0; j < i; j++) {
107108
sb.append(TAB);
108109
}
109110
sb.append("-> ");
110111
}
111-
sb.append(this.state.get(x));
112+
sb.append(entry);
113+
i++;
112114
}
113115
return sb.toString();
114116
}
@@ -118,7 +120,6 @@ public String toString() {
118120
* Marker interface for entries into the {@link ParseState}.
119121
*/
120122
public interface Entry {
121-
122123
}
123124

124125
}

spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceListFactoryBean.java

Lines changed: 3 additions & 3 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.beans.factory.serviceloader;
1818

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

@@ -35,7 +35,7 @@ public class ServiceListFactoryBean extends AbstractServiceLoaderBasedFactoryBea
3535

3636
@Override
3737
protected Object getObjectToExpose(ServiceLoader<?> serviceLoader) {
38-
List<Object> result = new LinkedList<>();
38+
List<Object> result = new ArrayList<>();
3939
for (Object loaderObject : serviceLoader) {
4040
result.add(loaderObject);
4141
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
import java.lang.reflect.Modifier;
2525
import java.security.AccessController;
2626
import java.security.PrivilegedAction;
27+
import java.util.ArrayDeque;
2728
import java.util.ArrayList;
2829
import java.util.Arrays;
2930
import java.util.Collections;
31+
import java.util.Deque;
3032
import java.util.HashSet;
3133
import java.util.LinkedHashSet;
32-
import java.util.LinkedList;
3334
import java.util.List;
3435
import java.util.Map;
3536
import java.util.Set;
@@ -199,7 +200,7 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
199200
AutowireUtils.sortConstructors(candidates);
200201
int minTypeDiffWeight = Integer.MAX_VALUE;
201202
Set<Constructor<?>> ambiguousConstructors = null;
202-
LinkedList<UnsatisfiedDependencyException> causes = null;
203+
Deque<UnsatisfiedDependencyException> causes = null;
203204

204205
for (Constructor<?> candidate : candidates) {
205206
int parameterCount = candidate.getParameterCount();
@@ -233,7 +234,7 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
233234
}
234235
// Swallow and try next constructor.
235236
if (causes == null) {
236-
causes = new LinkedList<>();
237+
causes = new ArrayDeque<>(1);
237238
}
238239
causes.add(ex);
239240
continue;
@@ -511,7 +512,7 @@ public BeanWrapper instantiateUsingFactoryMethod(
511512
}
512513
}
513514

514-
LinkedList<UnsatisfiedDependencyException> causes = null;
515+
Deque<UnsatisfiedDependencyException> causes = null;
515516

516517
for (Method candidate : candidates) {
517518
int parameterCount = candidate.getParameterCount();
@@ -544,7 +545,7 @@ public BeanWrapper instantiateUsingFactoryMethod(
544545
}
545546
// Swallow and try next overloaded factory method.
546547
if (causes == null) {
547-
causes = new LinkedList<>();
548+
causes = new ArrayDeque<>(1);
548549
}
549550
causes.add(ex);
550551
continue;

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-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/CollectingReaderEventListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222
import java.util.LinkedHashMap;
23-
import java.util.LinkedList;
2423
import java.util.List;
2524
import java.util.Map;
2625

@@ -36,13 +35,13 @@
3635
*/
3736
public class CollectingReaderEventListener implements ReaderEventListener {
3837

39-
private final List<DefaultsDefinition> defaults = new LinkedList<>();
38+
private final List<DefaultsDefinition> defaults = new ArrayList<>();
4039

4140
private final Map<String, ComponentDefinition> componentDefinitions = new LinkedHashMap<>(8);
4241

4342
private final Map<String, List<AliasDefinition>> aliasMap = new LinkedHashMap<>(8);
4443

45-
private final List<ImportDefinition> imports = new LinkedList<>();
44+
private final List<ImportDefinition> imports = new ArrayList<>();
4645

4746

4847
@Override

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Date;
2323
import java.util.HashMap;
2424
import java.util.HashSet;
25-
import java.util.LinkedList;
2625
import java.util.List;
2726
import java.util.Map;
2827
import java.util.Properties;
@@ -77,7 +76,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
7776

7877
private Float myFloat = Float.valueOf(0.0f);
7978

80-
private Collection<? super Object> friends = new LinkedList<>();
79+
private Collection<? super Object> friends = new ArrayList<>();
8180

8281
private Set<?> someSet = new HashSet<>();
8382

spring-context-support/src/main/java/org/springframework/scheduling/commonj/TimerManagerFactoryBean.java

Lines changed: 14 additions & 10 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.scheduling.commonj;
1818

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

2222
import javax.naming.NamingException;
@@ -62,7 +62,8 @@ public class TimerManagerFactoryBean extends TimerManagerAccessor
6262
@Nullable
6363
private ScheduledTimerListener[] scheduledTimerListeners;
6464

65-
private final List<Timer> timers = new LinkedList<>();
65+
@Nullable
66+
private List<Timer> timers;
6667

6768

6869
/**
@@ -87,6 +88,7 @@ public void afterPropertiesSet() throws NamingException {
8788
super.afterPropertiesSet();
8889

8990
if (this.scheduledTimerListeners != null) {
91+
this.timers = new ArrayList<>(this.scheduledTimerListeners.length);
9092
TimerManager timerManager = obtainTimerManager();
9193
for (ScheduledTimerListener scheduledTask : this.scheduledTimerListeners) {
9294
Timer timer;
@@ -144,15 +146,17 @@ public boolean isSingleton() {
144146
@Override
145147
public void destroy() {
146148
// Cancel all registered timers.
147-
for (Timer timer : this.timers) {
148-
try {
149-
timer.cancel();
150-
}
151-
catch (Throwable ex) {
152-
logger.debug("Could not cancel CommonJ Timer", ex);
149+
if (this.timers != null) {
150+
for (Timer timer : this.timers) {
151+
try {
152+
timer.cancel();
153+
}
154+
catch (Throwable ex) {
155+
logger.debug("Could not cancel CommonJ Timer", ex);
156+
}
153157
}
158+
this.timers.clear();
154159
}
155-
this.timers.clear();
156160

157161
// Stop the TimerManager itself.
158162
super.destroy();

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.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.
@@ -18,7 +18,6 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.Arrays;
21-
import java.util.LinkedList;
2221
import java.util.List;
2322
import java.util.Map;
2423

@@ -228,7 +227,7 @@ protected void registerJobsAndTriggers() throws SchedulerException {
228227
}
229228
else {
230229
// Create empty list for easier checks when registering triggers.
231-
this.jobDetails = new LinkedList<>();
230+
this.jobDetails = new ArrayList<>();
232231
}
233232

234233
// Register Calendars.

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.ArrayList;
2222
import java.util.Collection;
2323
import java.util.Collections;
24-
import java.util.LinkedList;
2524
import java.util.List;
2625
import java.util.Map;
2726
import java.util.Optional;
@@ -403,7 +402,7 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
403402
Cache.ValueWrapper cacheHit = findCachedItem(contexts.get(CacheableOperation.class));
404403

405404
// Collect puts from any @Cacheable miss, if no cached item is found
406-
List<CachePutRequest> cachePutRequests = new LinkedList<>();
405+
List<CachePutRequest> cachePutRequests = new ArrayList<>();
407406
if (cacheHit == null) {
408407
collectPutRequests(contexts.get(CacheableOperation.class),
409408
CacheOperationExpressionEvaluator.NO_RESULT, cachePutRequests);

0 commit comments

Comments
 (0)