From 18966d048cac38e04a534a293444d5c176ddcf69 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 4 Aug 2023 02:39:31 +0200 Subject: [PATCH] Consistent equals/hashCode style (and related polishing) --- .../aop/aspectj/TypePatternClassFilter.java | 4 +- .../aop/support/ClassFilters.java | 8 +-- .../aop/support/NameMatchMethodPointcut.java | 4 +- .../aop/support/RootClassFilter.java | 4 +- .../interceptor/NopInterceptor.java | 10 +-- .../beans/ExtendedBeanInfo.java | 4 +- .../beans/MutablePropertyValues.java | 4 +- .../config/AutowiredPropertyMarker.java | 6 +- .../support/BeanDefinitionResource.java | 4 +- .../beans/factory/support/NullBean.java | 6 +- .../cache/interceptor/SimpleKey.java | 5 +- .../cache/support/NullValue.java | 6 +- .../context/annotation/BeanMethod.java | 7 +- .../annotation/ConfigurationClass.java | 4 +- .../annotation/ConfigurationClassParser.java | 8 +-- .../core/test/tools/ClassFiles.java | 12 ++-- .../core/test/tools/DynamicFile.java | 17 ++--- .../core/test/tools/DynamicFiles.java | 12 +--- .../core/test/tools/ResourceFiles.java | 11 +-- .../core/test/tools/SourceFiles.java | 16 ++--- .../aot/generate/MethodName.java | 15 ++-- .../core/AttributeAccessorSupport.java | 4 +- .../core/ParameterizedTypeReference.java | 8 +-- .../core/convert/TypeDescriptor.java | 4 +- .../core/env/ProfilesParser.java | 20 ++---- .../core/env/PropertySource.java | 8 +-- .../core/io/AbstractResource.java | 4 +- .../core/io/ByteArrayResource.java | 4 +- .../core/io/ClassPathResource.java | 9 +-- .../core/io/DescriptiveResource.java | 4 +- .../core/io/FileSystemResource.java | 4 +- .../core/io/InputStreamResource.java | 4 +- .../springframework/core/io/PathResource.java | 4 +- .../springframework/core/io/UrlResource.java | 4 +- .../springframework/core/io/VfsResource.java | 5 +- .../core/io/buffer/Netty5DataBuffer.java | 5 +- .../core/io/buffer/NettyDataBuffer.java | 5 +- .../core/type/StandardClassMetadata.java | 5 +- .../core/type/StandardMethodMetadata.java | 5 +- .../SimpleAnnotationMetadata.java | 4 +- ...impleAnnotationMetadataReadingVisitor.java | 18 ++--- .../classreading/SimpleMethodMetadata.java | 5 +- .../util/UnmodifiableMultiValueMap.java | 69 +++++++------------ .../util/comparator/BooleanComparator.java | 4 +- .../messaging/MessageHeaders.java | 4 +- .../simp/SimpMessageMappingInfo.java | 4 +- .../broker/DefaultSubscriptionRegistry.java | 4 +- .../messaging/simp/stomp/StompHeaders.java | 4 +- .../simp/user/MultiServerUserRegistry.java | 8 +-- .../SpringFlushSynchronization.java | 5 +- .../DynamicPropertiesContextCustomizer.java | 21 ++---- .../http/DefaultHttpStatusCode.java | 12 ++-- .../org/springframework/http/HttpHeaders.java | 25 +++---- .../org/springframework/http/HttpMethod.java | 4 +- .../http/server/DefaultPathContainer.java | 8 +-- .../web/multipart/MultipartFileResource.java | 8 +-- 56 files changed, 195 insertions(+), 285 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java index 1510b47b9ac..bc6de396395 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java @@ -117,8 +117,8 @@ public class TypePatternClassFilter implements ClassFilter { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof TypePatternClassFilter that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof TypePatternClassFilter that && ObjectUtils.nullSafeEquals(this.typePattern, that.typePattern))); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java index b0c2c65c6db..97e07ee91e6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java @@ -109,8 +109,8 @@ public abstract class ClassFilters { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof UnionClassFilter that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof UnionClassFilter that && ObjectUtils.nullSafeEquals(this.filters, that.filters))); } @@ -150,8 +150,8 @@ public abstract class ClassFilters { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof IntersectionClassFilter that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof IntersectionClassFilter that && ObjectUtils.nullSafeEquals(this.filters, that.filters))); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index 5c81794a92b..5e930660540 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java @@ -100,8 +100,8 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof NameMatchMethodPointcut that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof NameMatchMethodPointcut that && this.mappedNames.equals(that.mappedNames))); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java index 55430ffd6a2..c4bf82a1860 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java @@ -46,8 +46,8 @@ public class RootClassFilter implements ClassFilter, Serializable { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof RootClassFilter that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof RootClassFilter that && this.clazz.equals(that.clazz))); } diff --git a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java index 3006bef8c3d..df7bb2bd98a 100644 --- a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java +++ b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java @@ -47,14 +47,8 @@ public class NopInterceptor implements MethodInterceptor { @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof NopInterceptor that)) { - return false; - } - return this.count == that.count; + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof NopInterceptor that && this.count == that.count)); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index bd2513bc734..43632a66519 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -338,8 +338,8 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof PropertyDescriptor that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof PropertyDescriptor that && PropertyDescriptorUtils.equals(this, that))); } diff --git a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java index a4490cbb90e..62543e9a8cf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java @@ -366,8 +366,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof MutablePropertyValues that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof MutablePropertyValues that && this.propertyValueList.equals(that.propertyValueList))); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java index 4d4f2c6b694..7457494436d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 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. @@ -52,8 +52,8 @@ public final class AutowiredPropertyMarker implements Serializable { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj); + public boolean equals(@Nullable Object other) { + return (this == other); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java index dcc231ecce7..f59222a9621 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java @@ -81,8 +81,8 @@ class BeanDefinitionResource extends AbstractResource { * This implementation compares the underlying BeanDefinition. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof BeanDefinitionResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof BeanDefinitionResource that && this.beanDefinition.equals(that.beanDefinition))); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java index 6a87a11984b..7905acc0955 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -40,8 +40,8 @@ final class NullBean { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || obj == null); + public boolean equals(@Nullable Object other) { + return (this == other || other == null); } @Override diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java index f5dc0dcd52e..6dd60e6934b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java @@ -61,9 +61,8 @@ public class SimpleKey implements Serializable { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || - (obj instanceof SimpleKey that && Arrays.deepEquals(this.params, that.params))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SimpleKey that && Arrays.deepEquals(this.params, that.params))); } @Override diff --git a/spring-context/src/main/java/org/springframework/cache/support/NullValue.java b/spring-context/src/main/java/org/springframework/cache/support/NullValue.java index 18c26d32d98..cc60aa47f8c 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NullValue.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NullValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -50,8 +50,8 @@ public final class NullValue implements Serializable { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || obj == null); + public boolean equals(@Nullable Object other) { + return (this == other || other == null); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java b/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java index f0aa6b5fbb4..5f01df18b1a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java @@ -39,6 +39,7 @@ final class BeanMethod extends ConfigurationMethod { super(metadata, configurationClass); } + @Override public void validate(ProblemReporter problemReporter) { if (getMetadata().isStatic()) { @@ -55,9 +56,8 @@ final class BeanMethod extends ConfigurationMethod { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || - (obj instanceof BeanMethod that && this.metadata.equals(that.metadata))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof BeanMethod that && this.metadata.equals(that.metadata))); } @Override @@ -70,6 +70,7 @@ final class BeanMethod extends ConfigurationMethod { return "BeanMethod: " + this.metadata; } + private class NonOverridableMethodError extends Problem { NonOverridableMethodError() { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java index 1db03cd2aa4..e462008c7c2 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java @@ -237,8 +237,8 @@ final class ConfigurationClass { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof ConfigurationClass that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ConfigurationClass that && getMetadata().getClassName().equals(that.getMetadata().getClassName()))); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index 12281caec79..59d1f07147b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -211,8 +211,8 @@ class ConfigurationClassParser { } List getPropertySourceDescriptors() { - return (this.propertySourceRegistry != null ? this.propertySourceRegistry.getDescriptors() - : Collections.emptyList()); + return (this.propertySourceRegistry != null ? this.propertySourceRegistry.getDescriptors() : + Collections.emptyList()); } protected void processConfigurationClass(ConfigurationClass configClass, Predicate filter) throws IOException { @@ -1005,8 +1005,8 @@ class ConfigurationClassParser { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SourceClass that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SourceClass that && this.metadata.getClassName().equals(that.metadata.getClassName()))); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java index 02f2fca7196..595c920a3ac 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java @@ -61,6 +61,7 @@ public final class ClassFiles implements Iterable { return none().and(ClassFiles); } + /** * Return a new {@link ClassFiles} instance that merges classes from * another array of {@link ClassFile} instances. @@ -116,15 +117,10 @@ public final class ClassFiles implements Iterable { return this.files.get(name); } + @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.files.equals(((ClassFiles) obj).files); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ClassFiles that && this.files.equals(that.files))); } @Override diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java index 50a8a7aeda6..bbc81923a7c 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java @@ -18,7 +18,6 @@ package org.springframework.core.test.tools; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Objects; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -81,22 +80,16 @@ public abstract sealed class DynamicFile permits SourceFile, ResourceFile { return this.path; } + @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - DynamicFile other = (DynamicFile) obj; - return Objects.equals(this.path, other.path) - && Objects.equals(this.content, other.content); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof DynamicFile that && + this.path.equals(that.path) && this.content.equals(that.content))); } @Override public int hashCode() { - return Objects.hash(this.path, this.content); + return this.path.hashCode(); } @Override diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java index 0e204934604..23b2d47ccd3 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java @@ -39,7 +39,6 @@ final class DynamicFiles implements Iterable { private static final DynamicFiles NONE = new DynamicFiles<>(Collections.emptyMap()); - private final Map files; @@ -101,15 +100,10 @@ final class DynamicFiles implements Iterable { return files.iterator().next(); } + @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.files.equals(((DynamicFiles) obj).files); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof DynamicFiles that && this.files.equals(that.files))); } @Override diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java index e23208981e7..1a53e922774 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java @@ -130,15 +130,10 @@ public final class ResourceFiles implements Iterable { return this.files.getSingle(); } + @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.files.equals(((ResourceFiles) obj).files); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ResourceFiles that && this.files.equals(that.files))); } @Override diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java index 86c348734d2..ad8bab385af 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java @@ -17,7 +17,6 @@ package org.springframework.core.test.tools; import java.util.Iterator; -import java.util.Objects; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -155,19 +154,14 @@ public final class SourceFiles implements Iterable { * one file */ public SourceFile getSingleFromPackage(String packageName) { - return this.files.getSingle(candidate -> Objects.equals(packageName, - ClassUtils.getPackageName(candidate.getClassName()))); + return this.files.getSingle(candidate -> + ClassUtils.getPackageName(candidate.getClassName()).equals(packageName)); } + @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.files.equals(((SourceFiles) obj).files); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SourceFiles that && this.files.equals(that.files))); } @Override diff --git a/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java b/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java index 365d412f024..f9ea24c9fe8 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java @@ -91,19 +91,13 @@ final class MethodName { @Override - public int hashCode() { - return this.value.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof MethodName that && this.value.equals(that.value))); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if ((obj == null) || (getClass() != obj.getClass())) { - return false; - } - return this.value.equals(((MethodName) obj).value); + public int hashCode() { + return this.value.hashCode(); } @Override @@ -111,6 +105,7 @@ final class MethodName { return (!StringUtils.hasLength(this.value)) ? "$$aot" : this.value ; } + private static String join(String[] parts) { return StringUtils.uncapitalize(Arrays.stream(parts).map(MethodName::clean) .map(StringUtils::capitalize).collect(Collectors.joining())); 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 2f1c15c75ec..87e1975a82b 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java @@ -105,8 +105,8 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof AttributeAccessorSupport that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof AttributeAccessorSupport that && this.attributes.equals(that.attributes))); } 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 6c90bfcb8fe..e1123700635 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package org.springframework.core; import java.lang.reflect.ParameterizedType; @@ -67,8 +66,8 @@ public abstract class ParameterizedTypeReference { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof ParameterizedTypeReference that && this.type.equals(that.type))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ParameterizedTypeReference that && this.type.equals(that.type))); } @Override @@ -91,8 +90,7 @@ public abstract class ParameterizedTypeReference { * @since 4.3.12 */ public static ParameterizedTypeReference forType(Type type) { - return new ParameterizedTypeReference<>(type) { - }; + return new ParameterizedTypeReference<>(type) {}; } private static Class findParameterizedTypeReferenceSubclass(Class child) { 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 1c7c6d44efa..f02d0ea0a2b 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 @@ -779,8 +779,8 @@ public class TypeDescriptor implements Serializable { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof AnnotatedElementAdapter that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof AnnotatedElementAdapter that && Arrays.equals(this.annotations, that.annotations))); } diff --git a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java index 8a17a011239..9f5868d248c 100644 --- a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java +++ b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java @@ -168,30 +168,20 @@ final class ProfilesParser { } @Override - public int hashCode() { - return this.expressions.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ParsedProfiles that && + this.expressions.equals(that.expressions))); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ParsedProfiles that = (ParsedProfiles) obj; - return this.expressions.equals(that.expressions); + public int hashCode() { + return this.expressions.hashCode(); } @Override public String toString() { return StringUtils.collectionToDelimitedString(this.expressions, " or "); } - } } diff --git a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java b/spring-core/src/main/java/org/springframework/core/env/PropertySource.java index a88223c941c..f50968d2bba 100644 --- a/spring-core/src/main/java/org/springframework/core/env/PropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/PropertySource.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. @@ -134,9 +134,9 @@ public abstract class PropertySource { *

No properties other than {@code name} are evaluated. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof PropertySource other && - ObjectUtils.nullSafeEquals(getName(), other.getName()))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof PropertySource that && + ObjectUtils.nullSafeEquals(getName(), that.getName()))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index dff121b8feb..4bb5122cf7a 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -236,8 +236,8 @@ public abstract class AbstractResource implements Resource { * @see #getDescription() */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof Resource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof Resource that && getDescription().equals(that.getDescription()))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java index 76103d206fb..b0f84a94603 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java @@ -129,8 +129,8 @@ public class ByteArrayResource extends AbstractResource { * @see java.util.Arrays#equals(byte[], byte[]) */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof ByteArrayResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ByteArrayResource that && Arrays.equals(this.byteArray, that.byteArray))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index eca6b70c6ae..a12258a24e6 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -268,13 +268,10 @@ public class ClassPathResource extends AbstractFileResolvingResource { * @see #getClassLoader() */ @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - return (obj instanceof ClassPathResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof ClassPathResource that && this.absolutePath.equals(that.absolutePath) && - ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader())); + ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader()))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java index 0c2291b655b..49d9d854a96 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java @@ -72,8 +72,8 @@ public class DescriptiveResource extends AbstractResource { * This implementation compares the underlying description String. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof DescriptiveResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof DescriptiveResource that && this.description.equals(that.description))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index 4e5096f7198..76e329b5fc8 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -395,8 +395,8 @@ public class FileSystemResource extends AbstractResource implements WritableReso * @see #getPath() */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof FileSystemResource that && this.path.equals(that.path))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof FileSystemResource that && this.path.equals(that.path))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java index 53bc149b040..ab8e393b48d 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java @@ -115,8 +115,8 @@ public class InputStreamResource extends AbstractResource { * This implementation compares the underlying InputStream. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof InputStreamResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof InputStreamResource that && this.inputStream.equals(that.inputStream))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index b4edc9bbf47..1218ef9b674 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -298,8 +298,8 @@ public class PathResource extends AbstractResource implements WritableResource { * This implementation compares the underlying {@link Path} references. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof PathResource that && this.path.equals(that.path))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof PathResource that && this.path.equals(that.path))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index d770aa9356c..2a6bd335e1c 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -343,8 +343,8 @@ public class UrlResource extends AbstractFileResolvingResource { * This implementation compares the underlying URL references. */ @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof UrlResource that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof UrlResource that && getCleanedUrl().equals(that.getCleanedUrl()))); } diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index aa8ed7c1508..00203ed3b92 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -130,9 +130,8 @@ public class VfsResource extends AbstractResource { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof VfsResource that && - this.resource.equals(that.resource))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof VfsResource that && this.resource.equals(that.resource))); } @Override 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 25bb03a5b24..70a544cd4f0 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,8 +337,8 @@ public final class Netty5DataBuffer implements CloseableDataBuffer, TouchableDat @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof Netty5DataBuffer that && this.buffer.equals(that.buffer))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof Netty5DataBuffer that && this.buffer.equals(that.buffer))); } @Override @@ -362,7 +362,6 @@ public final class Netty5DataBuffer implements CloseableDataBuffer, TouchableDat @Nullable private T next; - public BufferComponentIterator(ComponentIterator delegate, boolean readable) { Assert.notNull(delegate, "Delegate must not be null"); this.delegate = delegate; 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 95cbf83efb5..42a73c3050b 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,8 +363,8 @@ public class NettyDataBuffer implements PooledDataBuffer { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof NettyDataBuffer that && this.byteBuf.equals(that.byteBuf))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof NettyDataBuffer that && this.byteBuf.equals(that.byteBuf))); } @Override @@ -386,7 +386,6 @@ public class NettyDataBuffer implements PooledDataBuffer { private int cursor = 0; - public ByteBufferIterator(ByteBuffer[] byteBuffers, boolean readOnly) { this.byteBuffers = byteBuffers; this.readOnly = readOnly; 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 86a818f799f..702b5c1b774 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 @@ -120,9 +120,10 @@ public class StandardClassMetadata implements ClassMetadata { return StringUtils.toStringArray(memberClassNames); } + @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof StandardClassMetadata that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof StandardClassMetadata that && getIntrospectedClass().equals(that.getIntrospectedClass()))); } 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 2dda60ab8c7..40943a223f3 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 @@ -149,9 +149,10 @@ public class StandardMethodMetadata implements MethodMetadata { annotationName, classValuesAsString, false); } + @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof StandardMethodMetadata that && + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof StandardMethodMetadata that && this.introspectedMethod.equals(that.introspectedMethod))); } 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 54a6a75ff09..375ac630fff 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 @@ -163,8 +163,8 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SimpleAnnotationMetadata that && this.className.equals(that.className))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SimpleAnnotationMetadata that && this.className.equals(that.className))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java index 7044ea7e419..a4e1128e624 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.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,6 +164,7 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { return (access & Opcodes.ACC_INTERFACE) != 0; } + /** * {@link MergedAnnotation} source. */ @@ -176,26 +177,19 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { } @Override - public int hashCode() { - return this.className.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof Source that && this.className.equals(that.className))); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.className.equals(((Source) obj).className); + public int hashCode() { + return this.className.hashCode(); } @Override public String toString() { return this.className; } - } } 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 50b78176f49..4b4a0ac5e5f 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 @@ -100,9 +100,10 @@ final class SimpleMethodMetadata implements MethodMetadata { return this.annotations; } + @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SimpleMethodMetadata that && this.source.equals(that.source))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SimpleMethodMetadata that && this.source.equals(that.source))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java b/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java index cad832b6fde..32fdeb1adae 100644 --- a/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java @@ -66,6 +66,7 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial this.delegate = (MultiValueMap) delegate; } + // delegation @Override @@ -92,7 +93,7 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial @Nullable public List get(Object key) { List result = this.delegate.get(key); - return result != null ? Collections.unmodifiableList(result) : null; + return (result != null ? Collections.unmodifiableList(result) : null); } @Override @@ -119,14 +120,15 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial return this.delegate.toSingleValueMap(); } + @Override - public int hashCode() { - return this.delegate.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || this.delegate.equals(other)); } @Override - public boolean equals(@Nullable Object obj) { - return this == obj || this.delegate.equals(obj); + public int hashCode() { + return this.delegate.hashCode(); } @Override @@ -134,6 +136,7 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial return this.delegate.toString(); } + // lazy init @Override @@ -239,20 +242,17 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - public List computeIfPresent(K key, - BiFunction, ? extends List> remappingFunction) { + public List computeIfPresent(K key, BiFunction, ? extends List> remappingFunction) { throw new UnsupportedOperationException(); } @Override - public List compute(K key, - BiFunction, ? extends List> remappingFunction) { + public List compute(K key, BiFunction, ? extends List> remappingFunction) { throw new UnsupportedOperationException(); } @Override - public List merge(K key, List value, - BiFunction, ? super List, ? extends List> remappingFunction) { + public List merge(K key, List value, BiFunction, ? super List, ? extends List> remappingFunction) { throw new UnsupportedOperationException(); } @@ -269,7 +269,6 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial @SuppressWarnings("serial") private final Set>> delegate; - @SuppressWarnings("unchecked") public UnmodifiableEntrySet(Set>> delegate) { this.delegate = (Set>>) delegate; @@ -357,20 +356,13 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - public int hashCode() { - return this.delegate.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || other instanceof Set that && size() == that.size() && containsAll(that)); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - else if (obj instanceof Set other) { - return other.size() == this.delegate.size() && - containsAll(other); - } - return false; + public int hashCode() { + return this.delegate.hashCode(); } @Override @@ -420,10 +412,10 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial private final Spliterator>> delegate; - @SuppressWarnings("unchecked") public UnmodifiableEntrySpliterator( Spliterator>> delegate) { + this.delegate = (Spliterator>>) delegate; } @@ -480,7 +472,6 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial private final Entry> delegate; - @SuppressWarnings("unchecked") public UnmodifiableEntry(Entry> delegate) { Assert.notNull(delegate, "Delegate must not be null"); @@ -503,20 +494,14 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - public int hashCode() { - return this.delegate.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof Map.Entry that && + getKey().equals(that.getKey()) && getValue().equals(that.getValue()))); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - else if (obj instanceof Map.Entry other) { - return getKey().equals(other.getKey()) && - getValue().equals(other.getValue()); - } - return false; + public int hashCode() { + return this.delegate.hashCode(); } @Override @@ -534,7 +519,6 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial @SuppressWarnings("serial") private final Collection> delegate; - public UnmodifiableValueCollection(Collection> delegate) { this.delegate = delegate; } @@ -620,13 +604,13 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - public int hashCode() { - return this.delegate.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || this.delegate.equals(other)); } @Override - public boolean equals(@Nullable Object obj) { - return this == obj || this.delegate.equals(obj); + public int hashCode() { + return this.delegate.hashCode(); } @Override @@ -676,7 +660,6 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial private final Spliterator> delegate; - public UnmodifiableValueSpliterator(Spliterator> delegate) { this.delegate = delegate; } @@ -728,6 +711,6 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial return this.delegate.getComparator(); } } - } + } 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 b11c6423411..33a357912d0 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 @@ -69,8 +69,8 @@ public class BooleanComparator implements Comparator, Serializable { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof BooleanComparator that && this.trueLow == that.trueLow)); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof BooleanComparator that && this.trueLow == that.trueLow)); } @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java index 0c22dae2bc8..5d0f0d2c85f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java @@ -333,8 +333,8 @@ public class MessageHeaders implements Map, Serializable { // equals, hashCode, toString @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof MessageHeaders that && this.headers.equals(that.headers))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof MessageHeaders that && this.headers.equals(that.headers))); } @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java index b2c47372000..31c194d1f68 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java @@ -77,8 +77,8 @@ public class SimpMessageMappingInfo implements MessageCondition, Serializable @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof StompHeaders that && this.headers.equals(that.headers))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof StompHeaders that && this.headers.equals(that.headers))); } @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java index 2d2f254aba9..6973f11b85a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java @@ -369,8 +369,8 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SimpUser that && this.name.equals(that.getName()))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SimpUser that && this.name.equals(that.getName()))); } @Override @@ -455,8 +455,8 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SimpSession that && this.id.equals(that.getId()))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SimpSession that && this.id.equals(that.getId()))); } @Override diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java index 111ddfd95d4..72f93fd7b64 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java @@ -43,10 +43,9 @@ public class SpringFlushSynchronization implements TransactionSynchronization { SessionFactoryUtils.flush(this.session, false); } - @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof SpringFlushSynchronization that && this.session == that.session)); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof SpringFlushSynchronization that && this.session == that.session)); } @Override diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java index cfae087326d..266782314aa 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java @@ -47,7 +47,6 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer { private static final String PROPERTY_SOURCE_NAME = "Dynamic Test Properties"; - private final Set methods; @@ -66,9 +65,7 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer { } @Override - public void customizeContext(ConfigurableApplicationContext context, - MergedContextConfiguration mergedConfig) { - + public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { MutablePropertySources sources = context.getEnvironment().getPropertySources(); sources.addFirst(new DynamicValuesPropertySource(PROPERTY_SOURCE_NAME, buildDynamicPropertiesMap())); } @@ -91,20 +88,16 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer { return this.methods; } + @Override - public int hashCode() { - return this.methods.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof DynamicPropertiesContextCustomizer that && + this.methods.equals(that.methods))); } @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - return this.methods.equals(((DynamicPropertiesContextCustomizer) obj).methods); + public int hashCode() { + return this.methods.hashCode(); } } diff --git a/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java b/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java index 0c1e2e3a11e..cc2f754e8e5 100644 --- a/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java +++ b/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java @@ -27,8 +27,7 @@ import org.springframework.lang.Nullable; * @author Arjen Poutsma * @since 6.0 */ -final class DefaultHttpStatusCode - implements HttpStatusCode, Comparable, Serializable { +final class DefaultHttpStatusCode implements HttpStatusCode, Comparable, Serializable { private static final long serialVersionUID = 7017664779360718111L; @@ -79,19 +78,20 @@ final class DefaultHttpStatusCode return this.value / 100; } + @Override public int compareTo(@NonNull HttpStatusCode o) { return Integer.compare(this.value, o.value()); } @Override - public int hashCode() { - return this.value; + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof HttpStatusCode that && this.value == that.value())); } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj) || (obj instanceof HttpStatusCode that && this.value == that.value()); + public int hashCode() { + return this.value; } @Override diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 7178894b4b9..d1656fbf843 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -1834,21 +1834,8 @@ public class HttpHeaders implements MultiValueMap, Serializable @Override - public boolean equals(@Nullable Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof HttpHeaders other)) { - return false; - } - return unwrap(this).equals(unwrap(other)); - } - - private static MultiValueMap unwrap(HttpHeaders headers) { - while (headers.headers instanceof HttpHeaders httpHeaders) { - headers = httpHeaders; - } - return headers.headers; + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof HttpHeaders that && unwrap(this).equals(unwrap(that)))); } @Override @@ -1955,6 +1942,14 @@ public class HttpHeaders implements MultiValueMap, Serializable return new String(encodedBytes, charset); } + + private static MultiValueMap unwrap(HttpHeaders headers) { + while (headers.headers instanceof HttpHeaders httpHeaders) { + headers = httpHeaders; + } + return headers.headers; + } + // Package-private: used in ResponseCookie static String formatDate(long date) { Instant instant = Instant.ofEpochMilli(date); diff --git a/spring-web/src/main/java/org/springframework/http/HttpMethod.java b/spring-web/src/main/java/org/springframework/http/HttpMethod.java index c223a3d1bdc..e926f62cea8 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -170,8 +170,8 @@ public final class HttpMethod implements Comparable, Serializable { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj) || (obj instanceof HttpMethod that && this.name.equals(that.name)); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof HttpMethod that && this.name.equals(that.name))); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java b/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java index 88e98a4d085..05497984b93 100644 --- a/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java +++ b/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java @@ -74,8 +74,8 @@ final class DefaultPathContainer implements PathContainer { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj) || (obj instanceof PathContainer that && value().equals(that.value())); + public boolean equals(@Nullable Object other) { + return (this == other) || (other instanceof PathContainer that && value().equals(that.value())); } @Override @@ -281,8 +281,8 @@ final class DefaultPathContainer implements PathContainer { } @Override - public boolean equals(@Nullable Object obj) { - return (this == obj) || (obj instanceof PathSegment that && value().equals(that.value())); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof PathSegment that && this.value.equals(that.value()))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java index 4095c494e7f..141ca407f09 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.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. @@ -88,9 +88,9 @@ class MultipartFileResource extends AbstractResource { @Override - public boolean equals(@Nullable Object obj) { - return (this == obj || (obj instanceof MultipartFileResource other && - this.multipartFile.equals(other.multipartFile))); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof MultipartFileResource that && + this.multipartFile.equals(that.multipartFile))); } @Override