Skip to content

Commit 56a1e7c

Browse files
committed
Use List.of / Map.of / Set.of
1 parent 86a8345 commit 56a1e7c

File tree

116 files changed

+288
-406
lines changed

Some content is hidden

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

116 files changed

+288
-406
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstaller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.maven.api.services;
2020

2121
import java.util.Collection;
22-
import java.util.Collections;
22+
import java.util.List;
2323

2424
import org.apache.maven.api.ProducedArtifact;
2525
import org.apache.maven.api.Service;
@@ -51,7 +51,7 @@ public interface ArtifactInstaller extends Service {
5151
* {@code artifact} is {@code null}
5252
*/
5353
default void install(Session session, ProducedArtifact artifact) {
54-
install(session, Collections.singletonList(artifact));
54+
install(session, List.of(artifact));
5555
}
5656

5757
/**

api/maven-api-core/src/main/java/org/apache/maven/api/services/ArtifactInstallerRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.api.services;
2020

2121
import java.util.Collection;
22-
import java.util.Collections;
2322
import java.util.List;
2423
import java.util.Objects;
2524

@@ -62,7 +61,7 @@ static ArtifactInstallerRequest build(Session session, Collection<ProducedArtifa
6261
class ArtifactInstallerRequestBuilder {
6362
Session session;
6463
RequestTrace trace;
65-
Collection<ProducedArtifact> artifacts = Collections.emptyList();
64+
Collection<ProducedArtifact> artifacts = List.of();
6665

6766
ArtifactInstallerRequestBuilder() {}
6867

@@ -80,7 +79,7 @@ public ArtifactInstallerRequestBuilder trace(RequestTrace trace) {
8079

8180
@Nonnull
8281
public ArtifactInstallerRequestBuilder artifacts(@Nullable Collection<ProducedArtifact> artifacts) {
83-
this.artifacts = artifacts != null ? artifacts : Collections.emptyList();
82+
this.artifacts = artifacts != null ? artifacts : List.of();
8483
return this;
8584
}
8685

api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactoryRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.Collection;
23-
import java.util.Collections;
23+
import java.util.List;
2424
import java.util.Objects;
2525

2626
import org.apache.maven.api.ArtifactCoordinates;
@@ -117,7 +117,7 @@ class DependencyCoordinatesFactoryRequestBuilder {
117117
private String coordinateString;
118118
private String scope;
119119
private boolean optional;
120-
private Collection<Exclusion> exclusions = Collections.emptyList();
120+
private Collection<Exclusion> exclusions = List.of();
121121

122122
DependencyCoordinatesFactoryRequestBuilder() {}
123123

api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverRequest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.Collection;
23-
import java.util.Collections;
2423
import java.util.List;
2524
import java.util.Objects;
2625
import java.util.Optional;
@@ -176,8 +175,8 @@ class DependencyResolverRequestBuilder {
176175
Project project;
177176
Artifact rootArtifact;
178177
DependencyCoordinates root;
179-
List<DependencyCoordinates> dependencies = Collections.emptyList();
180-
List<DependencyCoordinates> managedDependencies = Collections.emptyList();
178+
List<DependencyCoordinates> dependencies = List.of();
179+
List<DependencyCoordinates> managedDependencies = List.of();
181180
boolean verbose;
182181
PathScope pathScope;
183182
Predicate<PathType> pathTypeFilter;
@@ -246,7 +245,7 @@ public DependencyResolverRequestBuilder root(@Nonnull DependencyCoordinates root
246245
*/
247246
@Nonnull
248247
public DependencyResolverRequestBuilder dependencies(@Nullable List<DependencyCoordinates> dependencies) {
249-
this.dependencies = (dependencies != null) ? dependencies : Collections.emptyList();
248+
this.dependencies = (dependencies != null) ? dependencies : List.of();
250249
return this;
251250
}
252251

@@ -278,7 +277,7 @@ public DependencyResolverRequestBuilder dependency(@Nullable DependencyCoordinat
278277
@Nonnull
279278
public DependencyResolverRequestBuilder managedDependencies(
280279
@Nullable List<DependencyCoordinates> managedDependencies) {
281-
this.managedDependencies = (managedDependencies != null) ? managedDependencies : Collections.emptyList();
280+
this.managedDependencies = (managedDependencies != null) ? managedDependencies : List.of();
282281
return this;
283282
}
284283

api/maven-api-model/src/main/java/org/apache/maven/api/model/InputLocation.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.io.Serializable;
2222
import java.util.Collection;
23-
import java.util.Collections;
2423
import java.util.LinkedHashMap;
2524
import java.util.Map;
2625

@@ -44,7 +43,7 @@ public InputLocation(InputSource source) {
4443
this.lineNumber = -1;
4544
this.columnNumber = -1;
4645
this.source = source;
47-
this.locations = Collections.singletonMap(0, this);
46+
this.locations = Map.of(0, this);
4847
this.importedFrom = null;
4948
}
5049

@@ -60,8 +59,7 @@ public InputLocation(int lineNumber, int columnNumber, InputSource source, Objec
6059
this.lineNumber = lineNumber;
6160
this.columnNumber = columnNumber;
6261
this.source = source;
63-
this.locations =
64-
selfLocationKey != null ? Collections.singletonMap(selfLocationKey, this) : Collections.emptyMap();
62+
this.locations = selfLocationKey != null ? Map.of(selfLocationKey, this) : Map.of();
6563
this.importedFrom = null;
6664
}
6765

api/maven-api-spi/src/main/java/org/apache/maven/api/spi/LanguageProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* <pre>
3636
* public class CustomLanguageProvider implements LanguageProvider {
3737
* public Collection&lt;Language&gt; provides() {
38-
* return Collections.singleton(language("kotlin"));
38+
* return Set.of(language("kotlin"));
3939
* }
4040
* }
4141
* </pre>

api/maven-api-spi/src/main/java/org/apache/maven/api/spi/LifecycleProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <pre>
3838
* public class CustomLifecycleProvider implements LifecycleProvider {
3939
* public Collection&lt;Lifecycle&gt; provides() {
40-
* return Collections.singleton(
40+
* return Set.of(
4141
* lifecycle("deploy-docker", Arrays.asList(
4242
* "build-image",
4343
* "tag-image",

api/maven-api-spi/src/main/java/org/apache/maven/api/spi/PathScopeProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <pre>
3838
* public class CustomPathScopeProvider implements PathScopeProvider {
3939
* public Collection&lt;PathScope&gt; provides() {
40-
* return Collections.singleton(pathScope("integration-test",
40+
* return Set.of(pathScope("integration-test",
4141
* ProjectScope.TEST, DependencyScope.TEST));
4242
* }
4343
* }

api/maven-api-spi/src/main/java/org/apache/maven/api/spi/ProjectScopeProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* <pre>
3636
* public class CustomProjectScopeProvider implements ProjectScopeProvider {
3737
* public Collection&lt;ProjectScope&gt; provides() {
38-
* return Collections.singleton(projectScope("integration-test"));
38+
* return Set.of(projectScope("integration-test"));
3939
* }
4040
* }
4141
* </pre>

compat/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/ArtifactDescriptorReaderDelegate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.repository.internal;
2020

2121
import java.util.ArrayList;
22-
import java.util.Collections;
2322
import java.util.HashMap;
2423
import java.util.LinkedHashMap;
2524
import java.util.List;
@@ -104,7 +103,7 @@ private Dependency convert(org.apache.maven.model.Dependency dependency, Artifac
104103

105104
Map<String, String> props = null;
106105
if (system) {
107-
props = Collections.singletonMap(MavenArtifactProperties.LOCAL_PATH, dependency.getSystemPath());
106+
props = Map.of(MavenArtifactProperties.LOCAL_PATH, dependency.getSystemPath());
108107
}
109108

110109
Artifact artifact = new DefaultArtifact(

impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private CoreExtensionEntry createExtension(CoreExtension extension, List<Artifac
202202
}
203203
return CoreExtensionEntry.discoverFrom(
204204
realm,
205-
Collections.singleton(artifacts.get(0).getPath().toFile()),
205+
Set.of(artifacts.get(0).getPath().toFile()),
206206
extension.getGroupId() + ":" + extension.getArtifactId(),
207207
extension.getConfiguration());
208208
}

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnenc/EncryptParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.cling.invoker.mvnenc;
2020

21-
import java.util.Collections;
2221
import java.util.List;
2322

2423
import org.apache.commons.cli.ParseException;
@@ -56,7 +55,7 @@ protected EncryptInvokerRequest getInvokerRequest(LocalContext context) {
5655

5756
@Override
5857
protected List<Options> parseCliOptions(LocalContext context) {
59-
return Collections.singletonList(parseEncryptCliOptions(context.parserRequest.args()));
58+
return List.of(parseEncryptCliOptions(context.parserRequest.args()));
6059
}
6160

6261
protected CommonsCliEncryptOptions parseEncryptCliOptions(List<String> args) {

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnsh/ShellParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.maven.cling.invoker.mvnsh;
2020

21-
import java.util.Collections;
2221
import java.util.List;
2322

2423
import org.apache.commons.cli.ParseException;
@@ -55,7 +54,7 @@ protected ShellInvokerRequest getInvokerRequest(LocalContext context) {
5554

5655
@Override
5756
protected List<Options> parseCliOptions(LocalContext context) {
58-
return Collections.singletonList(parseShellCliOptions(context.parserRequest.args()));
57+
return List.of(parseShellCliOptions(context.parserRequest.args()));
5958
}
6059

6160
protected CommonsCliShellOptions parseShellCliOptions(List<String> args) {

impl/maven-cli/src/main/java/org/apache/maven/cling/props/MavenProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public String put(String key, List<String> commentLines, String value) {
311311
}
312312

313313
public String put(String key, String comment, String value) {
314-
return put(key, Collections.singletonList(comment), value);
314+
return put(key, List.of(comment), value);
315315
}
316316

317317
public boolean update(Map<String, String> props) {

impl/maven-core/src/main/java/org/apache/maven/DefaultMaven.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.ArrayList;
2828
import java.util.Arrays;
2929
import java.util.Collection;
30-
import java.util.Collections;
3130
import java.util.HashMap;
3231
import java.util.HashSet;
3332
import java.util.LinkedHashMap;
@@ -439,7 +438,7 @@ private <T> Collection<T> getExtensionComponents(Collection<MavenProject> projec
439438

440439
protected <T> Collection<T> getProjectScopedExtensionComponents(Collection<MavenProject> projects, Class<T> role) {
441440
if (projects == null) {
442-
return Collections.emptyList();
441+
return List.of();
443442
}
444443

445444
Collection<T> foundComponents = new LinkedHashSet<>();

impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public File findArtifact(Artifact artifact) {
124124

125125
public List<String> findVersions(Artifact artifact) {
126126
List<String> versions = getProjects()
127-
.getOrDefault(artifact.getGroupId(), Collections.emptyMap())
128-
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
127+
.getOrDefault(artifact.getGroupId(), Map.of())
128+
.getOrDefault(artifact.getArtifactId(), Map.of())
129129
.values()
130130
.stream()
131131
.map(MavenProject::getVersion)
@@ -134,8 +134,8 @@ public List<String> findVersions(Artifact artifact) {
134134
return versions;
135135
}
136136
return getAllProjects()
137-
.getOrDefault(artifact.getGroupId(), Collections.emptyMap())
138-
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
137+
.getOrDefault(artifact.getGroupId(), Map.of())
138+
.getOrDefault(artifact.getArtifactId(), Map.of())
139139
.values()
140140
.stream()
141141
.filter(p -> Objects.nonNull(findArtifact(p, artifact, false)))
@@ -484,8 +484,8 @@ private MavenProject getProject(Artifact artifact) {
484484
}
485485

486486
private MavenProject getProject(Artifact artifact, Map<String, Map<String, Map<String, MavenProject>>> projects) {
487-
return projects.getOrDefault(artifact.getGroupId(), Collections.emptyMap())
488-
.getOrDefault(artifact.getArtifactId(), Collections.emptyMap())
487+
return projects.getOrDefault(artifact.getGroupId(), Map.of())
488+
.getOrDefault(artifact.getArtifactId(), Map.of())
489489
.getOrDefault(artifact.getBaseVersion(), null);
490490
}
491491

@@ -501,7 +501,7 @@ private Map<String, Map<String, Map<String, MavenProject>>> getAllProjects() {
501501
.put(project.getVersion(), project));
502502
this.allProjects = map;
503503
} else {
504-
return Collections.emptyMap();
504+
return Map.of();
505505
}
506506
}
507507
return allProjects;
@@ -518,7 +518,7 @@ private Map<String, Map<String, Map<String, MavenProject>>> getProjects() {
518518
.put(project.getVersion(), project));
519519
this.projects = map;
520520
} else {
521-
return Collections.emptyMap();
521+
return Map.of();
522522
}
523523
}
524524
return projects;

impl/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.File;
2222
import java.util.ArrayList;
2323
import java.util.Collection;
24-
import java.util.Collections;
2524
import java.util.Iterator;
2625
import java.util.List;
2726
import java.util.Map;
@@ -122,7 +121,7 @@ public static void toArtifacts(
122121
nodeTrail.addAll(trail);
123122
nodeTrail.add(artifact.getId());
124123

125-
if (filter == null || filter.accept(node, Collections.emptyList())) {
124+
if (filter == null || filter.accept(node, List.of())) {
126125
artifact.setDependencyTrail(nodeTrail);
127126
artifacts.add(artifact);
128127
}
@@ -144,7 +143,7 @@ public static Artifact toArtifact(org.apache.maven.artifact.Artifact artifact) {
144143
Map<String, String> props = null;
145144
if (org.apache.maven.artifact.Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
146145
String localPath = (artifact.getFile() != null) ? artifact.getFile().getPath() : "";
147-
props = Collections.singletonMap(MavenArtifactProperties.LOCAL_PATH, localPath);
146+
props = Map.of(MavenArtifactProperties.LOCAL_PATH, localPath);
148147
}
149148

150149
Artifact result = new DefaultArtifact(
@@ -168,14 +167,14 @@ public static Dependency toDependency(
168167

169168
Artifact result = toArtifact(artifact);
170169

171-
List<Exclusion> excl = Optional.ofNullable(exclusions).orElse(Collections.emptyList()).stream()
170+
List<Exclusion> excl = Optional.ofNullable(exclusions).orElse(List.of()).stream()
172171
.map(RepositoryUtils::toExclusion)
173172
.toList();
174173
return new Dependency(result, artifact.getScope(), artifact.isOptional(), excl);
175174
}
176175

177176
public static List<RemoteRepository> toRepos(List<ArtifactRepository> repos) {
178-
return Optional.ofNullable(repos).orElse(Collections.emptyList()).stream()
177+
return Optional.ofNullable(repos).orElse(List.of()).stream()
179178
.map(RepositoryUtils::toRepo)
180179
.toList();
181180
}
@@ -279,7 +278,7 @@ public static Dependency toDependency(
279278

280279
Map<String, String> props = null;
281280
if (system) {
282-
props = Collections.singletonMap(MavenArtifactProperties.LOCAL_PATH, dependency.getSystemPath());
281+
props = Map.of(MavenArtifactProperties.LOCAL_PATH, dependency.getSystemPath());
283282
}
284283

285284
Artifact artifact = new DefaultArtifact(

impl/maven-core/src/main/java/org/apache/maven/artifact/repository/MavenArtifactRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MavenArtifactRepository implements ArtifactRepository {
5757

5858
private Proxy proxy;
5959

60-
private List<ArtifactRepository> mirroredRepositories = Collections.emptyList();
60+
private List<ArtifactRepository> mirroredRepositories = List.of();
6161

6262
private boolean blocked;
6363

@@ -190,7 +190,7 @@ public Artifact find(Artifact artifact) {
190190
}
191191

192192
public List<String> findVersions(Artifact artifact) {
193-
return Collections.emptyList();
193+
return List.of();
194194
}
195195

196196
public String getId() {
@@ -386,7 +386,7 @@ public void setMirroredRepositories(List<ArtifactRepository> mirroredRepositorie
386386
if (mirroredRepositories != null) {
387387
this.mirroredRepositories = Collections.unmodifiableList(mirroredRepositories);
388388
} else {
389-
this.mirroredRepositories = Collections.emptyList();
389+
this.mirroredRepositories = List.of();
390390
}
391391
}
392392

impl/maven-core/src/main/java/org/apache/maven/bridge/MavenRepositorySystem.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.file.Path;
2929
import java.util.ArrayList;
3030
import java.util.Collection;
31-
import java.util.Collections;
3231
import java.util.HashSet;
3332
import java.util.LinkedHashMap;
3433
import java.util.List;
@@ -207,7 +206,7 @@ private void injectMirror(ArtifactRepository repository, Mirror mirror) {
207206
repository.getSnapshots(),
208207
repository.getReleases());
209208

210-
repository.setMirroredRepositories(Collections.singletonList(original));
209+
repository.setMirroredRepositories(List.of(original));
211210

212211
repository.setId(mirror.getId());
213212
repository.setUrl(mirror.getUrl());

0 commit comments

Comments
 (0)