Use List.of() and Set.of() where feasible.

Closes #3231
This commit is contained in:
Yanming Zhou
2025-01-08 17:19:31 +08:00
committed by Mark Paluch
parent 95d9637edc
commit b4d2391cdb
10 changed files with 12 additions and 23 deletions

View File

@@ -28,7 +28,6 @@ import java.time.Period;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -48,7 +47,7 @@ import org.springframework.lang.NonNull;
*/
public abstract class Jsr310Converters {
private static final List<Class<?>> CLASSES = Arrays.asList(LocalDateTime.class, LocalDate.class, LocalTime.class,
private static final List<Class<?>> CLASSES = List.of(LocalDateTime.class, LocalDate.class, LocalTime.class,
Instant.class, ZoneId.class, Duration.class, Period.class);
/**

View File

@@ -19,7 +19,6 @@ import static java.lang.String.*;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
@@ -44,7 +43,7 @@ import org.springframework.util.Assert;
*/
public abstract class Parameters<S extends Parameters<S, T>, T extends Parameter> implements Streamable<T> {
public static final List<Class<?>> TYPES = Arrays.asList(ScrollPosition.class, Pageable.class, Sort.class,
public static final List<Class<?>> TYPES = List.of(ScrollPosition.class, Pageable.class, Sort.class,
Limit.class);
private static final String PARAM_ON_SPECIAL = format("You must not use @%s on a parameter typed %s or %s",

View File

@@ -17,9 +17,7 @@ package org.springframework.data.repository.query;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -229,7 +227,7 @@ public abstract class ReturnedType {
*/
private static final class ReturnedClass extends ReturnedType {
private static final Set<Class<?>> VOID_TYPES = new HashSet<>(Arrays.asList(Void.class, void.class));
private static final Set<Class<?>> VOID_TYPES = Set.of(Void.class, void.class);
private final Class<?> type;
private final boolean isDto;

View File

@@ -16,7 +16,6 @@
package org.springframework.data.repository.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -301,7 +300,7 @@ public class SpelQueryContext {
*/
static class QuotationMap {
private static final Collection<Character> QUOTING_CHARACTERS = Arrays.asList('"', '\'');
private static final Collection<Character> QUOTING_CHARACTERS = List.of('"', '\'');
private final List<Range<Integer>> quotedRanges = new ArrayList<>();

View File

@@ -16,7 +16,6 @@
package org.springframework.data.repository.query;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -345,7 +344,7 @@ public class ValueExpressionQueryRewriter {
*/
static class QuotationMap {
private static final Collection<Character> QUOTING_CHARACTERS = Arrays.asList('"', '\'');
private static final Collection<Character> QUOTING_CHARACTERS = List.of('"', '\'');
private final List<Range<Integer>> quotedRanges = new ArrayList<>();

View File

@@ -16,8 +16,6 @@
package org.springframework.data.repository.query.parser;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@@ -46,7 +44,7 @@ class OrderBySource {
private static final String BLOCK_SPLIT = "(?<=Asc|Desc)(?=\\p{Lu})";
private static final Pattern DIRECTION_SPLIT = Pattern.compile("(.+?)(Asc|Desc)?$");
private static final String INVALID_ORDER_SYNTAX = "Invalid order syntax for part %s";
private static final Set<String> DIRECTION_KEYWORDS = new HashSet<>(Arrays.asList("Asc", "Desc"));
private static final Set<String> DIRECTION_KEYWORDS = Set.of("Asc", "Desc");
private final List<Order> orders;

View File

@@ -189,7 +189,7 @@ public class Part {
// Need to list them again explicitly as the order is important
// (esp. for IS_NULL, IS_NOT_NULL)
private static final List<Part.Type> ALL = Arrays.asList(IS_NOT_NULL, IS_NULL, BETWEEN, LESS_THAN, LESS_THAN_EQUAL,
private static final List<Part.Type> ALL = List.of(IS_NOT_NULL, IS_NULL, BETWEEN, LESS_THAN, LESS_THAN_EQUAL,
GREATER_THAN, GREATER_THAN_EQUAL, BEFORE, AFTER, NOT_LIKE, LIKE, STARTING_WITH, ENDING_WITH, IS_NOT_EMPTY,
IS_EMPTY, NOT_CONTAINING, CONTAINING, NOT_IN, IN, NEAR, WITHIN, REGEX, EXISTS, TRUE, FALSE,
NEGATING_SIMPLE_PROPERTY, SIMPLE_PROPERTY);

View File

@@ -20,8 +20,6 @@ import java.lang.annotation.ElementType;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -89,8 +87,8 @@ public abstract class NullableUtils {
private static final Set<Class<?>> NON_NULLABLE_ANNOTATIONS = findClasses("reactor.util.lang.NonNullApi",
NonNullApi.class.getName());
private static final Set<String> WHEN_NULLABLE = new HashSet<>(Arrays.asList("UNKNOWN", "MAYBE", "NEVER"));
private static final Set<String> WHEN_NON_NULLABLE = new HashSet<>(Collections.singletonList("ALWAYS"));
private static final Set<String> WHEN_NULLABLE = Set.of("UNKNOWN", "MAYBE", "NEVER");
private static final Set<String> WHEN_NON_NULLABLE = Set.of("ALWAYS");
private NullableUtils() {}

View File

@@ -45,10 +45,9 @@ public class TypeCollector {
private static final Log logger = LogFactory.getLog(TypeCollector.class);
static final Set<String> EXCLUDED_DOMAINS = new HashSet<>(
Arrays.asList("java", "sun.", "jdk.", "reactor.", "kotlinx.", "kotlin.", "org.springframework.core.",
static final Set<String> EXCLUDED_DOMAINS = Set.of("java", "sun.", "jdk.", "reactor.", "kotlinx.", "kotlin.", "org.springframework.core.",
"org.springframework.data.mapping.", "org.springframework.data.repository.", "org.springframework.boot.",
"org.springframework.context.", "org.springframework.beans."));
"org.springframework.context.", "org.springframework.beans.");
private final Predicate<Class<?>> excludedDomainsFilter = type -> {
String packageName = type.getPackageName() + ".";

View File

@@ -46,7 +46,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
public class ProxyingHandlerMethodArgumentResolver extends ModelAttributeMethodProcessor
implements BeanFactoryAware, BeanClassLoaderAware {
private static final List<String> IGNORED_PACKAGES = Arrays.asList("java", "org.springframework");
private static final List<String> IGNORED_PACKAGES = List.of("java", "org.springframework");
private final SpelAwareProxyProjectionFactory proxyFactory;
private final ObjectFactory<ConversionService> conversionService;