Use Collection factory methods when applicable
This commit replaces the use of Collections.unmodifiableList/Set/Map with the corresponding 'of(...)' factory methods introduced in Java 9. Closes gh-27824
This commit is contained in:
committed by
Sam Brannen
parent
ab240f5d8e
commit
941b6af9ac
@@ -21,7 +21,6 @@ import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -70,20 +69,16 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnnotation<A> {
|
||||
|
||||
private static final Map<Class<?>, Object> EMPTY_ARRAYS;
|
||||
static {
|
||||
Map<Class<?>, Object> emptyArrays = new HashMap<>();
|
||||
emptyArrays.put(boolean.class, new boolean[0]);
|
||||
emptyArrays.put(byte.class, new byte[0]);
|
||||
emptyArrays.put(char.class, new char[0]);
|
||||
emptyArrays.put(double.class, new double[0]);
|
||||
emptyArrays.put(float.class, new float[0]);
|
||||
emptyArrays.put(int.class, new int[0]);
|
||||
emptyArrays.put(long.class, new long[0]);
|
||||
emptyArrays.put(short.class, new short[0]);
|
||||
emptyArrays.put(String.class, new String[0]);
|
||||
EMPTY_ARRAYS = Collections.unmodifiableMap(emptyArrays);
|
||||
}
|
||||
private static final Map<Class<?>, Object> EMPTY_ARRAYS = Map.of(
|
||||
boolean.class, new boolean[0],
|
||||
byte.class, new byte[0],
|
||||
char.class, new char[0],
|
||||
double.class, new double[0],
|
||||
float.class, new float[0],
|
||||
int.class, new int[0],
|
||||
long.class, new long[0],
|
||||
short.class, new short[0],
|
||||
String.class, new String[0]);
|
||||
|
||||
|
||||
private final AnnotationTypeMapping mapping;
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.core.convert.support;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -40,17 +38,11 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
|
||||
|
||||
private static final TypeDescriptor BYTE_ARRAY_TYPE = TypeDescriptor.valueOf(byte[].class);
|
||||
|
||||
private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS;
|
||||
|
||||
static {
|
||||
Set<ConvertiblePair> convertiblePairs = new HashSet<>(4);
|
||||
convertiblePairs.add(new ConvertiblePair(ByteBuffer.class, byte[].class));
|
||||
convertiblePairs.add(new ConvertiblePair(byte[].class, ByteBuffer.class));
|
||||
convertiblePairs.add(new ConvertiblePair(ByteBuffer.class, Object.class));
|
||||
convertiblePairs.add(new ConvertiblePair(Object.class, ByteBuffer.class));
|
||||
CONVERTIBLE_PAIRS = Collections.unmodifiableSet(convertiblePairs);
|
||||
}
|
||||
|
||||
private static final Set<ConvertiblePair> CONVERTIBLE_PAIRS = Set.of(
|
||||
new ConvertiblePair(ByteBuffer.class, byte[].class),
|
||||
new ConvertiblePair(byte[].class, ByteBuffer.class),
|
||||
new ConvertiblePair(ByteBuffer.class, Object.class),
|
||||
new ConvertiblePair(Object.class, ByteBuffer.class));
|
||||
|
||||
private final ConversionService conversionService;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -21,8 +21,6 @@ import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -46,21 +44,15 @@ public abstract class NumberUtils {
|
||||
* Standard number types (all immutable):
|
||||
* Byte, Short, Integer, Long, BigInteger, Float, Double, BigDecimal.
|
||||
*/
|
||||
public static final Set<Class<?>> STANDARD_NUMBER_TYPES;
|
||||
|
||||
static {
|
||||
Set<Class<?>> numberTypes = new HashSet<>(8);
|
||||
numberTypes.add(Byte.class);
|
||||
numberTypes.add(Short.class);
|
||||
numberTypes.add(Integer.class);
|
||||
numberTypes.add(Long.class);
|
||||
numberTypes.add(BigInteger.class);
|
||||
numberTypes.add(Float.class);
|
||||
numberTypes.add(Double.class);
|
||||
numberTypes.add(BigDecimal.class);
|
||||
STANDARD_NUMBER_TYPES = Collections.unmodifiableSet(numberTypes);
|
||||
}
|
||||
|
||||
public static final Set<Class<?>> STANDARD_NUMBER_TYPES = Set.of(
|
||||
Byte.class,
|
||||
Short.class,
|
||||
Integer.class,
|
||||
Long.class,
|
||||
BigInteger.class,
|
||||
Float.class,
|
||||
Double.class,
|
||||
BigDecimal.class);
|
||||
|
||||
/**
|
||||
* Convert the given number into an instance of the given target class.
|
||||
|
||||
Reference in New Issue
Block a user