Apply "instanceof pattern matching" Eclipse clean-up in spring-core

This commit also applies additional clean-up tasks such as the following.

- final fields
- diamond operator (<>) for anonymous inner classes

This has only been applied to `src/main/java`.
This commit is contained in:
Sam Brannen 2021-10-14 18:12:27 +02:00
parent 9b9906cfc4
commit cb17441780
31 changed files with 108 additions and 142 deletions

View File

@ -119,7 +119,7 @@ public final class CollectionFactory {
* @see java.util.TreeSet
* @see java.util.LinkedHashSet
*/
@SuppressWarnings({"rawtypes", "unchecked", "cast"})
@SuppressWarnings({"rawtypes", "unchecked"})
public static <E> Collection<E> createApproximateCollection(@Nullable Object collection, int capacity) {
if (collection instanceof LinkedList) {
return new LinkedList<>();
@ -127,14 +127,13 @@ public final class CollectionFactory {
else if (collection instanceof List) {
return new ArrayList<>(capacity);
}
else if (collection instanceof EnumSet) {
// Cast is necessary for compilation in Eclipse 4.4.1.
Collection<E> enumSet = (Collection<E>) EnumSet.copyOf((EnumSet) collection);
enumSet.clear();
return enumSet;
else if (collection instanceof EnumSet enumSet) {
Collection<E> copy = EnumSet.copyOf(enumSet);
copy.clear();
return copy;
}
else if (collection instanceof SortedSet) {
return new TreeSet<>(((SortedSet<E>) collection).comparator());
else if (collection instanceof SortedSet sortedSet) {
return new TreeSet<>(sortedSet.comparator());
}
else {
return new LinkedHashSet<>(capacity);
@ -178,7 +177,7 @@ public final class CollectionFactory {
* @see java.util.TreeSet
* @see java.util.EnumSet
*/
@SuppressWarnings({"unchecked", "cast"})
@SuppressWarnings("unchecked")
public static <E> Collection<E> createCollection(Class<?> collectionType, @Nullable Class<?> elementType, int capacity) {
Assert.notNull(collectionType, "Collection type must not be null");
if (collectionType.isInterface()) {
@ -197,8 +196,7 @@ public final class CollectionFactory {
}
else if (EnumSet.class.isAssignableFrom(collectionType)) {
Assert.notNull(elementType, "Cannot create EnumSet for unknown element type");
// Cast is necessary for compilation in Eclipse 4.4.1.
return (Collection<E>) EnumSet.noneOf(asEnumType(elementType));
return EnumSet.noneOf(asEnumType(elementType));
}
else {
if (!Collection.class.isAssignableFrom(collectionType)) {
@ -243,13 +241,13 @@ public final class CollectionFactory {
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static <K, V> Map<K, V> createApproximateMap(@Nullable Object map, int capacity) {
if (map instanceof EnumMap) {
EnumMap enumMap = new EnumMap((EnumMap) map);
enumMap.clear();
return enumMap;
if (map instanceof EnumMap enumMap) {
EnumMap copy = new EnumMap(enumMap);
copy.clear();
return copy;
}
else if (map instanceof SortedMap) {
return new TreeMap<>(((SortedMap<K, V>) map).comparator());
else if (map instanceof SortedMap sortedMap) {
return new TreeMap<>(sortedMap.comparator());
}
else {
return new LinkedHashMap<>(capacity);

View File

@ -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.
@ -54,10 +54,9 @@ public final class MethodClassKey implements Comparable<MethodClassKey> {
if (this == other) {
return true;
}
if (!(other instanceof MethodClassKey)) {
if (!(other instanceof MethodClassKey otherKey)) {
return false;
}
MethodClassKey otherKey = (MethodClassKey) other;
return (this.method.equals(otherKey.method) &&
ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -753,10 +753,9 @@ public class MethodParameter {
if (this == other) {
return true;
}
if (!(other instanceof MethodParameter)) {
if (!(other instanceof MethodParameter otherParam)) {
return false;
}
MethodParameter otherParam = (MethodParameter) other;
return (getContainingClass() == otherParam.getContainingClass() &&
ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) &&
this.nestingLevel == otherParam.nestingLevel &&

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -92,7 +92,7 @@ public abstract class ParameterizedTypeReference<T> {
* @since 4.3.12
*/
public static <T> ParameterizedTypeReference<T> forType(Type type) {
return new ParameterizedTypeReference<T>(type) {
return new ParameterizedTypeReference<>(type) {
};
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -594,8 +594,7 @@ public class ResolvableType implements Serializable {
* without specific bounds (i.e., equal to {@code ? extends Object}).
*/
private boolean isWildcardWithoutBounds() {
if (this.type instanceof WildcardType) {
WildcardType wt = (WildcardType) this.type;
if (this.type instanceof WildcardType wt) {
if (wt.getLowerBounds().length == 0) {
Type[] upperBounds = wt.getUpperBounds();
if (upperBounds.length == 0 || (upperBounds.length == 1 && Object.class == upperBounds[0])) {
@ -870,8 +869,7 @@ public class ResolvableType implements Serializable {
if (this.type instanceof TypeVariable) {
return resolveType().resolveVariable(variable);
}
if (this.type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) this.type;
if (this.type instanceof ParameterizedType parameterizedType) {
Class<?> resolved = resolve();
if (resolved == null) {
return null;
@ -906,11 +904,10 @@ public class ResolvableType implements Serializable {
if (this == other) {
return true;
}
if (!(other instanceof ResolvableType)) {
if (!(other instanceof ResolvableType otherType)) {
return false;
}
ResolvableType otherType = (ResolvableType) other;
if (!ObjectUtils.nullSafeEquals(this.type, otherType.type)) {
return false;
}
@ -1573,10 +1570,9 @@ public class ResolvableType implements Serializable {
if (this == other) {
return true;
}
if (!(other instanceof ParameterizedType)) {
if (!(other instanceof ParameterizedType otherType)) {
return false;
}
ParameterizedType otherType = (ParameterizedType) other;
return (otherType.getOwnerType() == null && this.rawType.equals(otherType.getRawType()) &&
Arrays.equals(this.typeArguments, otherType.getActualTypeArguments()));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -1006,12 +1006,10 @@ public abstract class AnnotationUtils {
return names;
}
}
if (value instanceof Annotation) {
Annotation annotation = (Annotation) value;
if (value instanceof Annotation annotation) {
return MergedAnnotation.from(annotatedElement, annotation).synthesize();
}
if (value instanceof Annotation[]) {
Annotation[] annotations = (Annotation[]) value;
if (value instanceof Annotation[] annotations) {
Annotation[] synthesized = (Annotation[]) Array.newInstance(
annotations.getClass().getComponentType(), annotations.length);
for (int i = 0; i < annotations.length; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -521,8 +521,7 @@ abstract class AnnotationsScanner {
return (searchStrategy == SearchStrategy.TYPE_HIERARCHY_AND_ENCLOSING_CLASSES ? noSuperTypes &&
sourceClass.getEnclosingClass() == null : noSuperTypes);
}
if (source instanceof Method) {
Method sourceMethod = (Method) source;
if (source instanceof Method sourceMethod) {
return (Modifier.isPrivate(sourceMethod.getModifiers()) ||
isWithoutHierarchy(sourceMethod.getDeclaringClass(), searchStrategy));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -221,7 +221,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations {
private class AnnotationsSpliterator<A extends Annotation> implements Spliterator<MergedAnnotation<A>> {
@Nullable
private Object requiredType;
private final Object requiredType;
private final int[] mappingCursors;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -439,8 +439,7 @@ final class TypeMappedAnnotation<A extends Annotation> extends AbstractMergedAnn
}
value = names;
}
else if (value instanceof String[] && type == Class[].class) {
String[] names = (String[]) value;
else if (value instanceof String[] names && type == Class[].class) {
Class<?>[] classes = new Class<?>[names.length];
for (int i = 0; i < names.length; i++) {
classes[i] = ClassUtils.resolveClassName(names[i], getClassLoader());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -263,10 +263,9 @@ public final class Property {
if (this == other) {
return true;
}
if (!(other instanceof Property)) {
if (!(other instanceof Property otherProperty)) {
return false;
}
Property otherProperty = (Property) other;
return (ObjectUtils.nullSafeEquals(this.objectType, otherProperty.objectType) &&
ObjectUtils.nullSafeEquals(this.name, otherProperty.name) &&
ObjectUtils.nullSafeEquals(this.readMethod, otherProperty.readMethod) &&

View File

@ -458,10 +458,9 @@ public class TypeDescriptor implements Serializable {
if (this == other) {
return true;
}
if (!(other instanceof TypeDescriptor)) {
if (!(other instanceof TypeDescriptor otherDesc)) {
return false;
}
TypeDescriptor otherDesc = (TypeDescriptor) other;
if (getType() != otherDesc.getType()) {
return false;
}

View File

@ -88,8 +88,7 @@ final class ByteBufferConverter implements ConditionalGenericConverter {
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
boolean byteBufferTarget = targetType.isAssignableTo(BYTE_BUFFER_TYPE);
if (source instanceof ByteBuffer) {
ByteBuffer buffer = (ByteBuffer) source;
if (source instanceof ByteBuffer buffer) {
return (byteBufferTarget ? buffer.duplicate() : convertFromByteBuffer(buffer, targetType));
}
if (byteBufferTarget) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -463,10 +463,9 @@ public class GenericConversionService implements ConfigurableConversionService {
if (this == other) {
return true;
}
if (!(other instanceof ConverterCacheKey)) {
if (!(other instanceof ConverterCacheKey otherKey)) {
return false;
}
ConverterCacheKey otherKey = (ConverterCacheKey) other;
return (this.sourceType.equals(otherKey.sourceType)) &&
this.targetType.equals(otherKey.targetType);
}

View File

@ -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.
@ -92,8 +92,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
Member member = getValidatedMember(targetClass, sourceClass);
try {
if (member instanceof Method) {
Method method = (Method) member;
if (member instanceof Method method) {
ReflectionUtils.makeAccessible(method);
if (!Modifier.isStatic(method.getModifiers())) {
return method.invoke(source);
@ -152,8 +151,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter {
}
private static boolean isApplicable(Member member, Class<?> sourceClass) {
if (member instanceof Method) {
Method method = (Method) member;
if (member instanceof Method method) {
return (!Modifier.isStatic(method.getModifiers()) ?
ClassUtils.isAssignable(method.getDeclaringClass(), sourceClass) :
method.getParameterTypes()[0] == sourceClass);

View File

@ -106,8 +106,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
// Try InputStream resolution for jar resources
URLConnection con = url.openConnection();
customizeConnection(con);
if (con instanceof HttpURLConnection) {
HttpURLConnection httpCon = (HttpURLConnection) con;
if (con instanceof HttpURLConnection httpCon) {
int code = httpCon.getResponseCode();
if (code != HttpURLConnection.HTTP_OK) {
httpCon.disconnect();

View File

@ -267,10 +267,9 @@ public class ClassPathResource extends AbstractFileResolvingResource {
if (this == other) {
return true;
}
if (!(other instanceof ClassPathResource)) {
if (!(other instanceof ClassPathResource otherRes)) {
return false;
}
ClassPathResource otherRes = (ClassPathResource) other;
return (this.path.equals(otherRes.path) &&
ObjectUtils.nullSafeEquals(this.classLoader, otherRes.classLoader) &&
ObjectUtils.nullSafeEquals(this.clazz, otherRes.clazz));

View File

@ -513,8 +513,7 @@ public abstract class DataBufferUtils {
* @return {@code true} if the buffer was released; {@code false} otherwise.
*/
public static boolean release(@Nullable DataBuffer dataBuffer) {
if (dataBuffer instanceof PooledDataBuffer) {
PooledDataBuffer pooledDataBuffer = (PooledDataBuffer) dataBuffer;
if (dataBuffer instanceof PooledDataBuffer pooledDataBuffer) {
if (pooledDataBuffer.isAllocated()) {
try {
return pooledDataBuffer.release();

View File

@ -431,10 +431,9 @@ public class DefaultDataBuffer implements DataBuffer {
if (this == other) {
return true;
}
if (!(other instanceof DefaultDataBuffer)) {
if (!(other instanceof DefaultDataBuffer otherBuffer)) {
return false;
}
DefaultDataBuffer otherBuffer = (DefaultDataBuffer) other;
return (this.readPosition == otherBuffer.readPosition &&
this.writePosition == otherBuffer.writePosition &&
this.byteBuffer.equals(otherBuffer.byteBuffer));

View File

@ -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.
@ -165,10 +165,9 @@ public class EncodedResource implements InputStreamSource {
if (this == other) {
return true;
}
if (!(other instanceof EncodedResource)) {
if (!(other instanceof EncodedResource otherResource)) {
return false;
}
EncodedResource otherResource = (EncodedResource) other;
return (this.resource.equals(otherResource.resource) &&
ObjectUtils.nullSafeEquals(this.charset, otherResource.charset) &&
ObjectUtils.nullSafeEquals(this.encoding, otherResource.encoding));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -368,9 +368,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
* @since 4.1.1
*/
protected void addAllClassLoaderJarRoots(@Nullable ClassLoader classLoader, Set<Resource> result) {
if (classLoader instanceof URLClassLoader) {
if (classLoader instanceof URLClassLoader urlClassLoader) {
try {
for (URL url : ((URLClassLoader) classLoader).getURLs()) {
for (URL url : urlClassLoader.getURLs()) {
try {
UrlResource jarResource = (ResourceUtils.URL_PROTOCOL_JAR.equals(url.getProtocol()) ?
new UrlResource(url) :
@ -597,9 +597,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
String rootEntryPath;
boolean closeJarFile;
if (con instanceof JarURLConnection) {
if (con instanceof JarURLConnection jarCon) {
// Should usually be the case for traditional JAR files.
JarURLConnection jarCon = (JarURLConnection) con;
ResourceUtils.useCachesIfNecessary(jarCon);
jarFile = jarCon.getJarFile();
jarFileUrl = jarCon.getJarFileURL().toExternalForm();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -143,7 +143,7 @@ public abstract class LogMessage implements CharSequence {
private static final class SupplierMessage extends LogMessage {
private Supplier<? extends CharSequence> supplier;
private final Supplier<? extends CharSequence> supplier;
SupplierMessage(Supplier<? extends CharSequence> supplier) {
Assert.notNull(supplier, "Supplier must not be null");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -61,8 +61,7 @@ public class DefaultValueStyler implements ValueStyler {
else if (value instanceof Class) {
return ClassUtils.getShortName((Class<?>) value);
}
else if (value instanceof Method) {
Method method = (Method) value;
else if (value instanceof Method method) {
return method.getName() + "@" + ClassUtils.getShortName(method.getDeclaringClass());
}
else if (value instanceof Map) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -61,8 +61,7 @@ abstract class AnnotationReadingVisitorUtils {
value = convertClassValues(
annotatedElement, classLoader, (AnnotationAttributes) value, classValuesAsString);
}
else if (value instanceof AnnotationAttributes[]) {
AnnotationAttributes[] values = (AnnotationAttributes[]) value;
else if (value instanceof AnnotationAttributes[] values) {
for (int i = 0; i < values.length; i++) {
values[i] = convertClassValues(annotatedElement, classLoader, values[i], classValuesAsString);
}
@ -72,8 +71,7 @@ abstract class AnnotationReadingVisitorUtils {
value = (classValuesAsString ? ((Type) value).getClassName() :
ClassUtils.forName(((Type) value).getClassName(), classLoader));
}
else if (value instanceof Type[]) {
Type[] array = (Type[]) value;
else if (value instanceof Type[] array) {
Object[] convArray =
(classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
for (int i = 0; i < array.length; i++) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -69,7 +69,7 @@ class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata
private String[] interfaces = new String[0];
private Set<String> memberClassNames = new LinkedHashSet<>(4);
private final Set<String> memberClassNames = new LinkedHashSet<>(4);
public ClassMetadataReadingVisitor() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 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.
@ -59,11 +59,11 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor {
private boolean independentInnerClass;
private Set<String> memberClassNames = new LinkedHashSet<>(4);
private final Set<String> memberClassNames = new LinkedHashSet<>(4);
private List<MergedAnnotation<?>> annotations = new ArrayList<>();
private final List<MergedAnnotation<?>> annotations = new ArrayList<>();
private List<SimpleMethodMetadata> annotatedMethods = new ArrayList<>();
private final List<SimpleMethodMetadata> annotatedMethods = new ArrayList<>();
@Nullable
private SimpleAnnotationMetadata metadata;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 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.
@ -102,10 +102,12 @@ public class SpringObjenesis implements Objenesis {
return getInstantiatorOf(clazz).newInstance();
}
@Override
public <T> T newInstance(Class<T> clazz) {
return getInstantiatorOf(clazz).newInstance();
}
@Override
@SuppressWarnings("unchecked")
public <T> ObjectInstantiator<T> getInstantiatorOf(Class<T> clazz) {
ObjectInstantiator<?> instantiator = this.cache.get(clazz);

View File

@ -762,10 +762,9 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
if (this == other) {
return true;
}
if (!(other instanceof Map.Entry)) {
if (!(other instanceof Map.Entry otherEntry)) {
return false;
}
Map.Entry otherEntry = (Map.Entry) other;
return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) &&
ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue()));
}
@ -853,8 +852,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public boolean contains(@Nullable Object o) {
if (o instanceof Map.Entry<?, ?>) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
if (o instanceof Map.Entry<?, ?> entry) {
Reference<K, V> ref = ConcurrentReferenceHashMap.this.getReference(entry.getKey(), Restructure.NEVER);
Entry<K, V> otherEntry = (ref != null ? ref.get() : null);
if (otherEntry != null) {
@ -866,8 +864,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
@Override
public boolean remove(Object o) {
if (o instanceof Map.Entry<?, ?>) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) o;
if (o instanceof Map.Entry<?, ?> entry) {
return ConcurrentReferenceHashMap.this.remove(entry.getKey(), entry.getValue());
}
return false;

View File

@ -110,7 +110,7 @@ public class LinkedCaseInsensitiveMap<V> implements Map<String, V>, Serializable
* @see #convertKey(String)
*/
public LinkedCaseInsensitiveMap(int expectedSize, @Nullable Locale locale) {
this.targetMap = new LinkedHashMap<String, V>(
this.targetMap = new LinkedHashMap<>(
(int) (expectedSize / CollectionUtils.DEFAULT_LOAD_FACTOR), CollectionUtils.DEFAULT_LOAD_FACTOR) {
@Override
public boolean containsKey(Object key) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -453,10 +453,9 @@ public class MimeType implements Comparable<MimeType>, Serializable {
if (this == other) {
return true;
}
if (!(other instanceof MimeType)) {
if (!(other instanceof MimeType otherType)) {
return false;
}
MimeType otherType = (MimeType) other;
return (this.type.equalsIgnoreCase(otherType.type) &&
this.subtype.equalsIgnoreCase(otherType.subtype) &&
parametersAreEqual(otherType));

View File

@ -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.
@ -25,11 +25,12 @@ import org.springframework.lang.Nullable;
/**
* Utility to work with Java 5 generic type parameters.
* Mainly for internal use within the framework.
* <p>Mainly for internal use within the framework.
*
* @author Ramnivas Laddad
* @author Juergen Hoeller
* @author Chris Beams
* @author Sam Brannen
* @since 2.0.7
*/
public abstract class TypeUtils {
@ -50,62 +51,56 @@ public abstract class TypeUtils {
return true;
}
if (lhsType instanceof Class) {
Class<?> lhsClass = (Class<?>) lhsType;
if (lhsType instanceof Class<?> lhsClass) {
// just comparing two classes
if (rhsType instanceof Class) {
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsType);
if (rhsType instanceof Class<?> rhsClass) {
return ClassUtils.isAssignable(lhsClass, rhsClass);
}
if (rhsType instanceof ParameterizedType) {
Type rhsRaw = ((ParameterizedType) rhsType).getRawType();
if (rhsType instanceof ParameterizedType rhsParameterizedType) {
Type rhsRaw = rhsParameterizedType.getRawType();
// a parameterized type is always assignable to its raw class type
if (rhsRaw instanceof Class) {
return ClassUtils.isAssignable(lhsClass, (Class<?>) rhsRaw);
if (rhsRaw instanceof Class<?> rhRawClass) {
return ClassUtils.isAssignable(lhsClass, rhRawClass);
}
}
else if (lhsClass.isArray() && rhsType instanceof GenericArrayType) {
Type rhsComponent = ((GenericArrayType) rhsType).getGenericComponentType();
else if (lhsClass.isArray() && rhsType instanceof GenericArrayType rhsGenericArrayType) {
Type rhsComponent = rhsGenericArrayType.getGenericComponentType();
return isAssignable(lhsClass.getComponentType(), rhsComponent);
}
}
// parameterized types are only assignable to other parameterized types and class types
if (lhsType instanceof ParameterizedType) {
if (rhsType instanceof Class) {
Type lhsRaw = ((ParameterizedType) lhsType).getRawType();
if (lhsType instanceof ParameterizedType lhsParameterizedType) {
if (rhsType instanceof Class<?> rhsClass) {
Type lhsRaw = lhsParameterizedType.getRawType();
if (lhsRaw instanceof Class) {
return ClassUtils.isAssignable((Class<?>) lhsRaw, (Class<?>) rhsType);
if (lhsRaw instanceof Class<?> lhsClass) {
return ClassUtils.isAssignable(lhsClass, rhsClass);
}
}
else if (rhsType instanceof ParameterizedType) {
return isAssignable((ParameterizedType) lhsType, (ParameterizedType) rhsType);
else if (rhsType instanceof ParameterizedType rhsParameterizedType) {
return isAssignable(lhsParameterizedType, rhsParameterizedType);
}
}
if (lhsType instanceof GenericArrayType) {
Type lhsComponent = ((GenericArrayType) lhsType).getGenericComponentType();
if (lhsType instanceof GenericArrayType lhsGenericArrayType) {
Type lhsComponent = lhsGenericArrayType.getGenericComponentType();
if (rhsType instanceof Class) {
Class<?> rhsClass = (Class<?>) rhsType;
if (rhsClass.isArray()) {
return isAssignable(lhsComponent, rhsClass.getComponentType());
}
if (rhsType instanceof Class<?> rhsClass && rhsClass.isArray()) {
return isAssignable(lhsComponent, rhsClass.getComponentType());
}
else if (rhsType instanceof GenericArrayType) {
Type rhsComponent = ((GenericArrayType) rhsType).getGenericComponentType();
else if (rhsType instanceof GenericArrayType rhsGenericArrayType) {
Type rhsComponent = rhsGenericArrayType.getGenericComponentType();
return isAssignable(lhsComponent, rhsComponent);
}
}
if (lhsType instanceof WildcardType) {
return isAssignable((WildcardType) lhsType, rhsType);
if (lhsType instanceof WildcardType lhsWildcardType) {
return isAssignable(lhsWildcardType, rhsType);
}
return false;
@ -128,7 +123,7 @@ public abstract class TypeUtils {
Type rhsArg = rhsTypeArguments[i];
if (!lhsArg.equals(rhsArg) &&
!(lhsArg instanceof WildcardType && isAssignable((WildcardType) lhsArg, rhsArg))) {
!(lhsArg instanceof WildcardType wildcardType && isAssignable(wildcardType, rhsArg))) {
return false;
}
}
@ -151,11 +146,10 @@ public abstract class TypeUtils {
lLowerBounds = new Type[] { null };
}
if (rhsType instanceof WildcardType) {
if (rhsType instanceof WildcardType rhsWcType) {
// both the upper and lower bounds of the right-hand side must be
// completely enclosed in the upper and lower bounds of the left-
// hand side.
WildcardType rhsWcType = (WildcardType) rhsType;
Type[] rUpperBounds = rhsWcType.getUpperBounds();
if (rUpperBounds.length == 0) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 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.
@ -22,6 +22,7 @@ import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Comment;
@ -155,7 +156,7 @@ class XMLEventStreamReader extends AbstractXMLStreamReader {
if (this.event.isCharacters()) {
return this.event.asCharacters().getData();
}
else if (this.event.getEventType() == XMLEvent.COMMENT) {
else if (this.event.getEventType() == XMLStreamConstants.COMMENT) {
return ((Comment) this.event).getText();
}
else {