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:
@@ -19,7 +19,6 @@ package org.springframework.boot.configurationprocessor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
@@ -69,8 +68,7 @@ class ConstructorParameterPropertyDescriptor extends PropertyDescriptor<Variable
|
||||
if (defaultValue.size() == 1) {
|
||||
return coerceValue(specificType, defaultValue.get(0));
|
||||
}
|
||||
return defaultValue.stream().map((value) -> coerceValue(specificType, value))
|
||||
.collect(Collectors.toList());
|
||||
return defaultValue.stream().map((value) -> coerceValue(specificType, value)).toList();
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
environment.getMessager().printMessage(Kind.ERROR, ex.getMessage(), element, annotation);
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
@@ -202,7 +201,7 @@ class PropertyDescriptorResolver {
|
||||
if (bindConstructor != null) {
|
||||
return Collections.singletonList(bindConstructor);
|
||||
}
|
||||
return constructors.stream().filter(env::hasConstructorBindingAnnotation).collect(Collectors.toList());
|
||||
return constructors.stream().filter(env::hasConstructorBindingAnnotation).toList();
|
||||
}
|
||||
|
||||
private static ExecutableElement deduceBindConstructor(List<ExecutableElement> constructors,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -21,7 +21,6 @@ import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.boot.configurationprocessor.json.JSONArray;
|
||||
import org.springframework.boot.configurationprocessor.json.JSONObject;
|
||||
@@ -40,7 +39,7 @@ class JsonConverter {
|
||||
JSONArray toJsonArray(ConfigurationMetadata metadata, ItemType itemType) throws Exception {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.isOfItemType(itemType))
|
||||
.sorted(ITEM_COMPARATOR).collect(Collectors.toList());
|
||||
.sorted(ITEM_COMPARATOR).toList();
|
||||
for (ItemMetadata item : items) {
|
||||
if (item.isOfItemType(itemType)) {
|
||||
jsonArray.put(toJsonObject(item));
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.boot.configurationprocessor;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@@ -223,7 +222,7 @@ class ConstructorParameterPropertyDescriptorTests extends PropertyDescriptorTest
|
||||
|
||||
private VariableElement getConstructorParameter(TypeElement ownerElement, String name) {
|
||||
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements()).stream()
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty()).collect(Collectors.toList());
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty()).toList();
|
||||
if (constructors.size() != 1) {
|
||||
throw new IllegalStateException("No candidate constructor for " + ownerElement);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -87,7 +86,7 @@ class MergeMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
SimpleConflictingProperties.class);
|
||||
assertThat(metadata.getItems()).hasSize(6);
|
||||
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
assertThat(items).hasSize(2);
|
||||
ItemMetadata matchingProperty = items.stream().filter((item) -> item.getType().equals(Boolean.class.getName()))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.hamcrest.collection.IsMapContaining;
|
||||
@@ -210,8 +209,7 @@ public final class Metadata {
|
||||
|
||||
private ItemMetadata findItem(ConfigurationMetadata metadata, String name) {
|
||||
List<ItemMetadata> candidates = metadata.getItems().stream()
|
||||
.filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName()))
|
||||
.collect(Collectors.toList());
|
||||
.filter((item) -> item.isOfItemType(this.itemType) && name.equals(item.getName())).toList();
|
||||
if (candidates.size() > 1) {
|
||||
throw new IllegalStateException("More than one metadata item with name '" + name + "': " + candidates);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user