Simplify code using Stream.toList (#3831)

Stream.toList was introduced in Java 16 and creates an unmodifiable List so it can be used to simplify code whenever the List is not expected to be modified.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born
2023-10-09 09:20:08 +02:00
committed by GitHub
parent 2794c973d3
commit 09b3160a55
93 changed files with 294 additions and 471 deletions
@@ -19,7 +19,6 @@ import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -144,7 +143,7 @@ public class BundleInfoReader {
if (Files.exists(modulePath)) {
try (Stream<Path> files = Files.walk(modulePath)) {
List<JsonObject> moduleTypes = files.filter(isJsonFile).flatMap(this::readJsonElementsFromFile)
.map(JsonElement::getAsJsonObject).collect(Collectors.toList());
.map(JsonElement::getAsJsonObject).toList();
if (!moduleTypes.isEmpty()) {
bundleInfo.setModuleTypesJson(moduleTypes);
}
@@ -157,7 +156,7 @@ public class BundleInfoReader {
if (Files.exists(template)) {
try (Stream<Path> files = Files.walk(template)) {
List<JsonObject> ruleTemplates = files.filter(isJsonFile).flatMap(this::readJsonElementsFromFile)
.map(JsonElement::getAsJsonObject).collect(Collectors.toList());
.map(JsonElement::getAsJsonObject).toList();
if (!ruleTemplates.isEmpty()) {
bundleInfo.setRuleTemplateJson(ruleTemplates);
}