From 720261db26ea917cd979bbac2cd7db1ff70928ee Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 30 May 2022 18:26:06 +0200 Subject: [PATCH] Use List.of() and Set.of() where feasible --- .../beans/factory/config/YamlProcessor.java | 4 ++-- .../beans/factory/groovy/GroovyBeanDefinitionReader.java | 2 +- .../springframework/cache/annotation/EnableCaching.java | 6 +++--- .../cache/interceptor/NamedCacheResolver.java | 7 +++---- .../annotation/ScheduledAnnotationBeanPostProcessor.java | 5 ++--- .../java/org/springframework/core/codec/StringDecoder.java | 5 ++--- .../java/org/springframework/mock/web/MockFilterChain.java | 3 +-- .../test/context/junit/jupiter/SpringExtension.java | 4 ++-- .../test/web/reactive/server/ExchangeResult.java | 3 +-- .../annotation/SpringTransactionAnnotationParser.java | 4 ++-- .../web/testfixture/servlet/MockFilterChain.java | 3 +-- 11 files changed, 20 insertions(+), 26 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java index 140370b5650..758e1afbcc7 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java @@ -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"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public abstract class YamlProcessor { * */ public void setDocumentMatchers(DocumentMatcher... matchers) { - this.documentMatchers = Arrays.asList(matchers); + this.documentMatchers = List.of(matchers); } /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java index 2b201f8767c..383e3c6d712 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java @@ -552,7 +552,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp constructorArgs[i] = manageMapIfNecessary(map); } } - return Arrays.asList(constructorArgs); + return List.of(constructorArgs); } /** diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java index 872f493edc0..126d3e0b74a 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java @@ -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"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ import org.springframework.core.Ordered; * public CacheManager cacheManager() { * // configure and return an implementation of Spring's CacheManager SPI * SimpleCacheManager cacheManager = new SimpleCacheManager(); - * cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("default"))); + * cacheManager.setCaches(Set.of(new ConcurrentMapCache("default"))); * return cacheManager; * } * } @@ -116,7 +116,7 @@ import org.springframework.core.Ordered; * public CacheManager cacheManager() { * // configure and return an implementation of Spring's CacheManager SPI * SimpleCacheManager cacheManager = new SimpleCacheManager(); - * cacheManager.setCaches(Arrays.asList(new ConcurrentMapCache("default"))); + * cacheManager.setCaches(Set.of(new ConcurrentMapCache("default"))); * return cacheManager; * } * diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java b/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java index 767c712d2e1..a8023cea59c 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-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. @@ -16,9 +16,8 @@ package org.springframework.cache.interceptor; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.List; import org.springframework.cache.CacheManager; import org.springframework.lang.Nullable; @@ -41,7 +40,7 @@ public class NamedCacheResolver extends AbstractCacheResolver { public NamedCacheResolver(CacheManager cacheManager, String... cacheNames) { super(cacheManager); - this.cacheNames = new ArrayList<>(Arrays.asList(cacheNames)); + this.cacheNames = List.of(cacheNames); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java index f0aae203468..cf833983c35 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java @@ -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"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.scheduling.annotation; import java.lang.reflect.Method; import java.time.Duration; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.IdentityHashMap; @@ -361,7 +360,7 @@ public class ScheduledAnnotationBeanPostProcessor Class targetClass = AopProxyUtils.ultimateTargetClass(bean); if (!this.nonAnnotatedClasses.contains(targetClass) && - AnnotationUtils.isCandidateClass(targetClass, Arrays.asList(Scheduled.class, Schedules.class))) { + AnnotationUtils.isCandidateClass(targetClass, List.of(Scheduled.class, Schedules.class))) { Map> annotatedMethods = MethodIntrospector.selectMethods(targetClass, (MethodIntrospector.MetadataLookup>) method -> { Set scheduledAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations( diff --git a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java index 5749d859eb3..cb74b8d2c4e 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java @@ -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"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -64,7 +63,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder { public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; /** The default delimiter strings to use, i.e. {@code \r\n} and {@code \n}. */ - public static final List DEFAULT_DELIMITERS = Arrays.asList("\r\n", "\n"); + public static final List DEFAULT_DELIMITERS = List.of("\r\n", "\n"); private final List delimiters; diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java index f475838d6a5..2a48a42e5ed 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java @@ -17,7 +17,6 @@ package org.springframework.mock.web; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -94,7 +93,7 @@ public class MockFilterChain implements FilterChain { private static List initFilterList(Servlet servlet, Filter... filters) { Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet)); - return Arrays.asList(allFilters); + return List.of(allFilters); } diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java index 8861c5e3621..f9ba801e824 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java @@ -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"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes // Note that @Test, @TestFactory, @TestTemplate, @RepeatedTest, and @ParameterizedTest // are all meta-annotated with @Testable. private static final List> JUPITER_ANNOTATION_TYPES = - Arrays.asList(BeforeAll.class, AfterAll.class, BeforeEach.class, AfterEach.class, Testable.class); + List.of(BeforeAll.class, AfterAll.class, BeforeEach.class, AfterEach.class, Testable.class); private static final MethodFilter autowiredTestOrLifecycleMethodFilter = ReflectionUtils.USER_DECLARED_METHODS diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java index 650e3c20b13..4d07adfca38 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java @@ -20,7 +20,6 @@ import java.net.URI; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.time.Duration; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -59,7 +58,7 @@ public class ExchangeResult { private static final Log logger = LogFactory.getLog(ExchangeResult.class); - private static final List PRINTABLE_MEDIA_TYPES = Arrays.asList( + private static final List PRINTABLE_MEDIA_TYPES = List.of( MediaType.parseMediaType("application/*+json"), MediaType.APPLICATION_XML, MediaType.parseMediaType("text/*"), MediaType.APPLICATION_FORM_URLENCODED); diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java index c8148c735d1..01db4e6e010 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java @@ -19,8 +19,8 @@ package org.springframework.transaction.annotation; import java.io.Serializable; import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import java.util.Set; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAttributes; @@ -81,7 +81,7 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP rbta.setReadOnly(attributes.getBoolean("readOnly")); rbta.setQualifier(attributes.getString("value")); - rbta.setLabels(Arrays.asList(attributes.getStringArray("label"))); + rbta.setLabels(Set.of(attributes.getStringArray("label"))); List rollbackRules = new ArrayList<>(); for (Class rbRule : attributes.getClassArray("rollbackFor")) { diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java index 635471aa5ff..03ed3b0d3ea 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java @@ -17,7 +17,6 @@ package org.springframework.web.testfixture.servlet; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -94,7 +93,7 @@ public class MockFilterChain implements FilterChain { private static List initFilterList(Servlet servlet, Filter... filters) { Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet)); - return Arrays.asList(allFilters); + return List.of(allFilters); }