Avoid resizing of fixed-size HashMap/LinkedHashMap variants

Closes gh-25349
This commit is contained in:
Juergen Hoeller 2020-08-25 19:26:18 +02:00
parent 241afeb1b7
commit ff11467a0c
58 changed files with 195 additions and 149 deletions

View File

@ -21,7 +21,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -53,6 +52,7 @@ import org.springframework.core.SmartClassLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@ -325,7 +325,7 @@ class CglibAopProxy implements AopProxy, Serializable {
if (isStatic && isFrozen) {
Method[] methods = rootClass.getMethods();
Callback[] fixedCallbacks = new Callback[methods.length];
this.fixedInterceptorMap = new HashMap<>(methods.length);
this.fixedInterceptorMap = CollectionUtils.newHashMap(methods.length);
// TODO: small memory optimization here (can skip creation for methods with no advice)
for (int x = 0; x < methods.length; x++) {

View File

@ -49,6 +49,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@ -792,7 +793,7 @@ public abstract class BeanUtils {
}
List<KParameter> parameters = kotlinConstructor.getParameters();
Map<KParameter, Object> argParameters = new HashMap<>(parameters.size());
Map<KParameter, Object> argParameters = CollectionUtils.newHashMap(parameters.size());
Assert.isTrue(args.length <= parameters.size(),
"Number of provided arguments should be less of equals than number of constructor parameters");
for (int i = 0 ; i < args.length ; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 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,13 +16,13 @@
package org.springframework.beans.factory.config;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
/**
* Simple factory for shared Map instances. Allows for central setup
@ -85,7 +85,7 @@ public class MapFactoryBean extends AbstractFactoryBean<Map<Object, Object>> {
result = BeanUtils.instantiateClass(this.targetMapClass);
}
else {
result = new LinkedHashMap<>(this.sourceMap.size());
result = CollectionUtils.newLinkedHashMap(this.sourceMap.size());
}
Class<?> keyType = null;
Class<?> valueType = null;

View File

@ -18,7 +18,6 @@ package org.springframework.beans.factory.support;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -42,6 +41,7 @@ import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@ -447,7 +447,7 @@ class BeanDefinitionValueResolver {
* For each element in the managed map, resolve reference if necessary.
*/
private Map<?, ?> resolveManagedMap(Object argName, Map<?, ?> mm) {
Map<Object, Object> resolved = new LinkedHashMap<>(mm.size());
Map<Object, Object> resolved = CollectionUtils.newLinkedHashMap(mm.size());
mm.forEach((key, value) -> {
Object resolvedKey = resolveValueIfNecessary(argName, key);
Object resolvedValue = resolveValueIfNecessary(new KeyedArgName(argName, key), value);

View File

@ -33,7 +33,6 @@ import java.util.Collection;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -81,6 +80,7 @@ import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.CompositeIterator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@ -476,7 +476,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
if (beanNames.length == 0) {
return Stream.empty();
}
Map<String, T> matchingBeans = new LinkedHashMap<>(beanNames.length);
Map<String, T> matchingBeans = CollectionUtils.newLinkedHashMap(beanNames.length);
for (String beanName : beanNames) {
Object beanInstance = getBean(beanName);
if (!(beanInstance instanceof NullBean)) {
@ -665,7 +665,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException {
String[] beanNames = getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
Map<String, T> result = new LinkedHashMap<>(beanNames.length);
Map<String, T> result = CollectionUtils.newLinkedHashMap(beanNames.length);
for (String beanName : beanNames) {
try {
Object beanInstance = getBean(beanName);
@ -715,7 +715,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override
public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) {
String[] beanNames = getBeanNamesForAnnotation(annotationType);
Map<String, Object> result = new LinkedHashMap<>(beanNames.length);
Map<String, Object> result = CollectionUtils.newLinkedHashMap(beanNames.length);
for (String beanName : beanNames) {
Object beanInstance = getBean(beanName);
if (!(beanInstance instanceof NullBean)) {
@ -1235,7 +1235,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
return new NamedBeanHolder<>(beanName, (T) getBean(beanName, requiredType.toClass(), args));
}
else if (candidateNames.length > 1) {
Map<String, Object> candidates = new LinkedHashMap<>(candidateNames.length);
Map<String, Object> candidates = CollectionUtils.newLinkedHashMap(candidateNames.length);
for (String beanName : candidateNames) {
if (containsSingleton(beanName) && args == null) {
Object beanInstance = getBean(beanName);
@ -1532,7 +1532,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
this, requiredType, true, descriptor.isEager());
Map<String, Object> result = new LinkedHashMap<>(candidateNames.length);
Map<String, Object> result = CollectionUtils.newLinkedHashMap(candidateNames.length);
for (Map.Entry<Class<?>, Object> classObjectEntry : this.resolvableDependencies.entrySet()) {
Class<?> autowiringType = classObjectEntry.getKey();
if (autowiringType.isAssignableFrom(requiredType)) {

View File

@ -101,7 +101,6 @@ class KeyGeneratorAdapter implements KeyGenerator {
}
}
@SuppressWarnings("unchecked")
private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationContext<?> context) {
List<Object> parameters = new ArrayList<>();
for (CacheInvocationParameter param : context.getKeyParameters()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -66,6 +66,7 @@ import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@ -301,13 +302,13 @@ public class MBeanClientInterceptor
MBeanInfo info = server.getMBeanInfo(this.objectName);
MBeanAttributeInfo[] attributeInfo = info.getAttributes();
this.allowedAttributes = new HashMap<>(attributeInfo.length);
this.allowedAttributes = CollectionUtils.newHashMap(attributeInfo.length);
for (MBeanAttributeInfo infoEle : attributeInfo) {
this.allowedAttributes.put(infoEle.getName(), infoEle);
}
MBeanOperationInfo[] operationInfo = info.getOperations();
this.allowedOperations = new HashMap<>(operationInfo.length);
this.allowedOperations = CollectionUtils.newHashMap(operationInfo.length);
for (MBeanOperationInfo infoEle : operationInfo) {
Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader);
this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);

View File

@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@ -28,6 +27,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@ -126,7 +126,7 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI
* @return the resolved interface mappings (with Class objects as values)
*/
private Map<String, Class<?>[]> resolveInterfaceMappings(Properties mappings) {
Map<String, Class<?>[]> resolvedMappings = new HashMap<>(mappings.size());
Map<String, Class<?>[]> resolvedMappings = CollectionUtils.newHashMap(mappings.size());
for (Enumeration<?> en = mappings.propertyNames(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] classNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));

View File

@ -34,9 +34,11 @@ import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.util.CollectionUtils;
/**
* Benchmarks for {@link GenericConversionService}.
*
* @author Brian Clozel
*/
@BenchmarkMode(Mode.Throughput)
@ -78,11 +80,12 @@ public class GenericConversionServiceBenchmark {
@Benchmark
public void convertMapOfStringToListOfIntegerBaseline(MapBenchmarkState state, Blackhole bh) {
Map<String, Integer> target = new HashMap<>(state.source.size());
Map<String, Integer> target = CollectionUtils.newHashMap(state.source.size());
state.source.forEach((k, v) -> target.put(k, Integer.valueOf(v)));
bh.consume(target);
}
@State(Scope.Benchmark)
public static class MapBenchmarkState extends BenchmarkState {
@ -90,7 +93,7 @@ public class GenericConversionServiceBenchmark {
@Setup(Level.Trial)
public void setup() throws Exception {
this.source = new HashMap<>(this.collectionSize);
this.source = CollectionUtils.newHashMap(this.collectionSize);
Map<String, Integer> target = new HashMap<>();
this.targetTypeDesc = TypeDescriptor.forObject(target);
this.source = IntStream.rangeClosed(1, collectionSize).mapToObj(String::valueOf)
@ -98,6 +101,7 @@ public class GenericConversionServiceBenchmark {
}
}
@State(Scope.Benchmark)
public static class BenchmarkState {
@ -107,6 +111,6 @@ public class GenericConversionServiceBenchmark {
int collectionSize;
TypeDescriptor targetTypeDesc;
}
}

View File

@ -24,7 +24,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
@ -35,6 +34,7 @@ import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.Mirr
import org.springframework.core.annotation.MergedAnnotation.Adapt;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@ -905,7 +905,7 @@ public abstract class AnnotationUtils {
if (!methods.hasDefaultValueMethod()) {
return Collections.emptyMap();
}
Map<String, DefaultValueHolder> result = new LinkedHashMap<>(methods.size());
Map<String, DefaultValueHolder> result = CollectionUtils.newLinkedHashMap(methods.size());
if (!methods.hasNestedAnnotation()) {
// Use simpler method if there are no nested annotations
for (int i = 0; i < methods.size(); i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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,12 +17,12 @@
package org.springframework.core.codec;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
/**
* Constants and convenience methods for working with hints.
@ -120,7 +120,7 @@ public abstract class Hints {
return hints2;
}
else {
Map<String, Object> result = new HashMap<>(hints1.size() + hints2.size());
Map<String, Object> result = CollectionUtils.newHashMap(hints1.size() + hints2.size());
result.putAll(hints1);
result.putAll(hints2);
return result;
@ -141,7 +141,7 @@ public abstract class Hints {
return Collections.singletonMap(hintName, hintValue);
}
else {
Map<String, Object> result = new HashMap<>(hints.size() + 1);
Map<String, Object> result = CollectionUtils.newHashMap(hints.size() + 1);
result.putAll(hints);
result.put(hintName, hintValue);
return result;

View File

@ -68,7 +68,7 @@ public class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisito
* to ensure that the hierarchical ordering of the entries is preserved.
* @see AnnotationReadingVisitorUtils#getMergedAnnotationAttributes
*/
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(4);
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(3);
protected final Set<MethodMetadata> methodMetadataSet = new LinkedHashSet<>(4);

View File

@ -66,7 +66,7 @@ public class MethodMetadataReadingVisitor extends MethodVisitor implements Metho
protected final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<>(4);
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(4);
protected final LinkedMultiValueMap<String, AnnotationAttributes> attributesMap = new LinkedMultiValueMap<>(3);
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName,

View File

@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@ -42,6 +43,14 @@ import org.springframework.lang.Nullable;
*/
public abstract class CollectionUtils {
/**
* Default load factor for {@link HashMap}/{@link LinkedHashMap} variants.
* @see #newHashMap(int)
* @see #newLinkedHashMap(int)
*/
static final float DEFAULT_LOAD_FACTOR = 0.75f;
/**
* Return {@code true} if the supplied Collection is {@code null} or empty.
* Otherwise, return {@code false}.
@ -62,6 +71,37 @@ public abstract class CollectionUtils {
return (map == null || map.isEmpty());
}
/**
* Instantiate a new {@link HashMap} with an initial capacity
* that can accommodate the given number of elements.
* <p>This differs from the regular {@link HashMap} constructor
* which takes an initial capacity relative to a load factor
* but is effectively aligned with the JDK's
* {@link java.util.concurrent.ConcurrentHashMap#ConcurrentHashMap(int)}.
* @param expectedSize the expected number of elements
* @since 5.3
* @see #newLinkedHashMap(int)
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static <K, V> HashMap<K, V> newHashMap(int expectedSize) {
return new HashMap((int) (expectedSize / DEFAULT_LOAD_FACTOR), DEFAULT_LOAD_FACTOR);
}
/**
* Instantiate a new {@link LinkedHashMap} with an initial capacity
* that can accommodate the given number of elements.
* <p>This differs from the regular {@link LinkedHashMap} constructor
* which takes an initial capacity relative to a load factor but is
* aligned with Spring's own {@link LinkedCaseInsensitiveMap} and
* {@link LinkedMultiValueMap} constructor semantics as of 5.3.
* @param expectedSize the expected number of elements
* @since 5.3
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(int expectedSize) {
return new LinkedHashMap((int) (expectedSize / DEFAULT_LOAD_FACTOR), DEFAULT_LOAD_FACTOR);
}
/**
* Convert the supplied array into a List. A primitive array gets converted
* into a List of the appropriate wrapper type.
@ -74,8 +114,7 @@ public abstract class CollectionUtils {
* @see ObjectUtils#toObjectArray(Object)
* @see Arrays#asList(Object[])
*/
@SuppressWarnings("rawtypes")
public static List arrayToList(@Nullable Object source) {
public static List<?> arrayToList(@Nullable Object source) {
return Arrays.asList(ObjectUtils.toObjectArray(source));
}
@ -430,7 +469,7 @@ public abstract class CollectionUtils {
MultiValueMap<? extends K, ? extends V> targetMap) {
Assert.notNull(targetMap, "'targetMap' must not be null");
Map<K, List<V>> result = new LinkedHashMap<>(targetMap.size());
Map<K, List<V>> result = newLinkedHashMap(targetMap.size());
targetMap.forEach((key, value) -> {
List<? extends V> values = Collections.unmodifiableList(value);
result.put(key, (List<V>) values);

View File

@ -76,7 +76,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
/**
* Create a new LinkedCaseInsensitiveMap that stores case-insensitive keys
* according to the given Locale (by default in lower case).
* according to the given Locale (in lower case).
* @param locale the Locale to use for case-insensitive key conversion
* @see #convertKey(String)
*/
@ -86,25 +86,26 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
/**
* Create a new LinkedCaseInsensitiveMap that wraps a {@link LinkedHashMap}
* with the given initial capacity and stores case-insensitive keys
* according to the default Locale (by default in lower case).
* @param initialCapacity the initial capacity
* with an initial capacity that can accommodate the given number of elements,
* storing case-insensitive keys according to the default Locale (in lower case).
* @param expectedSize the expected number of elements
* @see #convertKey(String)
*/
public LinkedCaseInsensitiveMap(int initialCapacity) {
this(initialCapacity, null);
public LinkedCaseInsensitiveMap(int expectedSize) {
this(expectedSize, null);
}
/**
* Create a new LinkedCaseInsensitiveMap that wraps a {@link LinkedHashMap}
* with the given initial capacity and stores case-insensitive keys
* according to the given Locale (by default in lower case).
* @param initialCapacity the initial capacity
* with an initial capacity that can accommodate the given number of elements,
* storing case-insensitive keys according to the given Locale (in lower case).
* @param expectedSize the expected number of elements
* @param locale the Locale to use for case-insensitive key conversion
* @see #convertKey(String)
*/
public LinkedCaseInsensitiveMap(int initialCapacity, @Nullable Locale locale) {
this.targetMap = new LinkedHashMap<String, V>(initialCapacity) {
public LinkedCaseInsensitiveMap(int expectedSize, @Nullable Locale locale) {
this.targetMap = new LinkedHashMap<String, V>(
(int) (expectedSize / CollectionUtils.DEFAULT_LOAD_FACTOR), CollectionUtils.DEFAULT_LOAD_FACTOR) {
@Override
public boolean containsKey(Object key) {
return LinkedCaseInsensitiveMap.this.containsKey(key);
@ -118,7 +119,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
return doRemove;
}
};
this.caseInsensitiveKeys = new HashMap<>(initialCapacity);
this.caseInsensitiveKeys = CollectionUtils.newHashMap(expectedSize);
this.locale = (locale != null ? locale : Locale.getDefault());
}

View File

@ -49,11 +49,11 @@ public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> implem
/**
* Create a new LinkedMultiValueMap that wraps a {@link LinkedHashMap}
* with the given initial capacity.
* @param initialCapacity the initial capacity
* with an initial capacity that can accommodate the given number of elements.
* @param expectedSize the expected number of elements
*/
public LinkedMultiValueMap(int initialCapacity) {
super(new LinkedHashMap<>(initialCapacity));
public LinkedMultiValueMap(int expectedSize) {
super(CollectionUtils.newLinkedHashMap(expectedSize));
}
/**

View File

@ -18,7 +18,6 @@ package org.springframework.util;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -88,7 +87,7 @@ class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
@Override
public Map<K, V> toSingleValueMap() {
Map<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
Map<K, V> singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size());
this.targetMap.forEach((key, values) -> {
if (values != null && !values.isEmpty()) {
singleValueMap.put(key, values.get(0));

View File

@ -55,6 +55,7 @@ import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.StringUtils;
@ -1333,7 +1334,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
protected Map<String, Object> extractOutputParameters(CallableStatement cs, List<SqlParameter> parameters)
throws SQLException {
Map<String, Object> results = new LinkedHashMap<>(parameters.size());
Map<String, Object> results = CollectionUtils.newLinkedHashMap(parameters.size());
int sqlColIndex = 1;
for (SqlParameter param : parameters) {
if (param instanceof SqlOutParameter) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.jdbc.core.metadata;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@ -42,6 +41,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@ -369,7 +369,7 @@ public class CallMetaDataContext {
return workParams;
}
Map<String, String> limitedInParamNamesMap = new HashMap<>(this.limitedInParameterNames.size());
Map<String, String> limitedInParamNamesMap = CollectionUtils.newHashMap(this.limitedInParameterNames.size());
for (String limitedParamName : this.limitedInParameterNames) {
limitedInParamNamesMap.put(lowerCase(provider.parameterNameToUse(limitedParamName)), limitedParamName);
}
@ -482,8 +482,8 @@ public class CallMetaDataContext {
Map<String, String> caseInsensitiveParameterNames =
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource);
Map<String, String> callParameterNames = new HashMap<>(this.callParameters.size());
Map<String, Object> matchedParameters = new HashMap<>(this.callParameters.size());
Map<String, String> callParameterNames = CollectionUtils.newHashMap(this.callParameters.size());
Map<String, Object> matchedParameters = CollectionUtils.newHashMap(this.callParameters.size());
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
@ -551,7 +551,7 @@ public class CallMetaDataContext {
return inParameters;
}
Map<String, String> callParameterNames = new HashMap<>(this.callParameters.size());
Map<String, String> callParameterNames = CollectionUtils.newHashMap(this.callParameters.size());
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
@ -562,7 +562,7 @@ public class CallMetaDataContext {
}
}
Map<String, Object> matchedParameters = new HashMap<>(inParameters.size());
Map<String, Object> matchedParameters = CollectionUtils.newHashMap(inParameters.size());
inParameters.forEach((parameterName, parameterValue) -> {
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
String callParameterName = callParameterNames.get(lowerCase(parameterNameToMatch));
@ -602,7 +602,7 @@ public class CallMetaDataContext {
}
public Map<String, ?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
Map<String, Object> matchedParameters = new HashMap<>(parameterValues.length);
Map<String, Object> matchedParameters = CollectionUtils.newHashMap(parameterValues.length);
int i = 0;
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.jdbc.core.metadata;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -36,6 +35,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Class to manage context meta-data used for the configuration
@ -319,7 +319,7 @@ public class TableMetaDataContext {
public int[] createInsertTypes() {
int[] types = new int[getTableColumns().size()];
List<TableParameterMetaData> parameters = obtainMetaDataProvider().getTableParameterMetaData();
Map<String, TableParameterMetaData> parameterMap = new LinkedHashMap<>(parameters.size());
Map<String, TableParameterMetaData> parameterMap = CollectionUtils.newLinkedHashMap(parameters.size());
for (TableParameterMetaData tpmd : parameters) {
parameterMap.put(tpmd.getParameterName().toUpperCase(), tpmd);
}

View File

@ -19,7 +19,6 @@ package org.springframework.jdbc.datasource.lookup;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
@ -28,6 +27,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.AbstractDataSource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Abstract {@link javax.sql.DataSource} implementation that routes {@link #getConnection()}
@ -119,7 +119,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
if (this.targetDataSources == null) {
throw new IllegalArgumentException("Property 'targetDataSources' is required");
}
this.resolvedDataSources = new HashMap<>(this.targetDataSources.size());
this.resolvedDataSources = CollectionUtils.newHashMap(this.targetDataSources.size());
this.targetDataSources.forEach((key, value) -> {
Object lookupKey = resolveSpecifiedLookupKey(key);
DataSource dataSource = resolveSpecifiedDataSource(value);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -25,11 +25,11 @@ import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.springframework.jdbc.InvalidResultSetAccessException;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
/**
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
@ -97,7 +97,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
ResultSetMetaData rsmd = resultSet.getMetaData();
if (rsmd != null) {
int columnCount = rsmd.getColumnCount();
this.columnLabelMap = new HashMap<>(columnCount);
this.columnLabelMap = CollectionUtils.newHashMap(columnCount);
for (int i = 1; i <= columnCount; i++) {
String key = rsmd.getColumnLabel(i);
// Make sure to preserve first matching column for any given name,

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.CollectionUtils;
import org.springframework.util.IdGenerator;
/**
@ -164,7 +165,7 @@ public class MessageHeaders implements Map<String, Object>, Serializable {
* @param keysToIgnore the keys of the entries to ignore
*/
private MessageHeaders(MessageHeaders original, Set<String> keysToIgnore) {
this.headers = new HashMap<>(original.headers.size());
this.headers = CollectionUtils.newHashMap(original.headers.size());
original.headers.forEach((key, value) -> {
if (!keysToIgnore.contains(key)) {
this.headers.put(key, value);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -109,7 +109,7 @@ public abstract class AbstractMethodMessageHandler<T>
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<>(64);
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<>(64);
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<>(48);
private final Map<Class<?>, AbstractExceptionHandlerMethodResolver> exceptionHandlerCache =
new ConcurrentHashMap<>(64);

View File

@ -106,7 +106,7 @@ public abstract class AbstractMethodMessageHandler<T>
private final Map<T, HandlerMethod> handlerMethods = new LinkedHashMap<>(64);
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<>(64);
private final MultiValueMap<String, T> destinationLookup = new LinkedMultiValueMap<>(48);
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.messaging.rsocket.annotation.support;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@ -29,6 +28,7 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.AbstractMessageCondition;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* A condition to assist with mapping onto handler methods based on the RSocket
@ -88,7 +88,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition<R
private static final Map<String, RSocketFrameTypeMessageCondition> frameTypeConditionCache;
static {
frameTypeConditionCache = new HashMap<>(FrameType.values().length);
frameTypeConditionCache = CollectionUtils.newHashMap(FrameType.values().length);
for (FrameType type : FrameType.values()) {
frameTypeConditionCache.put(type.name(), new RSocketFrameTypeMessageCondition(type));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@ -28,6 +28,7 @@ import java.util.Set;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@ -110,7 +111,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
* Create a new instance to be populated with new header values.
*/
public StompHeaders() {
this(new LinkedMultiValueMap<>(4), false);
this(new LinkedMultiValueMap<>(3), false);
}
private StompHeaders(Map<String, List<String>> headers, boolean readOnly) {
@ -482,7 +483,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
@Override
public Map<String, String> toSingleValueMap() {
LinkedHashMap<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
LinkedHashMap<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
return singleValueMap;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -33,6 +33,7 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
/**
@ -209,7 +210,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
public UserRegistrySnapshot(String id, SimpUserRegistry registry) {
this.id = id;
Set<SimpUser> users = registry.getUsers();
this.users = new HashMap<>(users.size());
this.users = CollectionUtils.newHashMap(users.size());
for (SimpUser user : users) {
this.users.put(user.getName(), new TransferSimpUser(user));
}

View File

@ -163,7 +163,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
return;
}
if (map == null) {
map = new LinkedMultiValueMap<>(4);
map = new LinkedMultiValueMap<>(3);
setHeader(NATIVE_HEADERS, map);
}
List<String> values = new LinkedList<>();
@ -184,7 +184,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
}
Map<String, List<String>> nativeHeaders = getNativeHeaders();
if (nativeHeaders == null) {
nativeHeaders = new LinkedMultiValueMap<>(4);
nativeHeaders = new LinkedMultiValueMap<>(3);
setHeader(NATIVE_HEADERS, nativeHeaders);
}
List<String> values = nativeHeaders.computeIfAbsent(name, k -> new LinkedList<>());

View File

@ -24,7 +24,6 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -82,6 +81,7 @@ import org.springframework.oxm.UnmarshallingFailureException;
import org.springframework.oxm.XmlMappingException;
import org.springframework.oxm.support.AbstractMarshaller;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.function.SingletonSupplier;
@ -584,7 +584,7 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo
}
private Map<String, Class<?>> toClassMap(Map<String, ?> map) throws ClassNotFoundException {
Map<String, Class<?>> result = new LinkedHashMap<>(map.size());
Map<String, Class<?>> result = CollectionUtils.newLinkedHashMap(map.size());
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();

View File

@ -16,7 +16,6 @@
package org.springframework.r2dbc.connection.lookup;
import java.util.HashMap;
import java.util.Map;
import io.r2dbc.spi.Connection;
@ -27,6 +26,7 @@ import reactor.core.publisher.Mono;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Abstract {@link ConnectionFactory} implementation that routes
@ -129,12 +129,12 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact
this.connectionFactoryLookup = connectionFactoryLookup;
}
@Override
public void afterPropertiesSet() {
Assert.notNull(this.targetConnectionFactories, "Property 'targetConnectionFactories' must not be null");
this.resolvedConnectionFactories = new HashMap<>(this.targetConnectionFactories.size());
this.resolvedConnectionFactories = CollectionUtils.newHashMap(this.targetConnectionFactories.size());
this.targetConnectionFactories.forEach((key, value) -> {
Object lookupKey = resolveSpecifiedLookupKey(key);
ConnectionFactory connectionFactory = resolveSpecifiedConnectionFactory(value);

View File

@ -51,6 +51,7 @@ import org.springframework.r2dbc.connection.ConnectionFactoryUtils;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.r2dbc.core.binding.BindTarget;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
@ -255,7 +256,6 @@ class DefaultDatabaseClient implements DatabaseClient {
"Value at index %d must not be null. Use bindNull(…) instead.", index));
Map<Integer, Parameter> byIndex = new LinkedHashMap<>(this.byIndex);
if (value instanceof Parameter) {
byIndex.put(index, (Parameter) value);
}
@ -285,7 +285,6 @@ class DefaultDatabaseClient implements DatabaseClient {
"Value for parameter %s must not be null. Use bindNull(…) instead.", name));
Map<String, Parameter> byName = new LinkedHashMap<>(this.byName);
if (value instanceof Parameter) {
byName.put(name, (Parameter) value);
}
@ -393,7 +392,7 @@ class DefaultDatabaseClient implements DatabaseClient {
private MapBindParameterSource retrieveParameters(String sql, List<String> parameterNames,
Map<String, Parameter> remainderByName, Map<Integer, Parameter> remainderByIndex) {
Map<String, Parameter> namedBindings = new LinkedHashMap<>(parameterNames.size());
Map<String, Parameter> namedBindings = CollectionUtils.newLinkedHashMap(parameterNames.size());
for (String parameterName : parameterNames) {
Parameter parameter = getParameter(remainderByName, remainderByIndex, parameterNames, parameterName);
if (parameter == null) {

View File

@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Spliterator;
@ -31,6 +30,7 @@ import io.r2dbc.spi.Statement;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Value object representing value and {@code null} bindings
@ -60,7 +60,7 @@ public class Bindings implements Iterable<Bindings.Binding> {
*/
public Bindings(Collection<Binding> bindings) {
Assert.notNull(bindings, "Bindings must not be null");
Map<BindMarker, Binding> mapping = new LinkedHashMap<>(bindings.size());
Map<BindMarker, Binding> mapping = CollectionUtils.newLinkedHashMap(bindings.size());
bindings.forEach(binding -> mapping.put(binding.getBindMarker(), binding));
this.bindings = mapping;
}

View File

@ -22,7 +22,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -33,6 +32,7 @@ import org.apache.hc.core5.http.HttpResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -85,7 +85,7 @@ class HttpComponentsHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> map = new LinkedHashMap<>(size());
Map<String, String> map = CollectionUtils.newLinkedHashMap(size());
this.response.headerIterator().forEachRemaining(h -> map.putIfAbsent(h.getName(), h.getValue()));
return map;
}

View File

@ -20,7 +20,6 @@ import java.util.AbstractSet;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -31,6 +30,7 @@ import org.eclipse.jetty.http.HttpFields;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -83,7 +83,7 @@ class JettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
Iterator<HttpField> iterator = this.headers.iterator();
iterator.forEachRemaining(field -> {
if (!singleValueMap.containsKey(field.getName())) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.http.client.reactive;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -28,6 +27,7 @@ import java.util.stream.Collectors;
import io.netty.handler.codec.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -81,7 +81,7 @@ class NettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.entries()
.forEach(entry -> {
if (!singleValueMap.containsKey(entry.getKey())) {

View File

@ -21,7 +21,6 @@ import java.lang.annotation.Annotation;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -52,6 +51,7 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeType;
/**
@ -70,7 +70,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
private static final Map<String, JsonEncoding> ENCODINGS;
static {
ENCODINGS = new HashMap<>(JsonEncoding.values().length + 1);
ENCODINGS = CollectionUtils.newHashMap(JsonEncoding.values().length);
for (JsonEncoding encoding : JsonEncoding.values()) {
ENCODINGS.put(encoding.getJavaName(), encoding);
}

View File

@ -24,7 +24,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@ -56,6 +55,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.TypeUtils;
/**
@ -77,7 +77,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
private static final Map<String, JsonEncoding> ENCODINGS;
static {
ENCODINGS = new HashMap<>(JsonEncoding.values().length + 1);
ENCODINGS = CollectionUtils.newHashMap(JsonEncoding.values().length);
for (JsonEncoding encoding : JsonEncoding.values()) {
ENCODINGS.put(encoding.getJavaName(), encoding);
}

View File

@ -20,7 +20,6 @@ import java.util.AbstractSet;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -31,6 +30,7 @@ import org.eclipse.jetty.http.HttpFields;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -83,7 +83,7 @@ class JettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
Iterator<HttpField> iterator = this.headers.iterator();
iterator.forEachRemaining(field -> {
if (!singleValueMap.containsKey(field.getName())) {

View File

@ -19,7 +19,6 @@ package org.springframework.http.server.reactive;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -28,6 +27,7 @@ import java.util.stream.Collectors;
import io.netty.handler.codec.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -81,7 +81,7 @@ class NettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.entries()
.forEach(entry -> {
if (!singleValueMap.containsKey(entry.getKey())) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -33,6 +32,7 @@ import org.apache.tomcat.util.http.MimeHeaders;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -83,7 +83,7 @@ class TomcatHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.keySet().forEach(key -> singleValueMap.put(key, getFirst(key)));
return singleValueMap;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.http.server.reactive;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -30,6 +29,7 @@ import io.undertow.util.HeaderValues;
import io.undertow.util.HttpString;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
/**
@ -81,7 +81,7 @@ class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@Override
public Map<String, String> toSingleValueMap() {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
this.headers.forEach(values ->
singleValueMap.put(values.getHeaderName().toString(), values.getFirst()));
return singleValueMap;

View File

@ -17,7 +17,6 @@
package org.springframework.web.cors;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -27,6 +26,7 @@ import org.springframework.http.server.PathContainer;
import org.springframework.lang.Nullable;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.PathMatcher;
import org.springframework.web.util.ServletRequestPathUtils;
import org.springframework.web.util.UrlPathHelper;
@ -232,7 +232,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
* Return all configured CORS mappings.
*/
public Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> result = new HashMap<>(this.corsConfigurations.size());
Map<String, CorsConfiguration> result = CollectionUtils.newHashMap(this.corsConfigurations.size());
this.corsConfigurations.forEach((pattern, config) -> result.put(pattern.getPatternString(), config));
return Collections.unmodifiableMap(result);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@ -26,6 +26,7 @@ import javax.servlet.http.Part;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
@ -115,7 +116,7 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
if (servletRequest != null && MultipartResolutionDelegate.isMultipartRequest(servletRequest)) {
Collection<Part> parts = servletRequest.getParts();
LinkedHashMap<String, Part> result = new LinkedHashMap<>(parts.size());
LinkedHashMap<String, Part> result = CollectionUtils.newLinkedHashMap(parts.size());
for (Part part : parts) {
if (!result.containsKey(part.getName())) {
result.put(part.getName(), part);
@ -127,7 +128,7 @@ public class RequestParamMapMethodArgumentResolver implements HandlerMethodArgum
}
else {
Map<String, String[]> parameterMap = webRequest.getParameterMap();
Map<String, String> result = new LinkedHashMap<>(parameterMap.size());
Map<String, String> result = CollectionUtils.newLinkedHashMap(parameterMap.size());
parameterMap.forEach((key, values) -> {
if (values.length > 0) {
result.put(key, values[0]);

View File

@ -20,7 +20,6 @@ import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@ -28,6 +27,7 @@ import java.util.regex.Pattern;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/**
* Representation of a URI template that can be expanded with URI variables via
@ -154,7 +154,7 @@ public class UriTemplate implements Serializable {
*/
public Map<String, String> match(String uri) {
Assert.notNull(uri, "'uri' must not be null");
Map<String, String> result = new LinkedHashMap<>(this.variableNames.size());
Map<String, String> result = CollectionUtils.newLinkedHashMap(this.variableNames.size());
Matcher matcher = this.matchPattern.matcher(uri);
if (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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,11 +20,11 @@ import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
@ -325,7 +325,7 @@ public abstract class UriUtils {
* @since 5.0
*/
public static Map<String, String> encodeUriVariables(Map<String, ?> uriVariables) {
Map<String, String> result = new LinkedHashMap<>(uriVariables.size());
Map<String, String> result = CollectionUtils.newLinkedHashMap(uriVariables.size());
uriVariables.forEach((key, value) -> {
String stringValue = (value != null ? value.toString() : "");
result.put(key, encode(stringValue, StandardCharsets.UTF_8));

View File

@ -18,7 +18,6 @@ package org.springframework.web.util;
import java.net.URLDecoder;
import java.nio.charset.UnsupportedCharsetException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
@ -32,6 +31,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
@ -615,7 +615,7 @@ public class UrlPathHelper {
return vars;
}
else {
Map<String, String> decodedVars = new LinkedHashMap<>(vars.size());
Map<String, String> decodedVars = CollectionUtils.newLinkedHashMap(vars.size());
vars.forEach((key, value) -> decodedVars.put(key, decodeInternal(request, value)));
return decodedVars;
}

View File

@ -17,10 +17,10 @@
package org.springframework.web.reactive.config;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration;
/**
@ -55,7 +55,7 @@ public class CorsRegistry {
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
Map<String, CorsConfiguration> configs = CollectionUtils.newLinkedHashMap(this.registrations.size());
for (CorsRegistration registration : this.registrations) {
configs.put(registration.getPathPattern(), registration.getCorsConfiguration());
}

View File

@ -212,7 +212,7 @@ class DefaultWebClient implements WebClient {
private MultiValueMap<String, String> getCookies() {
if (this.cookies == null) {
this.cookies = new LinkedMultiValueMap<>(4);
this.cookies = new LinkedMultiValueMap<>(3);
}
return this.cookies;
}

View File

@ -180,7 +180,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
private MultiValueMap<String, String> initCookies() {
if (this.defaultCookies == null) {
this.defaultCookies = new LinkedMultiValueMap<>(4);
this.defaultCookies = new LinkedMultiValueMap<>(3);
}
return this.defaultCookies;
}

View File

@ -19,7 +19,6 @@ package org.springframework.web.reactive.result.condition;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@ -27,6 +26,7 @@ import java.util.Set;
import org.springframework.http.HttpMethod;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.cors.reactive.CorsUtils;
@ -45,7 +45,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
private static final Map<HttpMethod, RequestMethodsRequestCondition> requestMethodConditionCache;
static {
requestMethodConditionCache = new HashMap<>(RequestMethod.values().length);
requestMethodConditionCache = CollectionUtils.newHashMap(RequestMethod.values().length);
for (RequestMethod method : RequestMethod.values()) {
requestMethodConditionCache.put(
HttpMethod.valueOf(method.name()), new RequestMethodsRequestCondition(method));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.web.reactive.function.server;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -31,6 +30,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.result.view.View;
import org.springframework.web.reactive.result.view.ViewResolver;
@ -103,7 +103,7 @@ class RenderingResponseIntegrationTests extends AbstractRouterFunctionIntegratio
private Map<String, String> parseBody(String body) {
String[] lines = body.split("\\n");
Map<String, String> result = new LinkedHashMap<>(lines.length);
Map<String, String> result = CollectionUtils.newLinkedHashMap(lines.length);
for (String line : lines) {
int idx = line.indexOf('=');
String key = line.substring(0, idx);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2020 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.
@ -52,7 +52,7 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
@Nullable
private String targetRequestPath;
private final MultiValueMap<String, String> targetRequestParams = new LinkedMultiValueMap<>(4);
private final MultiValueMap<String, String> targetRequestParams = new LinkedMultiValueMap<>(3);
private long expirationTime = -1;

View File

@ -17,10 +17,10 @@
package org.springframework.web.servlet.config.annotation;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.CorsConfiguration;
/**
@ -56,7 +56,7 @@ public class CorsRegistry {
* keyed by path pattern.
*/
protected Map<String, CorsConfiguration> getCorsConfigurations() {
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
Map<String, CorsConfiguration> configs = CollectionUtils.newLinkedHashMap(this.registrations.size());
for (CorsRegistration registration : this.registrations) {
configs.put(registration.getPathPattern(), registration.getCorsConfiguration());
}

View File

@ -19,7 +19,6 @@ package org.springframework.web.servlet.mvc.condition;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@ -30,6 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.cors.CorsUtils;
@ -48,7 +48,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
private static final Map<String, RequestMethodsRequestCondition> requestMethodConditionCache;
static {
requestMethodConditionCache = new HashMap<>(RequestMethod.values().length);
requestMethodConditionCache = CollectionUtils.newHashMap(RequestMethod.values().length);
for (RequestMethod method : RequestMethod.values()) {
requestMethodConditionCache.put(method.name(), new RequestMethodsRequestCondition(method));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@ -332,7 +332,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
size += (model != null ? model.size() : 0);
size += (pathVars != null ? pathVars.size() : 0);
Map<String, Object> mergedModel = new LinkedHashMap<>(size);
Map<String, Object> mergedModel = CollectionUtils.newLinkedHashMap(size);
mergedModel.putAll(this.staticAttributes);
if (pathVars != null) {
mergedModel.putAll(pathVars);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.web.servlet.view.json;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@ -155,7 +154,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View {
*/
@Override
protected Object filterModel(Map<String, Object> model) {
Map<String, Object> result = new HashMap<>(model.size());
Map<String, Object> result = CollectionUtils.newHashMap(model.size());
Set<String> modelKeys = (!CollectionUtils.isEmpty(this.modelKeys) ? this.modelKeys : model.keySet());
model.forEach((clazz, value) -> {
if (!(value instanceof BindingResult) && modelKeys.contains(clazz) &&

View File

@ -18,7 +18,6 @@ package org.springframework.web.socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -154,7 +153,7 @@ public class WebSocketExtension {
Map<String, String> parameters = null;
if (parts.length > 1) {
parameters = new LinkedHashMap<>(parts.length - 1);
parameters = CollectionUtils.newLinkedHashMap(parts.length - 1);
for (int i = 1; i < parts.length; i++) {
String parameter = parts[i];
int eqIndex = parameter.indexOf('=');