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

@@ -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.
@@ -29,7 +29,6 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* A class path index file that provides ordering information for JARs.
@@ -45,7 +44,7 @@ final class ClassPathIndexFile {
private ClassPathIndexFile(File root, List<String> lines) {
this.root = root;
this.lines = lines.stream().map(this::extractName).collect(Collectors.toList());
this.lines = lines.stream().map(this::extractName).toList();
}
private String extractName(String line) {
@@ -67,7 +66,7 @@ final class ClassPathIndexFile {
}
List<URL> getUrls() {
return Collections.unmodifiableList(this.lines.stream().map(this::asUrl).collect(Collectors.toList()));
return this.lines.stream().map(this::asUrl).toList();
}
private URL asUrl(String line) {

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.
@@ -22,7 +22,6 @@ import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.stream.Collectors;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -207,7 +206,7 @@ class JarURLConnectionTests {
void entriesCanBeStreamedFromJarFileOfConnection() throws Exception {
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
List<String> entryNames = connection.getJarFile().stream().map(JarEntry::getName).collect(Collectors.toList());
List<String> entryNames = connection.getJarFile().stream().map(JarEntry::getName).toList();
assertThat(entryNames).hasSize(12);
}