Browse Source

Use Set.of instead of HashSet with Arrays.asList

pull/28427/head
Juergen Hoeller 3 years ago
parent
commit
2b65f274dc
  1. 6
      spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java
  2. 3
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  3. 8
      spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java
  4. 8
      spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java
  5. 2
      spring-core/src/main/java/org/springframework/util/ClassUtils.java
  6. 15
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java
  7. 17
      spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java
  8. 15
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java
  9. 6
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java
  10. 3
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java

6
spring-context-indexer/src/main/java/org/springframework/context/index/processor/PropertiesMarshaller.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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,8 +19,6 @@ package org.springframework.context.index.processor; @@ -19,8 +19,6 @@ package org.springframework.context.index.processor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@ -44,7 +42,7 @@ abstract class PropertiesMarshaller { @@ -44,7 +42,7 @@ abstract class PropertiesMarshaller {
Properties props = new Properties();
props.load(in);
props.forEach((type, value) -> {
Set<String> candidates = new HashSet<>(Arrays.asList(((String) value).split(",")));
Set<String> candidates = Set.of(((String) value).split(","));
result.add(new ItemMetadata((String) type, candidates));
});
return result;

3
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
package org.springframework.context.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@ -371,7 +370,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo @@ -371,7 +370,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
candidates.clear();
if (registry.getBeanDefinitionCount() > candidateNames.length) {
String[] newCandidateNames = registry.getBeanDefinitionNames();
Set<String> oldCandidateNames = new HashSet<>(Arrays.asList(candidateNames));
Set<String> oldCandidateNames = Set.of(candidateNames);
Set<String> alreadyParsedClasses = new HashSet<>();
for (ConfigurationClass configurationClass : alreadyParsed) {
alreadyParsedClasses.add(configurationClass.getMetadata().getClassName());

8
spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java

@ -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.
@ -17,10 +17,8 @@ @@ -17,10 +17,8 @@
package org.springframework.jmx.export.assembler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -72,7 +70,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean @@ -72,7 +70,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
* @see #setIgnoredMethodMappings(java.util.Properties)
*/
public void setIgnoredMethods(String... ignoredMethodNames) {
this.ignoredMethods = new HashSet<>(Arrays.asList(ignoredMethodNames));
this.ignoredMethods = Set.of(ignoredMethodNames);
}
/**
@ -87,7 +85,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean @@ -87,7 +85,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.ignoredMethodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames)));
this.ignoredMethodMappings.put(beanKey, Set.of(methodNames));
}
}

8
spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -17,10 +17,8 @@ @@ -17,10 +17,8 @@
package org.springframework.jmx.export.assembler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -76,7 +74,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean @@ -76,7 +74,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
* @see #setMethodMappings
*/
public void setManagedMethods(String... methodNames) {
this.managedMethods = new HashSet<>(Arrays.asList(methodNames));
this.managedMethods = Set.of(methodNames);
}
/**
@ -91,7 +89,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean @@ -91,7 +89,7 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean
for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.methodMappings.put(beanKey, new HashSet<>(Arrays.asList(methodNames)));
this.methodMappings.put(beanKey, Set.of(methodNames));
}
}

2
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -157,7 +157,7 @@ public abstract class ClassUtils { @@ -157,7 +157,7 @@ public abstract class ClassUtils {
Class<?>[] javaLanguageInterfaceArray = {Serializable.class, Externalizable.class,
Closeable.class, AutoCloseable.class, Cloneable.class, Comparable.class};
registerCommonClasses(javaLanguageInterfaceArray);
javaLanguageInterfaces = new HashSet<>(Arrays.asList(javaLanguageInterfaceArray));
javaLanguageInterfaces = Set.of(javaLanguageInterfaceArray);
}

15
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.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.
@ -22,7 +22,6 @@ import java.security.Principal; @@ -22,7 +22,6 @@ import java.security.Principal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -73,6 +72,7 @@ public abstract class RequestPredicates { @@ -73,6 +72,7 @@ public abstract class RequestPredicates {
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
/**
* Return a {@code RequestPredicate} that always matches.
* @return a predicate that always matches
@ -537,7 +537,6 @@ public abstract class RequestPredicates { @@ -537,7 +537,6 @@ public abstract class RequestPredicates {
public String toString() {
return this.pattern.getPatternString();
}
}
@ -566,12 +565,13 @@ public abstract class RequestPredicates { @@ -566,12 +565,13 @@ public abstract class RequestPredicates {
}
}
private static class ContentTypePredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public ContentTypePredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private ContentTypePredicate(Set<MediaType> mediaTypes) {
@ -603,12 +603,13 @@ public abstract class RequestPredicates { @@ -603,12 +603,13 @@ public abstract class RequestPredicates {
}
}
private static class AcceptPredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public AcceptPredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private AcceptPredicate(Set<MediaType> mediaTypes) {
@ -698,7 +699,6 @@ public abstract class RequestPredicates { @@ -698,7 +699,6 @@ public abstract class RequestPredicates {
this.extension :
this.extensionPredicate);
}
}
@ -809,6 +809,7 @@ public abstract class RequestPredicates { @@ -809,6 +809,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} that negates a delegate predicate.
*/
@ -851,6 +852,7 @@ public abstract class RequestPredicates { @@ -851,6 +852,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} where either {@code left} or {@code right} predicates
* may match.
@ -1094,7 +1096,6 @@ public abstract class RequestPredicates { @@ -1094,7 +1096,6 @@ public abstract class RequestPredicates {
public String toString() {
return method() + " " + path();
}
}
}

17
spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.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.
@ -24,7 +24,6 @@ import java.time.Instant; @@ -24,7 +24,6 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@ -73,6 +72,7 @@ public abstract class RequestPredicates { @@ -73,6 +72,7 @@ public abstract class RequestPredicates {
private static final Log logger = LogFactory.getLog(RequestPredicates.class);
/**
* Return a {@code RequestPredicate} that always matches.
* @return a predicate that always matches
@ -535,7 +535,6 @@ public abstract class RequestPredicates { @@ -535,7 +535,6 @@ public abstract class RequestPredicates {
public String toString() {
return this.pattern.getPatternString();
}
}
@ -564,12 +563,13 @@ public abstract class RequestPredicates { @@ -564,12 +563,13 @@ public abstract class RequestPredicates {
}
}
private static class ContentTypePredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public ContentTypePredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private ContentTypePredicate(Set<MediaType> mediaTypes) {
@ -601,12 +601,13 @@ public abstract class RequestPredicates { @@ -601,12 +601,13 @@ public abstract class RequestPredicates {
}
}
private static class AcceptPredicate extends HeadersPredicate {
private final Set<MediaType> mediaTypes;
public AcceptPredicate(MediaType... mediaTypes) {
this(new HashSet<>(Arrays.asList(mediaTypes)));
this(Set.of(mediaTypes));
}
private AcceptPredicate(Set<MediaType> mediaTypes) {
@ -696,7 +697,6 @@ public abstract class RequestPredicates { @@ -696,7 +697,6 @@ public abstract class RequestPredicates {
this.extension :
this.extensionPredicate);
}
}
@ -807,6 +807,7 @@ public abstract class RequestPredicates { @@ -807,6 +807,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} that negates a delegate predicate.
*/
@ -849,6 +850,7 @@ public abstract class RequestPredicates { @@ -849,6 +850,7 @@ public abstract class RequestPredicates {
}
}
/**
* {@link RequestPredicate} where either {@code left} or {@code right} predicates
* may match.
@ -1053,8 +1055,6 @@ public abstract class RequestPredicates { @@ -1053,8 +1055,6 @@ public abstract class RequestPredicates {
return this.request.session();
}
@Override
public Optional<Principal> principal() {
return this.request.principal();
@ -1084,7 +1084,6 @@ public abstract class RequestPredicates { @@ -1084,7 +1084,6 @@ public abstract class RequestPredicates {
public String toString() {
return method() + " " + path();
}
}
}

15
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.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.web.servlet.mvc.method.annotation; @@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.method.annotation;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -77,19 +76,19 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe @@ -77,19 +76,19 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
implements HandlerMethodReturnValueHandler {
/* Extensions associated with the built-in message converters */
private static final Set<String> SAFE_EXTENSIONS = new HashSet<>(Arrays.asList(
private static final Set<String> SAFE_EXTENSIONS = Set.of(
"txt", "text", "yml", "properties", "csv",
"json", "xml", "atom", "rss",
"png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp"));
"png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp");
private static final Set<String> SAFE_MEDIA_BASE_TYPES = new HashSet<>(
Arrays.asList("audio", "image", "video"));
private static final Set<String> SAFE_MEDIA_BASE_TYPES =
Set.of("audio", "image", "video");
private static final List<MediaType> ALL_APPLICATION_MEDIA_TYPES =
Arrays.asList(MediaType.ALL, new MediaType("application"));
List.of(MediaType.ALL, new MediaType("application"));
private static final Type RESOURCE_REGION_LIST_TYPE =
new ParameterizedTypeReference<List<ResourceRegion>>() { }.getType();
new ParameterizedTypeReference<List<ResourceRegion>>() {}.getType();
private final ContentNegotiationManager contentNegotiationManager;

6
spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -18,9 +18,7 @@ package org.springframework.web.servlet.view; @@ -18,9 +18,7 @@ package org.springframework.web.servlet.view;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@ -273,7 +271,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement @@ -273,7 +271,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* flag on but do not list specific bean names for this property.
*/
public void setExposedContextBeanNames(String... exposedContextBeanNames) {
this.exposedContextBeanNames = new HashSet<>(Arrays.asList(exposedContextBeanNames));
this.exposedContextBeanNames = Set.of(exposedContextBeanNames);
}
/**

3
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java

@ -20,7 +20,6 @@ import java.io.IOException; @@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -81,7 +80,7 @@ public abstract class AbstractSockJsSession implements SockJsSession { @@ -81,7 +80,7 @@ public abstract class AbstractSockJsSession implements SockJsSession {
* @see #indicatesDisconnectedClient(Throwable)
*/
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS =
new HashSet<>(Arrays.asList("ClientAbortException", "EOFException", "EofException"));
Set.of("ClientAbortException", "EOFException", "EofException");
/**

Loading…
Cancel
Save