Browse Source

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

Closes #3231
pull/3277/head
Yanming Zhou 1 year ago committed by Mark Paluch
parent
commit
b4d2391cdb
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 3
      src/main/java/org/springframework/data/convert/Jsr310Converters.java
  2. 3
      src/main/java/org/springframework/data/repository/query/Parameters.java
  3. 4
      src/main/java/org/springframework/data/repository/query/ReturnedType.java
  4. 3
      src/main/java/org/springframework/data/repository/query/SpelQueryContext.java
  5. 3
      src/main/java/org/springframework/data/repository/query/ValueExpressionQueryRewriter.java
  6. 4
      src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java
  7. 2
      src/main/java/org/springframework/data/repository/query/parser/Part.java
  8. 6
      src/main/java/org/springframework/data/util/NullableUtils.java
  9. 5
      src/main/java/org/springframework/data/util/TypeCollector.java
  10. 2
      src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java

3
src/main/java/org/springframework/data/convert/Jsr310Converters.java

@ -28,7 +28,6 @@ import java.time.Period; @@ -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; @@ -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);
/**

3
src/main/java/org/springframework/data/repository/query/Parameters.java

@ -19,7 +19,6 @@ import static java.lang.String.*; @@ -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; @@ -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",

4
src/main/java/org/springframework/data/repository/query/ReturnedType.java

@ -17,9 +17,7 @@ package org.springframework.data.repository.query; @@ -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 { @@ -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;

3
src/main/java/org/springframework/data/repository/query/SpelQueryContext.java

@ -16,7 +16,6 @@ @@ -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 { @@ -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<>();

3
src/main/java/org/springframework/data/repository/query/ValueExpressionQueryRewriter.java

@ -16,7 +16,6 @@ @@ -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 { @@ -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<>();

4
src/main/java/org/springframework/data/repository/query/parser/OrderBySource.java

@ -16,8 +16,6 @@ @@ -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 { @@ -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;

2
src/main/java/org/springframework/data/repository/query/parser/Part.java

@ -189,7 +189,7 @@ public class Part { @@ -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);

6
src/main/java/org/springframework/data/util/NullableUtils.java

@ -20,8 +20,6 @@ import java.lang.annotation.ElementType; @@ -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 { @@ -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() {}

5
src/main/java/org/springframework/data/util/TypeCollector.java

@ -45,10 +45,9 @@ public class TypeCollector { @@ -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() + ".";

2
src/main/java/org/springframework/data/web/ProxyingHandlerMethodArgumentResolver.java

@ -46,7 +46,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -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;

Loading…
Cancel
Save