Polish Stream#toList() consistent usage
In general, `Stream#toList()` is not a transparent replacement for `.collect(Collectors.toList()))`, as the former returns an immutable list. This commit reverts some of those changes, where the returned `List` instance was expected to be mutable. See gh-29203
This commit is contained in:
parent
641303baff
commit
9c400ed384
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
|
|
@ -279,7 +280,7 @@ public abstract class MimeTypeUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the comma-separated string into a list of {@code MimeType} objects.
|
* Parse the comma-separated string into a mutable list of {@code MimeType} objects.
|
||||||
* @param mimeTypes the string to parse
|
* @param mimeTypes the string to parse
|
||||||
* @return the list of mime types
|
* @return the list of mime types
|
||||||
* @throws InvalidMimeTypeException if the string cannot be parsed
|
* @throws InvalidMimeTypeException if the string cannot be parsed
|
||||||
|
|
@ -291,7 +292,7 @@ public abstract class MimeTypeUtils {
|
||||||
return tokenize(mimeTypes).stream()
|
return tokenize(mimeTypes).stream()
|
||||||
.filter(StringUtils::hasText)
|
.filter(StringUtils::hasText)
|
||||||
.map(MimeTypeUtils::parseMimeType)
|
.map(MimeTypeUtils::parseMimeType)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import io.micrometer.observation.Observation;
|
import io.micrometer.observation.Observation;
|
||||||
|
|
@ -970,7 +971,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||||
.filter(converter -> canReadResponse(this.responseType, converter))
|
.filter(converter -> canReadResponse(this.responseType, converter))
|
||||||
.flatMap((HttpMessageConverter<?> converter) -> getSupportedMediaTypes(this.responseType, converter))
|
.flatMap((HttpMessageConverter<?> converter) -> getSupportedMediaTypes(this.responseType, converter))
|
||||||
.distinct()
|
.distinct()
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
MimeTypeUtils.sortBySpecificity(allSupportedMediaTypes);
|
MimeTypeUtils.sortBySpecificity(allSupportedMediaTypes);
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Accept=" + allSupportedMediaTypes);
|
logger.debug("Accept=" + allSupportedMediaTypes);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2021 the original author or authors.
|
* Copyright 2002-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
@ -135,7 +136,7 @@ public class CorsConfiguration {
|
||||||
*/
|
*/
|
||||||
public void setAllowedOrigins(@Nullable List<String> origins) {
|
public void setAllowedOrigins(@Nullable List<String> origins) {
|
||||||
this.allowedOrigins = (origins == null ? null :
|
this.allowedOrigins = (origins == null ? null :
|
||||||
origins.stream().filter(Objects::nonNull).map(this::trimTrailingSlash).toList());
|
origins.stream().filter(Objects::nonNull).map(this::trimTrailingSlash).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String trimTrailingSlash(String origin) {
|
private String trimTrailingSlash(String origin) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue