Use Set.of() for constant sets where appropriate
This commit is contained in:
parent
0c878d2d06
commit
917c41fd52
|
@ -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.
|
||||
|
@ -132,17 +132,17 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
private static final int STEP_REFERENCE_PCUT_BINDING = 7;
|
||||
private static final int STEP_FINISHED = 8;
|
||||
|
||||
private static final Set<String> singleValuedAnnotationPcds = new HashSet<>();
|
||||
private static final Set<String> singleValuedAnnotationPcds = Set.of(
|
||||
"@this",
|
||||
"@target",
|
||||
"@within",
|
||||
"@withincode",
|
||||
"@annotation");
|
||||
|
||||
private static final Set<String> nonReferencePointcutTokens = new HashSet<>();
|
||||
|
||||
|
||||
static {
|
||||
singleValuedAnnotationPcds.add("@this");
|
||||
singleValuedAnnotationPcds.add("@target");
|
||||
singleValuedAnnotationPcds.add("@within");
|
||||
singleValuedAnnotationPcds.add("@withincode");
|
||||
singleValuedAnnotationPcds.add("@annotation");
|
||||
|
||||
Set<PointcutPrimitive> pointcutPrimitives = PointcutParser.getAllSupportedPointcutPrimitives();
|
||||
for (PointcutPrimitive primitive : pointcutPrimitives) {
|
||||
nonReferencePointcutTokens.add(primitive.getName());
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.io.ObjectInputStream;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -85,21 +84,17 @@ import org.springframework.util.StringUtils;
|
|||
public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware {
|
||||
|
||||
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = new HashSet<>();
|
||||
|
||||
static {
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.ARGS);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.REFERENCE);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.THIS);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.TARGET);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.WITHIN);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ANNOTATION);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_WITHIN);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_ARGS);
|
||||
SUPPORTED_PRIMITIVES.add(PointcutPrimitive.AT_TARGET);
|
||||
}
|
||||
|
||||
private static final Set<PointcutPrimitive> SUPPORTED_PRIMITIVES = Set.of(
|
||||
PointcutPrimitive.EXECUTION,
|
||||
PointcutPrimitive.ARGS,
|
||||
PointcutPrimitive.REFERENCE,
|
||||
PointcutPrimitive.THIS,
|
||||
PointcutPrimitive.TARGET,
|
||||
PointcutPrimitive.WITHIN,
|
||||
PointcutPrimitive.AT_ANNOTATION,
|
||||
PointcutPrimitive.AT_WITHIN,
|
||||
PointcutPrimitive.AT_ARGS,
|
||||
PointcutPrimitive.AT_TARGET);
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AspectJExpressionPointcut.class);
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.context.annotation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -66,14 +65,12 @@ public abstract class ConfigurationClassUtils {
|
|||
|
||||
private static final Log logger = LogFactory.getLog(ConfigurationClassUtils.class);
|
||||
|
||||
private static final Set<String> candidateIndicators = new HashSet<>(8);
|
||||
private static final Set<String> candidateIndicators = Set.of(
|
||||
Component.class.getName(),
|
||||
ComponentScan.class.getName(),
|
||||
Import.class.getName(),
|
||||
ImportResource.class.getName());
|
||||
|
||||
static {
|
||||
candidateIndicators.add(Component.class.getName());
|
||||
candidateIndicators.add(ComponentScan.class.getName());
|
||||
candidateIndicators.add(Import.class.getName());
|
||||
candidateIndicators.add(ImportResource.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a configuration class proxy for the specified class.
|
||||
|
|
|
@ -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.
|
||||
|
@ -18,7 +18,6 @@ package org.springframework.validation.beanvalidation;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -66,13 +65,8 @@ import org.springframework.validation.SmartValidator;
|
|||
*/
|
||||
public class SpringValidatorAdapter implements SmartValidator, jakarta.validation.Validator {
|
||||
|
||||
private static final Set<String> internalAnnotationAttributes = new HashSet<>(4);
|
||||
private static final Set<String> internalAnnotationAttributes = Set.of("message", "groups", "payload");
|
||||
|
||||
static {
|
||||
internalAnnotationAttributes.add("message");
|
||||
internalAnnotationAttributes.add("groups");
|
||||
internalAnnotationAttributes.add("payload");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private jakarta.validation.Validator targetValidator;
|
||||
|
|
|
@ -55,34 +55,31 @@ import org.springframework.util.ReflectionUtils;
|
|||
*/
|
||||
public final class CollectionFactory {
|
||||
|
||||
private static final Set<Class<?>> approximableCollectionTypes = new HashSet<>();
|
||||
private static final Set<Class<?>> approximableCollectionTypes = Set.of(
|
||||
// Standard collection interfaces
|
||||
Collection.class,
|
||||
List.class,
|
||||
Set.class,
|
||||
SortedSet.class,
|
||||
NavigableSet.class,
|
||||
// Common concrete collection classes
|
||||
ArrayList.class,
|
||||
LinkedList.class,
|
||||
HashSet.class,
|
||||
LinkedHashSet.class,
|
||||
TreeSet.class,
|
||||
EnumSet.class);
|
||||
|
||||
private static final Set<Class<?>> approximableMapTypes = new HashSet<>();
|
||||
|
||||
|
||||
static {
|
||||
// Standard collection interfaces
|
||||
approximableCollectionTypes.add(Collection.class);
|
||||
approximableCollectionTypes.add(List.class);
|
||||
approximableCollectionTypes.add(Set.class);
|
||||
approximableCollectionTypes.add(SortedSet.class);
|
||||
approximableCollectionTypes.add(NavigableSet.class);
|
||||
approximableMapTypes.add(Map.class);
|
||||
approximableMapTypes.add(SortedMap.class);
|
||||
approximableMapTypes.add(NavigableMap.class);
|
||||
|
||||
// Common concrete collection classes
|
||||
approximableCollectionTypes.add(ArrayList.class);
|
||||
approximableCollectionTypes.add(LinkedList.class);
|
||||
approximableCollectionTypes.add(HashSet.class);
|
||||
approximableCollectionTypes.add(LinkedHashSet.class);
|
||||
approximableCollectionTypes.add(TreeSet.class);
|
||||
approximableCollectionTypes.add(EnumSet.class);
|
||||
approximableMapTypes.add(HashMap.class);
|
||||
approximableMapTypes.add(LinkedHashMap.class);
|
||||
approximableMapTypes.add(TreeMap.class);
|
||||
approximableMapTypes.add(EnumMap.class);
|
||||
}
|
||||
private static final Set<Class<?>> approximableMapTypes = Set.of(
|
||||
// Standard map interfaces
|
||||
Map.class,
|
||||
SortedMap.class,
|
||||
NavigableMap.class,
|
||||
// Common concrete map classes
|
||||
HashMap.class,
|
||||
LinkedHashMap.class,
|
||||
TreeMap.class,
|
||||
EnumMap.class);
|
||||
|
||||
|
||||
private CollectionFactory() {
|
||||
|
|
|
@ -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.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.jdbc.support;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
|
@ -46,45 +45,42 @@ import org.springframework.lang.Nullable;
|
|||
*/
|
||||
public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLExceptionTranslator {
|
||||
|
||||
private static final Set<String> BAD_SQL_GRAMMAR_CODES = new HashSet<>(8);
|
||||
private static final Set<String> BAD_SQL_GRAMMAR_CODES = Set.of(
|
||||
"07", // Dynamic SQL error
|
||||
"21", // Cardinality violation
|
||||
"2A", // Syntax error direct SQL
|
||||
"37", // Syntax error dynamic SQL
|
||||
"42", // General SQL syntax error
|
||||
"65" // Oracle: unknown identifier
|
||||
);
|
||||
|
||||
private static final Set<String> DATA_INTEGRITY_VIOLATION_CODES = new HashSet<>(8);
|
||||
private static final Set<String> DATA_INTEGRITY_VIOLATION_CODES = Set.of(
|
||||
"01", // Data truncation
|
||||
"02", // No data found
|
||||
"22", // Value out of range
|
||||
"23", // Integrity constraint violation
|
||||
"27", // Triggered data change violation
|
||||
"44" // With check violation
|
||||
);
|
||||
|
||||
private static final Set<String> DATA_ACCESS_RESOURCE_FAILURE_CODES = new HashSet<>(8);
|
||||
private static final Set<String> DATA_ACCESS_RESOURCE_FAILURE_CODES = Set.of(
|
||||
"08", // Connection exception
|
||||
"53", // PostgreSQL: insufficient resources (e.g. disk full)
|
||||
"54", // PostgreSQL: program limit exceeded (e.g. statement too complex)
|
||||
"57", // DB2: out-of-memory exception / database not started
|
||||
"58" // DB2: unexpected system error
|
||||
);
|
||||
|
||||
private static final Set<String> TRANSIENT_DATA_ACCESS_RESOURCE_CODES = new HashSet<>(8);
|
||||
private static final Set<String> TRANSIENT_DATA_ACCESS_RESOURCE_CODES = Set.of(
|
||||
"JW", // Sybase: internal I/O error
|
||||
"JZ", // Sybase: unexpected I/O error
|
||||
"S1" // DB2: communication failure
|
||||
);
|
||||
|
||||
private static final Set<String> CONCURRENCY_FAILURE_CODES = new HashSet<>(4);
|
||||
|
||||
|
||||
static {
|
||||
BAD_SQL_GRAMMAR_CODES.add("07"); // Dynamic SQL error
|
||||
BAD_SQL_GRAMMAR_CODES.add("21"); // Cardinality violation
|
||||
BAD_SQL_GRAMMAR_CODES.add("2A"); // Syntax error direct SQL
|
||||
BAD_SQL_GRAMMAR_CODES.add("37"); // Syntax error dynamic SQL
|
||||
BAD_SQL_GRAMMAR_CODES.add("42"); // General SQL syntax error
|
||||
BAD_SQL_GRAMMAR_CODES.add("65"); // Oracle: unknown identifier
|
||||
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("01"); // Data truncation
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("02"); // No data found
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("22"); // Value out of range
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("23"); // Integrity constraint violation
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("27"); // Triggered data change violation
|
||||
DATA_INTEGRITY_VIOLATION_CODES.add("44"); // With check violation
|
||||
|
||||
DATA_ACCESS_RESOURCE_FAILURE_CODES.add("08"); // Connection exception
|
||||
DATA_ACCESS_RESOURCE_FAILURE_CODES.add("53"); // PostgreSQL: insufficient resources (e.g. disk full)
|
||||
DATA_ACCESS_RESOURCE_FAILURE_CODES.add("54"); // PostgreSQL: program limit exceeded (e.g. statement too complex)
|
||||
DATA_ACCESS_RESOURCE_FAILURE_CODES.add("57"); // DB2: out-of-memory exception / database not started
|
||||
DATA_ACCESS_RESOURCE_FAILURE_CODES.add("58"); // DB2: unexpected system error
|
||||
|
||||
TRANSIENT_DATA_ACCESS_RESOURCE_CODES.add("JW"); // Sybase: internal I/O error
|
||||
TRANSIENT_DATA_ACCESS_RESOURCE_CODES.add("JZ"); // Sybase: unexpected I/O error
|
||||
TRANSIENT_DATA_ACCESS_RESOURCE_CODES.add("S1"); // DB2: communication failure
|
||||
|
||||
CONCURRENCY_FAILURE_CODES.add("40"); // Transaction rollback
|
||||
CONCURRENCY_FAILURE_CODES.add("61"); // Oracle: deadlock
|
||||
}
|
||||
private static final Set<String> CONCURRENCY_FAILURE_CODES = Set.of(
|
||||
"40", // Transaction rollback
|
||||
"61" // Oracle: deadlock
|
||||
);
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.lang.reflect.InvocationHandler;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -73,25 +72,22 @@ public abstract class SharedEntityManagerCreator {
|
|||
|
||||
private static final Map<Class<?>, Class<?>[]> cachedQueryInterfaces = new ConcurrentReferenceHashMap<>(4);
|
||||
|
||||
private static final Set<String> transactionRequiringMethods = new HashSet<>(8);
|
||||
private static final Set<String> transactionRequiringMethods = Set.of(
|
||||
"joinTransaction",
|
||||
"flush",
|
||||
"persist",
|
||||
"merge",
|
||||
"remove",
|
||||
"refresh");
|
||||
|
||||
private static final Set<String> queryTerminatingMethods = new HashSet<>(8);
|
||||
|
||||
static {
|
||||
transactionRequiringMethods.add("joinTransaction");
|
||||
transactionRequiringMethods.add("flush");
|
||||
transactionRequiringMethods.add("persist");
|
||||
transactionRequiringMethods.add("merge");
|
||||
transactionRequiringMethods.add("remove");
|
||||
transactionRequiringMethods.add("refresh");
|
||||
|
||||
queryTerminatingMethods.add("execute"); // JPA 2.1 StoredProcedureQuery
|
||||
queryTerminatingMethods.add("executeUpdate");
|
||||
queryTerminatingMethods.add("getSingleResult");
|
||||
queryTerminatingMethods.add("getResultStream");
|
||||
queryTerminatingMethods.add("getResultList");
|
||||
queryTerminatingMethods.add("list"); // Hibernate Query.list() method
|
||||
}
|
||||
private static final Set<String> queryTerminatingMethods = Set.of(
|
||||
"execute", // JPA 2.1 StoredProcedureQuery
|
||||
"executeUpdate",
|
||||
"getSingleResult",
|
||||
"getResultStream",
|
||||
"getResultList",
|
||||
"list" // Hibernate Query.list() method
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,10 +58,9 @@ public final class PersistenceManagedTypesScanner {
|
|||
|
||||
private static final String PACKAGE_INFO_SUFFIX = ".package-info";
|
||||
|
||||
private static final Set<AnnotationTypeFilter> entityTypeFilters;
|
||||
private static final Set<AnnotationTypeFilter> entityTypeFilters = new LinkedHashSet<>(4);
|
||||
|
||||
static {
|
||||
entityTypeFilters = new LinkedHashSet<>(8);
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(Entity.class, false));
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(Embeddable.class, false));
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(MappedSuperclass.class, false));
|
||||
|
|
|
@ -75,9 +75,9 @@ public class MergedContextConfiguration implements Serializable {
|
|||
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
|
||||
|
||||
private static final Set<Class<? extends ApplicationContextInitializer<?>>> EMPTY_INITIALIZER_CLASSES =
|
||||
Collections.<Class<? extends ApplicationContextInitializer<?>>> emptySet();
|
||||
Collections.emptySet();
|
||||
|
||||
private static final Set<ContextCustomizer> EMPTY_CONTEXT_CUSTOMIZERS = Collections.<ContextCustomizer> emptySet();
|
||||
private static final Set<ContextCustomizer> EMPTY_CONTEXT_CUSTOMIZERS = Collections.emptySet();
|
||||
|
||||
|
||||
private final Class<?> testClass;
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
|
@ -75,15 +74,12 @@ public class SourceHttpMessageConverter<T extends Source> extends AbstractHttpMe
|
|||
private static final XMLResolver NO_OP_XML_RESOLVER =
|
||||
(publicID, systemID, base, ns) -> InputStream.nullInputStream();
|
||||
|
||||
private static final Set<Class<?>> SUPPORTED_CLASSES = new HashSet<>(8);
|
||||
|
||||
static {
|
||||
SUPPORTED_CLASSES.add(DOMSource.class);
|
||||
SUPPORTED_CLASSES.add(SAXSource.class);
|
||||
SUPPORTED_CLASSES.add(StAXSource.class);
|
||||
SUPPORTED_CLASSES.add(StreamSource.class);
|
||||
SUPPORTED_CLASSES.add(Source.class);
|
||||
}
|
||||
private static final Set<Class<?>> SUPPORTED_CLASSES = Set.of(
|
||||
DOMSource.class,
|
||||
SAXSource.class,
|
||||
StAXSource.class,
|
||||
StreamSource.class,
|
||||
Source.class);
|
||||
|
||||
|
||||
private final TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
|
|
|
@ -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.
|
||||
|
@ -16,8 +16,6 @@
|
|||
|
||||
package org.springframework.web.server.adapter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
@ -73,9 +71,9 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa
|
|||
private static final String DISCONNECTED_CLIENT_LOG_CATEGORY =
|
||||
"org.springframework.web.server.DisconnectedClient";
|
||||
|
||||
// Similar declaration exists in AbstractSockJsSession..
|
||||
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS = new HashSet<>(
|
||||
Arrays.asList("AbortedException", "ClientAbortException", "EOFException", "EofException"));
|
||||
// Similar declaration exists in AbstractSockJsSession.
|
||||
private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS =
|
||||
Set.of("AbortedException", "ClientAbortException", "EOFException", "EofException");
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(HttpWebHandlerAdapter.class);
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.springframework.web.socket.sockjs.client;
|
|||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -67,14 +66,7 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
|
|||
|
||||
private static final Log logger = LogFactory.getLog(SockJsClient.class);
|
||||
|
||||
private static final Set<String> supportedProtocols = new HashSet<>(4);
|
||||
|
||||
static {
|
||||
supportedProtocols.add("ws");
|
||||
supportedProtocols.add("wss");
|
||||
supportedProtocols.add("http");
|
||||
supportedProtocols.add("https");
|
||||
}
|
||||
private static final Set<String> supportedProtocols = Set.of("ws", "wss", "http", "https");
|
||||
|
||||
|
||||
private final List<Transport> transports;
|
||||
|
|
Loading…
Reference in New Issue