Use Stream.toList instead of Stream.collect when possible

Update code to make use of `Stream.toList()` whenever possible.

Closes gh-28177
This commit is contained in:
Phillip Webb
2022-10-04 00:26:51 -07:00
parent 118836d204
commit e0b67889a8
159 changed files with 349 additions and 607 deletions

View File

@@ -31,7 +31,6 @@ import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
@@ -510,7 +509,7 @@ public abstract class Packager {
private void writeClasspathIndexIfNecessary(List<String> paths, Layout layout, AbstractJarWriter writer)
throws IOException {
if (layout.getClasspathIndexFileLocation() != null) {
List<String> names = paths.stream().map((path) -> "- \"" + path + "\"").collect(Collectors.toList());
List<String> names = paths.stream().map((path) -> "- \"" + path + "\"").toList();
writer.writeIndexFile(layout.getClasspathIndexFileLocation(), names);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -19,7 +19,6 @@ package org.springframework.boot.loader.tools.layer;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.boot.loader.tools.Layer;
import org.springframework.util.Assert;
@@ -56,7 +55,7 @@ public class IncludeExcludeContentSelector<T> implements ContentSelector<T> {
}
private <S> List<ContentFilter<T>> adapt(List<S> list, Function<S, ContentFilter<T>> mapper) {
return list.stream().map(mapper).collect(Collectors.toList());
return list.stream().map(mapper).toList();
}
@Override

View File

@@ -234,7 +234,7 @@ abstract class AbstractPackagerTests<P extends Packager> {
String index = getPackagedEntryContent("BOOT-INF/classpath.idx");
String[] libraries = index.split("\\r?\\n");
List<String> expected = Stream.of(libJarFile1, libJarFile2, libJarFile3)
.map((jar) -> "- \"BOOT-INF/lib/" + jar.getName() + "\"").collect(Collectors.toList());
.map((jar) -> "- \"BOOT-INF/lib/" + jar.getName() + "\"").toList();
assertThat(Arrays.asList(libraries)).containsExactlyElementsOf(expected);
}
@@ -265,7 +265,7 @@ abstract class AbstractPackagerTests<P extends Packager> {
assertThat(hasPackagedEntry("BOOT-INF/classpath.idx")).isTrue();
String classpathIndex = getPackagedEntryContent("BOOT-INF/classpath.idx");
List<String> expectedClasspathIndex = Stream.of(libJarFile1, libJarFile2, libJarFile3)
.map((file) -> "- \"BOOT-INF/lib/" + file.getName() + "\"").collect(Collectors.toList());
.map((file) -> "- \"BOOT-INF/lib/" + file.getName() + "\"").toList();
assertThat(Arrays.asList(classpathIndex.split("\\n"))).containsExactlyElementsOf(expectedClasspathIndex);
assertThat(hasPackagedEntry("BOOT-INF/layers.idx")).isTrue();
String layersIndex = getPackagedEntryContent("BOOT-INF/layers.idx");
@@ -637,7 +637,8 @@ abstract class AbstractPackagerTests<P extends Packager> {
protected abstract void execute(P packager, Libraries libraries) throws IOException;
protected Collection<String> getPackagedEntryNames() throws IOException {
return getAllPackagedEntries().stream().map(ZipArchiveEntry::getName).collect(Collectors.toList());
return getAllPackagedEntries().stream().map(ZipArchiveEntry::getName)
.collect(Collectors.toCollection(ArrayList::new));
}
protected boolean hasPackagedLauncherClasses() throws IOException {