Browse Source

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

pull/28542/head
Sam Brannen 4 years ago
parent
commit
720261db26
  1. 4
      spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java
  2. 2
      spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java
  3. 6
      spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java
  4. 7
      spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java
  5. 5
      spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
  6. 5
      spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java
  7. 3
      spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java
  8. 4
      spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java
  9. 3
      spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java
  10. 4
      spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java
  11. 3
      spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java

4
spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

@ -1,5 +1,5 @@ @@ -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 { @@ -97,7 +97,7 @@ public abstract class YamlProcessor {
* </pre>
*/
public void setDocumentMatchers(DocumentMatcher... matchers) {
this.documentMatchers = Arrays.asList(matchers);
this.documentMatchers = List.of(matchers);
}
/**

2
spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java

@ -552,7 +552,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp @@ -552,7 +552,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
constructorArgs[i] = manageMapIfNecessary(map);
}
}
return Arrays.asList(constructorArgs);
return List.of(constructorArgs);
}
/**

6
spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java vendored

@ -1,5 +1,5 @@ @@ -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; @@ -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;
* }
* }</pre>
@ -116,7 +116,7 @@ import org.springframework.core.Ordered; @@ -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;
* }
*

7
spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java vendored

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -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);
}

5
spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 @@ -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<Method, Set<Scheduled>> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
(MethodIntrospector.MetadataLookup<Set<Scheduled>>) method -> {
Set<Scheduled> scheduledAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(

5
spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java

@ -1,5 +1,5 @@ @@ -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; @@ -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<String> { @@ -64,7 +63,7 @@ public final class StringDecoder extends AbstractDataBufferDecoder<String> {
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<String> DEFAULT_DELIMITERS = Arrays.asList("\r\n", "\n");
public static final List<String> DEFAULT_DELIMITERS = List.of("\r\n", "\n");
private final List<String> delimiters;

3
spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java

@ -17,7 +17,6 @@ @@ -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 { @@ -94,7 +93,7 @@ public class MockFilterChain implements FilterChain {
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
return Arrays.asList(allFilters);
return List.of(allFilters);
}

4
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java

@ -1,5 +1,5 @@ @@ -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 @@ -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<Class<? extends Annotation>> 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

3
spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java

@ -20,7 +20,6 @@ import java.net.URI; @@ -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 { @@ -59,7 +58,7 @@ public class ExchangeResult {
private static final Log logger = LogFactory.getLog(ExchangeResult.class);
private static final List<MediaType> PRINTABLE_MEDIA_TYPES = Arrays.asList(
private static final List<MediaType> PRINTABLE_MEDIA_TYPES = List.of(
MediaType.parseMediaType("application/*+json"), MediaType.APPLICATION_XML,
MediaType.parseMediaType("text/*"), MediaType.APPLICATION_FORM_URLENCODED);

4
spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java

@ -19,8 +19,8 @@ package org.springframework.transaction.annotation; @@ -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 @@ -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<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
for (Class<?> rbRule : attributes.getClassArray("rollbackFor")) {

3
spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java

@ -17,7 +17,6 @@ @@ -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 { @@ -94,7 +93,7 @@ public class MockFilterChain implements FilterChain {
private static List<Filter> initFilterList(Servlet servlet, Filter... filters) {
Filter[] allFilters = ObjectUtils.addObjectToArray(filters, new ServletFilterProxy(servlet));
return Arrays.asList(allFilters);
return List.of(allFilters);
}

Loading…
Cancel
Save