Skip to content

Commit 9ddb7b0

Browse files
committed
Merge pull request #41053 from PiyalAhmed
* pr/41053: Polish "Use constructor rather than Collection.addAll" Use constructor rather than Collection.addAll Closes gh-41053
2 parents d370981 + ecc9a23 commit 9ddb7b0

File tree

7 files changed

+12
-18
lines changed

7 files changed

+12
-18
lines changed

buildSrc/src/main/java/org/springframework/boot/build/toolchain/ToolchainPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ private void disableToolchainTasks(Project project) {
7171
}
7272

7373
private void configureTestToolchain(Project project, ToolchainExtension toolchain) {
74-
List<String> jvmArgs = new ArrayList<>();
75-
jvmArgs.addAll(toolchain.getTestJvmArgs().getOrElse(Collections.emptyList()));
74+
List<String> jvmArgs = new ArrayList<>(toolchain.getTestJvmArgs().getOrElse(Collections.emptyList()));
7675
project.getTasks().withType(Test.class, (test) -> test.jvmArgs(jvmArgs));
7776
}
7877

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -96,8 +96,7 @@ public Collection<LoadableResource> getResources(String prefix, String[] suffixe
9696
ensureInitialized();
9797
Predicate<LocatedResource> matchesPrefixAndSuffixes = (locatedResource) -> StringUtils
9898
.startsAndEndsWith(locatedResource.resource.getFilename(), prefix, suffixes);
99-
List<LoadableResource> result = new ArrayList<>();
100-
result.addAll(this.scanner.getResources(prefix, suffixes));
99+
List<LoadableResource> result = new ArrayList<>(this.scanner.getResources(prefix, suffixes));
101100
this.locatedResources.stream()
102101
.filter(matchesPrefixAndSuffixes)
103102
.map(this::asClassPathResource)

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ static class ContextCustomizerKey {
240240
this.key = Collections.unmodifiableSet(synthesize(annotations));
241241
}
242242
else {
243-
Set<Object> key = new HashSet<>();
244-
key.addAll(determinedImports);
243+
Set<Object> key = new HashSet<>(determinedImports);
245244
Set<Annotation> componentScanning = annotations.stream()
246245
.filter((annotation) -> annotation.getType().equals(ComponentScan.class))
247246
.map(MergedAnnotation::synthesize)

spring-boot-project/spring-boot-testcontainers/src/main/java/org/springframework/boot/testcontainers/service/connection/ServiceConnectionAutoConfigurationRegistrar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -68,8 +68,8 @@ private void registerBeanDefinitions(ConfigurableListableBeanFactory beanFactory
6868

6969
private Set<ServiceConnection> getAnnotations(ConfigurableListableBeanFactory beanFactory, String beanName,
7070
BeanDefinition beanDefinition) {
71-
Set<ServiceConnection> annotations = new LinkedHashSet<>();
72-
annotations.addAll(beanFactory.findAllAnnotationsOnBean(beanName, ServiceConnection.class, false));
71+
Set<ServiceConnection> annotations = new LinkedHashSet<>(
72+
beanFactory.findAllAnnotationsOnBean(beanName, ServiceConnection.class, false));
7373
if (beanDefinition instanceof TestcontainerBeanDefinition testcontainerBeanDefinition) {
7474
testcontainerBeanDefinition.getAnnotations()
7575
.stream(ServiceConnection.class)

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigData.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ public Options with(Option option) {
239239
}
240240

241241
private Options copy(Consumer<EnumSet<Option>> processor) {
242-
EnumSet<Option> options = EnumSet.noneOf(Option.class);
243-
options.addAll(this.options);
242+
EnumSet<Option> options = EnumSet.copyOf(this.options);
244243
processor.accept(options);
245244
return new Options(options);
246245
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TldPatterns.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -195,8 +195,7 @@ final class TldPatterns {
195195
static final Set<String> DEFAULT_SCAN;
196196

197197
static {
198-
Set<String> scanPatterns = new LinkedHashSet<>();
199-
scanPatterns.addAll(TOMCAT_SCAN);
198+
Set<String> scanPatterns = new LinkedHashSet<>(TOMCAT_SCAN);
200199
DEFAULT_SCAN = Collections.unmodifiableSet(scanPatterns);
201200
}
202201

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/TomcatEmbeddedContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -128,8 +128,7 @@ void setMimeMappings(MimeMappings mimeMappings) {
128128

129129
@Override
130130
public String[] findMimeMappings() {
131-
List<String> mappings = new ArrayList<>();
132-
mappings.addAll(Arrays.asList(super.findMimeMappings()));
131+
List<String> mappings = new ArrayList<>(Arrays.asList(super.findMimeMappings()));
133132
if (this.mimeMappings != null) {
134133
this.mimeMappings.forEach((mapping) -> mappings.add(mapping.getExtension()));
135134
}

0 commit comments

Comments
 (0)