Replace Collectors.toList with Stream.toList

Closes gh-29203
This commit is contained in:
Adam Ostrožlík
2022-09-26 14:04:43 +02:00
committed by Brian Clozel
parent 9d263668d5
commit 0ccb64fe10
49 changed files with 62 additions and 106 deletions

View File

@@ -66,7 +66,7 @@ public class GenericConversionServiceBenchmark {
@Setup(Level.Trial)
public void setup() throws Exception {
this.source = IntStream.rangeClosed(1, collectionSize).mapToObj(String::valueOf).collect(Collectors.toList());
this.source = IntStream.rangeClosed(1, collectionSize).mapToObj(String::valueOf).toList();
List<Integer> target = new ArrayList<>();
this.targetTypeDesc = TypeDescriptor.forObject(target);
}

View File

@@ -19,7 +19,6 @@ package org.springframework.core;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
import java.util.stream.Collectors;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
@@ -77,7 +76,7 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
.stream()
// Extension receivers of extension methods must be included as they appear as normal method parameters in Java
.filter(p -> KParameter.Kind.VALUE.equals(p.getKind()) || KParameter.Kind.EXTENSION_RECEIVER.equals(p.getKind()))
.collect(Collectors.toList());
.toList();
String[] parameterNames = new String[filteredParameters.size()];
for (int i = 0; i < filteredParameters.size(); i++) {
KParameter parameter = filteredParameters.get(i);

View File

@@ -29,7 +29,6 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import org.springframework.lang.Nullable;
@@ -292,7 +291,7 @@ public abstract class MimeTypeUtils {
return tokenize(mimeTypes).stream()
.filter(StringUtils::hasText)
.map(MimeTypeUtils::parseMimeType)
.collect(Collectors.toList());
.toList();
}
/**

View File

@@ -22,7 +22,6 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
@@ -95,7 +94,7 @@ class MergedAnnotationPredicatesTests {
List<MergedAnnotation<TestAnnotation>> filtered = MergedAnnotations.from(
WithMultipleTestAnnotation.class).stream(TestAnnotation.class).filter(
MergedAnnotationPredicates.firstRunOf(
this::firstCharOfValue)).collect(Collectors.toList());
this::firstCharOfValue)).toList();
assertThat(filtered.stream().map(
annotation -> annotation.getString("value"))).containsExactly("a1", "a2", "a3");
}
@@ -111,7 +110,7 @@ class MergedAnnotationPredicatesTests {
List<MergedAnnotation<TestAnnotation>> filtered = MergedAnnotations.from(
WithMultipleTestAnnotation.class).stream(TestAnnotation.class).filter(
MergedAnnotationPredicates.unique(
this::firstCharOfValue)).collect(Collectors.toList());
this::firstCharOfValue)).toList();
assertThat(filtered.stream().map(
annotation -> annotation.getString("value"))).containsExactly("a1", "b1", "c1");
}

View File

@@ -33,7 +33,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import jakarta.annotation.Resource;
@@ -1896,7 +1895,7 @@ class MergedAnnotationsTests {
Adapt.ANNOTATION_TO_MAP);
Map<String, Object>[] filters = (Map[]) map.get("excludeFilters");
List<String> patterns = Arrays.stream(filters).map(
m -> (String) m.get("pattern")).collect(Collectors.toList());
m -> (String) m.get("pattern")).toList();
assertThat(patterns).containsExactly("*Foo", "*Bar");
filters[0].put("pattern", "newFoo");
filters[0].put("enigma", 42);

View File

@@ -22,7 +22,6 @@ import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import io.netty.buffer.PooledByteBufAllocator;
import org.apache.commons.logging.Log;
@@ -140,7 +139,7 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
// Remove LeakAwareDataBuffer wrapper so delegate can find native buffers
dataBuffers = dataBuffers.stream()
.map(o -> o instanceof LeakAwareDataBuffer ? ((LeakAwareDataBuffer) o).dataBuffer() : o)
.collect(Collectors.toList());
.toList();
return new LeakAwareDataBuffer(this.delegate.join(dataBuffers), this);
}