From 8ebd746d69cfe551eab87db97d647aa5ba51e839 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 5 Mar 2023 17:21:32 +0100 Subject: [PATCH] Apply "instanceof pattern matching" in remainder of spring-core module See gh-30067 --- .../cglib/beans/BeanGenerator.java | 2 +- .../springframework/cglib/core/EmitUtils.java | 17 ++++++++--------- .../cglib/core/internal/LoadingCache.java | 4 ++-- .../cglib/reflect/FastClass.java | 4 ++-- .../core/AttributeAccessorSupport.java | 8 ++++---- .../org/springframework/core/Constants.java | 6 +++--- .../core/GenericTypeResolver.java | 7 +++---- .../springframework/core/MethodParameter.java | 6 +++--- .../springframework/core/OrderComparator.java | 4 ++-- .../core/ParameterizedTypeReference.java | 7 +++---- .../core/ReactiveAdapterRegistry.java | 4 ++-- .../springframework/core/ResolvableType.java | 7 +++---- .../core/SerializableTypeWrapper.java | 4 ++-- .../AnnotationAwareOrderComparator.java | 2 +- .../org/springframework/core/codec/Decoder.java | 2 +- .../core/convert/TypeDescriptor.java | 8 ++++---- .../support/ObjectToOptionalConverter.java | 2 +- .../core/io/buffer/Netty5DataBuffer.java | 5 ++--- .../core/io/buffer/NettyDataBuffer.java | 5 ++--- .../core/type/StandardClassMetadata.java | 6 +++--- .../core/type/StandardMethodMetadata.java | 6 +++--- .../classreading/SimpleAnnotationMetadata.java | 5 ++--- .../type/classreading/SimpleMethodMetadata.java | 5 ++--- .../springframework/util/CollectionUtils.java | 10 +++++----- .../util/LinkedCaseInsensitiveMap.java | 4 ++-- .../org/springframework/util/NumberUtils.java | 6 +++--- .../org/springframework/util/StringUtils.java | 4 ++-- .../util/comparator/BooleanComparator.java | 7 +++---- 28 files changed, 74 insertions(+), 83 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/cglib/beans/BeanGenerator.java b/spring-core/src/main/java/org/springframework/cglib/beans/BeanGenerator.java index b6b4fb9e7c..36cc0cdac5 100644 --- a/spring-core/src/main/java/org/springframework/cglib/beans/BeanGenerator.java +++ b/spring-core/src/main/java/org/springframework/cglib/beans/BeanGenerator.java @@ -139,7 +139,7 @@ public class BeanGenerator extends AbstractClassGenerator @Override protected Object nextInstance(Object instance) { - Class protoclass = (instance instanceof Class) ? (Class)instance : instance.getClass(); + Class protoclass = (instance instanceof Class clazz) ? clazz : instance.getClass(); if (classOnly) { return protoclass; } else { diff --git a/spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java b/spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java index 822f38d5e8..a932f4f886 100644 --- a/spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java +++ b/spring-core/src/main/java/org/springframework/cglib/core/EmitUtils.java @@ -367,15 +367,14 @@ public class EmitUtils { if (obj == null) { e.aconst_null(); } else { - Class type = obj.getClass(); - if (type.isArray()) { - push_array(e, (Object[])obj); - } else if (obj instanceof String) { - e.push((String)obj); - } else if (obj instanceof Type) { - load_class(e, (Type)obj); - } else if (obj instanceof Class) { - load_class(e, Type.getType((Class)obj)); + if (obj.getClass().isArray()) { + push_array(e, (Object[]) obj); + } else if (obj instanceof String text) { + e.push(text); + } else if (obj instanceof Type type) { + load_class(e, type); + } else if (obj instanceof Class clazz) { + load_class(e, Type.getType(clazz)); } else if (obj instanceof BigInteger) { e.new_instance(Constants.TYPE_BIG_INTEGER); e.dup(); diff --git a/spring-core/src/main/java/org/springframework/cglib/core/internal/LoadingCache.java b/spring-core/src/main/java/org/springframework/cglib/core/internal/LoadingCache.java index 2bbc10e8db..c7e2eee3a7 100644 --- a/spring-core/src/main/java/org/springframework/cglib/core/internal/LoadingCache.java +++ b/spring-core/src/main/java/org/springframework/cglib/core/internal/LoadingCache.java @@ -69,8 +69,8 @@ public class LoadingCache { throw new IllegalStateException("Interrupted while loading cache item", e); } catch (ExecutionException e) { Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) { - throw ((RuntimeException) cause); + if (cause instanceof RuntimeException runtimeException) { + throw runtimeException; } throw new IllegalStateException("Unable to load cache item", cause); } diff --git a/spring-core/src/main/java/org/springframework/cglib/reflect/FastClass.java b/spring-core/src/main/java/org/springframework/cglib/reflect/FastClass.java index f2ad481761..87d51b0ff3 100644 --- a/spring-core/src/main/java/org/springframework/cglib/reflect/FastClass.java +++ b/spring-core/src/main/java/org/springframework/cglib/reflect/FastClass.java @@ -154,10 +154,10 @@ abstract public class FastClass @Override public boolean equals(Object o) { - if (o == null || !(o instanceof FastClass)) { + if (o == null || !(o instanceof FastClass that)) { return false; } - return type.equals(((FastClass)o).type); + return type.equals(that.type); } /** diff --git a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java index f5c788d5f4..2f1c15c75e 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -105,9 +105,9 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof AttributeAccessorSupport && - this.attributes.equals(((AttributeAccessorSupport) other).attributes))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof AttributeAccessorSupport that && + this.attributes.equals(that.attributes))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/Constants.java b/spring-core/src/main/java/org/springframework/core/Constants.java index 9cb3e7af71..1c949d19d7 100644 --- a/spring-core/src/main/java/org/springframework/core/Constants.java +++ b/spring-core/src/main/java/org/springframework/core/Constants.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -111,10 +111,10 @@ public class Constants { */ public Number asNumber(String code) throws ConstantException { Object obj = asObject(code); - if (!(obj instanceof Number)) { + if (!(obj instanceof Number number)) { throw new ConstantException(this.className, code, "not a Number"); } - return (Number) obj; + return number; } /** diff --git a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java index e9a0895e39..27f8682f47 100644 --- a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java +++ b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -172,9 +172,8 @@ public final class GenericTypeResolver { ResolvableType contextType = ResolvableType.forClass(contextClass); for (int i = 0; i < typeArguments.length; i++) { Type typeArgument = typeArguments[i]; - if (typeArgument instanceof TypeVariable) { - ResolvableType resolvedTypeArgument = resolveVariable( - (TypeVariable) typeArgument, contextType); + if (typeArgument instanceof TypeVariable typeVariable) { + ResolvableType resolvedTypeArgument = resolveVariable(typeVariable, contextType); if (resolvedTypeArgument != ResolvableType.NONE) { generics[i] = resolvedTypeArgument.resolve(); } diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 268184eab8..556005cf3d 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -195,7 +195,7 @@ public class MethodParameter { */ @Nullable public Method getMethod() { - return (this.executable instanceof Method ? (Method) this.executable : null); + return (this.executable instanceof Method method ? method : null); } /** @@ -205,7 +205,7 @@ public class MethodParameter { */ @Nullable public Constructor getConstructor() { - return (this.executable instanceof Constructor ? (Constructor) this.executable : null); + return (this.executable instanceof Constructor constructor ? constructor : null); } /** diff --git a/spring-core/src/main/java/org/springframework/core/OrderComparator.java b/spring-core/src/main/java/org/springframework/core/OrderComparator.java index 341ae09cb5..2724a414cf 100644 --- a/spring-core/src/main/java/org/springframework/core/OrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/OrderComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -142,7 +142,7 @@ public class OrderComparator implements Comparator { */ @Nullable protected Integer findOrder(Object obj) { - return (obj instanceof Ordered ? ((Ordered) obj).getOrder() : null); + return (obj instanceof Ordered ordered ? ordered.getOrder() : null); } /** diff --git a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java index 2cb589eb74..6c90bfcb8f 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -67,9 +67,8 @@ public abstract class ParameterizedTypeReference { } @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof ParameterizedTypeReference && - this.type.equals(((ParameterizedTypeReference) other).type))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof ParameterizedTypeReference that && this.type.equals(that.type))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java index 0c9cbf060b..50d8043294 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -149,7 +149,7 @@ public class ReactiveAdapterRegistry { return null; } - Object sourceToUse = (source instanceof Optional ? ((Optional) source).orElse(null) : source); + Object sourceToUse = (source instanceof Optional optional ? optional.orElse(null) : source); Class clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType); if (clazz == null) { return null; diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index a109b6633b..d4ae15af06 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -215,7 +215,7 @@ public class ResolvableType implements Serializable { if (rawType instanceof ParameterizedType parameterizedType) { rawType = parameterizedType.getRawType(); } - return (rawType instanceof Class ? (Class) rawType : null); + return (rawType instanceof Class rawClass ? rawClass : null); } /** @@ -376,7 +376,7 @@ public class ResolvableType implements Serializable { if (this == NONE) { return false; } - return ((this.type instanceof Class && ((Class) this.type).isArray()) || + return ((this.type instanceof Class clazz && clazz.isArray()) || this.type instanceof GenericArrayType || resolveType().isArray()); } @@ -1647,13 +1647,12 @@ public class ResolvableType implements Serializable { @Nullable public static WildcardBounds get(ResolvableType type) { ResolvableType resolveToWildcard = type; - while (!(resolveToWildcard.getType() instanceof WildcardType)) { + while (!(resolveToWildcard.getType() instanceof WildcardType wildcardType)) { if (resolveToWildcard == NONE) { return null; } resolveToWildcard = resolveToWildcard.resolveType(); } - WildcardType wildcardType = (WildcardType) resolveToWildcard.type; Kind boundsType = (wildcardType.getLowerBounds().length > 0 ? Kind.LOWER : Kind.UPPER); Type[] bounds = (boundsType == Kind.UPPER ? wildcardType.getUpperBounds() : wildcardType.getLowerBounds()); ResolvableType[] resolvableBounds = new ResolvableType[bounds.length]; diff --git a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java index 46b4c28083..a8affc03b2 100644 --- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java +++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -352,7 +352,7 @@ final class SerializableTypeWrapper { // Cache the result for further calls to getType() this.result = result; } - return (result instanceof Type[] ? ((Type[]) result)[this.index] : (Type) result); + return (result instanceof Type[] results ? results[this.index] : (Type) result); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java index 172275f8b4..75c9c1b5ec 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java @@ -70,7 +70,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator { @Nullable private Integer findOrderFromAnnotation(Object obj) { - AnnotatedElement element = (obj instanceof AnnotatedElement ? (AnnotatedElement) obj : obj.getClass()); + AnnotatedElement element = (obj instanceof AnnotatedElement ae ? ae : obj.getClass()); MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY); Integer order = OrderUtils.getOrderFromAnnotations(element, annotations); if (order == null && obj instanceof DecoratingProxy decoratingProxy) { diff --git a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java index cc5271d5c0..2599ce940a 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Decoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Decoder.java @@ -107,7 +107,7 @@ public interface Decoder { catch (InterruptedException ex) { failure = ex; } - throw (failure instanceof CodecException ? (CodecException) failure : + throw (failure instanceof CodecException codecException ? codecException : new DecodingException("Failed to decode: " + failure.getMessage(), failure)); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index f8f42d251c..ffa0da8694 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -779,9 +779,9 @@ public class TypeDescriptor implements Serializable { } @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof AnnotatedElementAdapter && - Arrays.equals(this.annotations, ((AnnotatedElementAdapter) other).annotations))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof AnnotatedElementAdapter that && + Arrays.equals(this.annotations, that.annotations))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java index 830530d88c..4d12b15e56 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java @@ -76,7 +76,7 @@ final class ObjectToOptionalConverter implements ConditionalGenericConverter { else if (targetType.getResolvableType().hasGenerics()) { Object target = this.conversionService.convert(source, sourceType, new GenericTypeDescriptor(targetType)); if (target == null || (target.getClass().isArray() && Array.getLength(target) == 0) || - (target instanceof Collection && ((Collection) target).isEmpty())) { + (target instanceof Collection collection && collection.isEmpty())) { return Optional.empty(); } return Optional.of(target); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java index 2514ee6afb..25bb03a5b2 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java @@ -337,9 +337,8 @@ public final class Netty5DataBuffer implements CloseableDataBuffer, TouchableDat @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof Netty5DataBuffer dataBuffer && - this.buffer.equals(dataBuffer.buffer))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof Netty5DataBuffer that && this.buffer.equals(that.buffer))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index 9e35a3591d..95cbf83efb 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -363,9 +363,8 @@ public class NettyDataBuffer implements PooledDataBuffer { @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof NettyDataBuffer && - this.byteBuf.equals(((NettyDataBuffer) other).byteBuf))); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof NettyDataBuffer that && this.byteBuf.equals(that.byteBuf))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java index 7543563381..86a818f799 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -122,8 +122,8 @@ public class StandardClassMetadata implements ClassMetadata { @Override public boolean equals(@Nullable Object obj) { - return ((this == obj) || ((obj instanceof StandardClassMetadata) && - getIntrospectedClass().equals(((StandardClassMetadata) obj).getIntrospectedClass()))); + return (this == obj || (obj instanceof StandardClassMetadata that && + getIntrospectedClass().equals(that.getIntrospectedClass()))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java index b2eb1b84fd..2dda60ab8c 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -151,8 +151,8 @@ public class StandardMethodMetadata implements MethodMetadata { @Override public boolean equals(@Nullable Object obj) { - return ((this == obj) || ((obj instanceof StandardMethodMetadata) && - this.introspectedMethod.equals(((StandardMethodMetadata) obj).introspectedMethod))); + return (this == obj || (obj instanceof StandardMethodMetadata that && + this.introspectedMethod.equals(that.introspectedMethod))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java index 9c504ad877..54a6a75ff0 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -164,8 +164,7 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { @Override public boolean equals(@Nullable Object obj) { - return ((this == obj) || ((obj instanceof SimpleAnnotationMetadata) && - this.className.equals(((SimpleAnnotationMetadata) obj).className))); + return (this == obj || (obj instanceof SimpleAnnotationMetadata that && this.className.equals(that.className))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java index 98fcbe759a..50b78176f4 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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,8 +102,7 @@ final class SimpleMethodMetadata implements MethodMetadata { @Override public boolean equals(@Nullable Object obj) { - return ((this == obj) || ((obj instanceof SimpleMethodMetadata) && - this.source.equals(((SimpleMethodMetadata) obj).source))); + return (this == obj || (obj instanceof SimpleMethodMetadata that && this.source.equals(that.source))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index 7f62aa9ee1..86156fef3b 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -361,8 +361,8 @@ public abstract class CollectionUtils { if (isEmpty(set)) { return null; } - if (set instanceof SortedSet) { - return ((SortedSet) set).first(); + if (set instanceof SortedSet sortedSet) { + return sortedSet.first(); } Iterator it = set.iterator(); @@ -402,8 +402,8 @@ public abstract class CollectionUtils { if (isEmpty(set)) { return null; } - if (set instanceof SortedSet) { - return ((SortedSet) set).last(); + if (set instanceof SortedSet sortedSet) { + return sortedSet.last(); } // Full iteration necessary... diff --git a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java index 12b26b904a..b3e8543af3 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -154,7 +154,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable @Override public boolean containsKey(Object key) { - return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key))); + return (key instanceof String string && this.caseInsensitiveKeys.containsKey(convertKey(string))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/NumberUtils.java b/spring-core/src/main/java/org/springframework/util/NumberUtils.java index 61df19ff7d..11febb67f1 100644 --- a/spring-core/src/main/java/org/springframework/util/NumberUtils.java +++ b/spring-core/src/main/java/org/springframework/util/NumberUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -246,8 +246,8 @@ public abstract class NumberUtils { Assert.notNull(targetClass, "Target class must not be null"); DecimalFormat decimalFormat = null; boolean resetBigDecimal = false; - if (numberFormat instanceof DecimalFormat) { - decimalFormat = (DecimalFormat) numberFormat; + if (numberFormat instanceof DecimalFormat dc) { + decimalFormat = dc; if (BigDecimal.class == targetClass && !decimalFormat.isParseBigDecimal()) { decimalFormat.setParseBigDecimal(true); resetBigDecimal = true; diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index f2eb263234..f34e45b0d0 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -510,7 +510,7 @@ public abstract class StringUtils { */ @Nullable public static Object quoteIfString(@Nullable Object obj) { - return (obj instanceof String ? quote((String) obj) : obj); + return (obj instanceof String text ? quote(text) : obj); } /** diff --git a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java index 6f59c2ea9e..b11c642341 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 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,9 +69,8 @@ public class BooleanComparator implements Comparator, Serializable { @Override - public boolean equals(@Nullable Object other) { - return (this == other || (other instanceof BooleanComparator && - this.trueLow == ((BooleanComparator) other).trueLow)); + public boolean equals(@Nullable Object obj) { + return (this == obj || (obj instanceof BooleanComparator that && this.trueLow == that.trueLow)); } @Override