diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java index 4a3835bcdb..a412214ccd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java @@ -714,13 +714,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AdviceExcludingMethodMatcher otherMm)) { - return false; - } - return this.adviceMethod.equals(otherMm.adviceMethod); + return (this == other || (other instanceof AdviceExcludingMethodMatcher that && + this.adviceMethod.equals(that.adviceMethod))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index ee26513d6b..c6ee43b2ec 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -243,8 +243,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut /** * If a pointcut expression has been specified in XML, the user cannot - * write {@code and} as "&&" (though && will work). - * We also allow {@code and} between two pointcut sub-expressions. + * write "and" as "&&" (though {@code &&} will work). + *

We also allow "and" between two pointcut sub-expressions. *

This method converts back to {@code &&} for the AspectJ pointcut parser. */ private String replaceBooleanOperators(String pcExpr) { @@ -516,21 +516,16 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AspectJExpressionPointcut otherPc)) { - return false; - } - return ObjectUtils.nullSafeEquals(this.getExpression(), otherPc.getExpression()) && - ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, otherPc.pointcutDeclarationScope) && - ObjectUtils.nullSafeEquals(this.pointcutParameterNames, otherPc.pointcutParameterNames) && - ObjectUtils.nullSafeEquals(this.pointcutParameterTypes, otherPc.pointcutParameterTypes); + return (this == other || (other instanceof AspectJExpressionPointcut that && + ObjectUtils.nullSafeEquals(getExpression(), that.getExpression()) && + ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, that.pointcutDeclarationScope) && + ObjectUtils.nullSafeEquals(this.pointcutParameterNames, that.pointcutParameterNames) && + ObjectUtils.nullSafeEquals(this.pointcutParameterTypes, that.pointcutParameterTypes))); } @Override public int hashCode() { - int hashCode = ObjectUtils.nullSafeHashCode(this.getExpression()); + int hashCode = ObjectUtils.nullSafeHashCode(getExpression()); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutDeclarationScope); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterNames); hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterTypes); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java index fb1974faee..2bfafe1d36 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java @@ -89,13 +89,8 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AspectJPointcutAdvisor otherAdvisor)) { - return false; - } - return this.advice.equals(otherAdvisor.advice); + return (this == other || (other instanceof AspectJPointcutAdvisor that && + this.advice.equals(that.advice))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java index cb7d8e7a0f..4b331ffec8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java @@ -597,15 +597,10 @@ class CglibAopProxy implements AopProxy, Serializable { } if (other instanceof Factory factory) { Callback callback = factory.getCallback(INVOKE_EQUALS); - if (!(callback instanceof EqualsInterceptor equalsInterceptor)) { - return false; - } - AdvisedSupport otherAdvised = equalsInterceptor.advised; - return AopProxyUtils.equalsInProxy(this.advised, otherAdvised); - } - else { - return false; + return (callback instanceof EqualsInterceptor that && + AopProxyUtils.equalsInProxy(this.advised, that.advised)); } + return false; } } @@ -920,20 +915,14 @@ class CglibAopProxy implements AopProxy, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ProxyCallbackFilter otherCallbackFilter)) { - return false; - } - AdvisedSupport otherAdvised = otherCallbackFilter.advised; - return (this.advised.getAdvisorKey().equals(otherAdvised.getAdvisorKey()) && - AopProxyUtils.equalsProxiedInterfaces(this.advised, otherAdvised) && - ObjectUtils.nullSafeEquals(this.advised.getTargetClass(), otherAdvised.getTargetClass()) && - this.advised.getTargetSource().isStatic() == otherAdvised.getTargetSource().isStatic() && - this.advised.isFrozen() == otherAdvised.isFrozen() && - this.advised.isExposeProxy() == otherAdvised.isExposeProxy() && - this.advised.isOpaque() == otherAdvised.isOpaque()); + return (this == other || (other instanceof ProxyCallbackFilter that && + this.advised.getAdvisorKey().equals(that.advised.getAdvisorKey()) && + AopProxyUtils.equalsProxiedInterfaces(this.advised, that.advised) && + ObjectUtils.nullSafeEquals(this.advised.getTargetClass(), that.advised.getTargetClass()) && + this.advised.getTargetSource().isStatic() == that.advised.getTargetSource().isStatic() && + this.advised.isFrozen() == that.advised.isFrozen() && + this.advised.isExposeProxy() == that.advised.isExposeProxy() && + this.advised.isOpaque() == that.advised.isOpaque())); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java index b9f45e2a57..1486cff2a9 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java @@ -133,13 +133,9 @@ public final class EmptyTargetSource implements TargetSource, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof EmptyTargetSource otherTs)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.targetClass, otherTs.targetClass) && this.isStatic == otherTs.isStatic); + return (this == other || (other instanceof EmptyTargetSource that && + ObjectUtils.nullSafeEquals(this.targetClass, that.targetClass) && + this.isStatic == that.isStatic)); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java index 57662a952b..28d09d49ff 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.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. @@ -82,15 +82,10 @@ public class BeanMetadataAttribute implements BeanMetadataElement { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof BeanMetadataAttribute otherMa)) { - return false; - } - return (this.name.equals(otherMa.name) && - ObjectUtils.nullSafeEquals(this.value, otherMa.value) && - ObjectUtils.nullSafeEquals(this.source, otherMa.source)); + return (this == other ||(other instanceof BeanMetadataAttribute that && + this.name.equals(that.name) && + ObjectUtils.nullSafeEquals(this.value, that.value) && + ObjectUtils.nullSafeEquals(this.source, that.source))); } @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 c1964a8765..bd2513bc73 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -491,16 +491,11 @@ class ExtendedBeanInfo implements BeanInfo { */ @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof IndexedPropertyDescriptor otherPd)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getIndexedReadMethod(), otherPd.getIndexedReadMethod()) && - ObjectUtils.nullSafeEquals(getIndexedWriteMethod(), otherPd.getIndexedWriteMethod()) && - ObjectUtils.nullSafeEquals(getIndexedPropertyType(), otherPd.getIndexedPropertyType()) && - PropertyDescriptorUtils.equals(this, otherPd)); + return (this == other || (other instanceof IndexedPropertyDescriptor that && + ObjectUtils.nullSafeEquals(getIndexedReadMethod(), that.getIndexedReadMethod()) && + ObjectUtils.nullSafeEquals(getIndexedWriteMethod(), that.getIndexedWriteMethod()) && + ObjectUtils.nullSafeEquals(getIndexedPropertyType(), that.getIndexedPropertyType()) && + PropertyDescriptorUtils.equals(this, that))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java index fb5d4d15ae..017b7bb12c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.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. @@ -165,13 +165,9 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof GenericTypeAwarePropertyDescriptor otherPd)) { - return false; - } - return (getBeanClass().equals(otherPd.getBeanClass()) && PropertyDescriptorUtils.equals(this, otherPd)); + return (this == other || (other instanceof GenericTypeAwarePropertyDescriptor that && + getBeanClass().equals(that.getBeanClass()) && + PropertyDescriptorUtils.equals(this, that))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java index 38b21b30af..b9f374e93f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java @@ -189,15 +189,10 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof PropertyValue otherPv)) { - return false; - } - return (this.name.equals(otherPv.name) && - ObjectUtils.nullSafeEquals(this.value, otherPv.value) && - ObjectUtils.nullSafeEquals(getSource(), otherPv.getSource())); + return (this == other || (other instanceof PropertyValue that && + this.name.equals(that.name) && + ObjectUtils.nullSafeEquals(this.value, that.value) && + ObjectUtils.nullSafeEquals(getSource(), that.getSource()))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index 590c2152f5..d1a5946aa0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -340,13 +340,8 @@ public class InjectionMetadata { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof InjectedElement otherElement)) { - return false; - } - return this.member.equals(otherElement.member); + return (this == other || (other instanceof InjectedElement that && + this.member.equals(that.member))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java index 0b25ad6144..36a56cae9d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionHolder.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. @@ -165,15 +165,10 @@ public class BeanDefinitionHolder implements BeanMetadataElement { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof BeanDefinitionHolder otherHolder)) { - return false; - } - return this.beanDefinition.equals(otherHolder.beanDefinition) && - this.beanName.equals(otherHolder.beanName) && - ObjectUtils.nullSafeEquals(this.aliases, otherHolder.aliases); + return (this == other || (other instanceof BeanDefinitionHolder that && + this.beanDefinition.equals(that.beanDefinition) && + this.beanName.equals(that.beanName) && + ObjectUtils.nullSafeEquals(this.aliases, that.aliases))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java index e50e934658..7fa5b36b07 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionContext.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. @@ -70,13 +70,8 @@ public class BeanExpressionContext { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof BeanExpressionContext otherContext)) { - return false; - } - return (this.beanFactory == otherContext.beanFactory && this.scope == otherContext.scope); + return (this == other || (other instanceof BeanExpressionContext that && + this.beanFactory == that.beanFactory && this.scope == that.scope)); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java index 90a59c2ac7..f04a8d103e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.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. @@ -68,13 +68,8 @@ public class RuntimeBeanNameReference implements BeanReference { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof RuntimeBeanNameReference that)) { - return false; - } - return this.beanName.equals(that.beanName); + return (this == other || (other instanceof RuntimeBeanNameReference that && + this.beanName.equals(that.beanName))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java index fbb748ad3c..361b786dd3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.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. @@ -132,14 +132,9 @@ public class RuntimeBeanReference implements BeanReference { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof RuntimeBeanReference that)) { - return false; - } - return (this.beanName.equals(that.beanName) && this.beanType == that.beanType && - this.toParent == that.toParent); + return (this == other || (other instanceof RuntimeBeanReference that && + this.beanName.equals(that.beanName) && this.beanType == that.beanType && + this.toParent == that.toParent)); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java index 382068dd3e..79b91cfe10 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/TypedStringValue.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. @@ -216,14 +216,9 @@ public class TypedStringValue implements BeanMetadataElement { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof TypedStringValue otherValue)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.value, otherValue.value) && - ObjectUtils.nullSafeEquals(this.targetType, otherValue.targetType)); + return (this == other || (other instanceof TypedStringValue that && + ObjectUtils.nullSafeEquals(this.value, that.value) && + ObjectUtils.nullSafeEquals(this.targetType, that.targetType))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java index b3cbede748..a81613d3bd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java @@ -1211,13 +1211,8 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AbstractBeanDefinition that)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getBeanClassName(), that.getBeanClassName()) && + return (this == other || (other instanceof AbstractBeanDefinition that && + ObjectUtils.nullSafeEquals(getBeanClassName(), that.getBeanClassName()) && ObjectUtils.nullSafeEquals(this.scope, that.scope) && this.abstractFlag == that.abstractFlag && this.lazyInit == that.lazyInit && @@ -1240,7 +1235,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess this.enforceDestroyMethod == that.enforceDestroyMethod && this.synthetic == that.synthetic && this.role == that.role && - super.equals(other)); + super.equals(other))); } private boolean equalsConstructorArgumentValues(AbstractBeanDefinition other) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java index bab5f2118f..5f15616d95 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.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. @@ -157,13 +157,8 @@ public class ChildBeanDefinition extends AbstractBeanDefinition { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ChildBeanDefinition that)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.parentName, that.parentName) && super.equals(other)); + return (this == other || (other instanceof ChildBeanDefinition that && + ObjectUtils.nullSafeEquals(this.parentName, that.parentName) && super.equals(other))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java index 01bb1726ed..8381b7b20f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java @@ -87,13 +87,8 @@ public class GenericBeanDefinition extends AbstractBeanDefinition { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof GenericBeanDefinition that)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.parentName, that.parentName) && super.equals(other)); + return (this == other || (other instanceof GenericBeanDefinition that && + ObjectUtils.nullSafeEquals(this.parentName, that.parentName) && super.equals(other))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java index faa7478a81..f51af88735 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.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,16 +102,14 @@ public class LookupOverride extends MethodOverride { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof LookupOverride that) || !super.equals(other)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.method, that.method) && + return (other instanceof LookupOverride that && super.equals(other) && + ObjectUtils.nullSafeEquals(this.method, that.method) && ObjectUtils.nullSafeEquals(this.beanName, that.beanName)); } @Override public int hashCode() { - return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName)); + return super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.beanName); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java index 0107e104c2..e0880d60cb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.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. @@ -106,14 +106,9 @@ public abstract class MethodOverride implements BeanMetadataElement { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MethodOverride that)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.methodName, that.methodName) && - ObjectUtils.nullSafeEquals(this.source, that.source)); + return (this == other || (other instanceof MethodOverride that && + ObjectUtils.nullSafeEquals(this.methodName, that.methodName) && + ObjectUtils.nullSafeEquals(this.source, that.source))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java index 07dc3a6b0d..d9d9e6c121 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverrides.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. @@ -104,13 +104,8 @@ public class MethodOverrides { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MethodOverrides that)) { - return false; - } - return this.overrides.equals(that.overrides); + return (this == other || (other instanceof MethodOverrides that && + this.overrides.equals(that.overrides))); } @Override diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index a702b7d7af..497c60b080 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.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. @@ -97,10 +97,8 @@ public class ReplaceOverride extends MethodOverride { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof ReplaceOverride that) || !super.equals(other)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.methodReplacerBeanName, that.methodReplacerBeanName) && + return (other instanceof ReplaceOverride that && super.equals(other) && + ObjectUtils.nullSafeEquals(this.methodReplacerBeanName, that.methodReplacerBeanName) && ObjectUtils.nullSafeEquals(this.typeIdentifiers, that.typeIdentifiers)); } diff --git a/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java b/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java index 096b0d6a2c..495072fa36 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.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. @@ -156,15 +156,10 @@ public class MutableSortDefinition implements SortDefinition, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SortDefinition otherSd)) { - return false; - } - return (getProperty().equals(otherSd.getProperty()) && - isAscending() == otherSd.isAscending() && - isIgnoreCase() == otherSd.isIgnoreCase()); + return (this == other || (other instanceof SortDefinition that && + getProperty().equals(that.getProperty()) && + isAscending() == that.isAscending() && + isIgnoreCase() == that.isIgnoreCase())); } @Override diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java index 1257cfe050..3ff88b1836 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java @@ -65,10 +65,8 @@ public class SerializablePerson implements Person, Serializable { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof SerializablePerson p)) { - return false; - } - return p.age == age && ObjectUtils.nullSafeEquals(name, p.name); + return (this == other || (other instanceof SerializablePerson that && + ObjectUtils.nullSafeEquals(this.name, that.name) && this.age == that.age)); } @Override diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index bca1ed7653..580e117c31 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -466,18 +466,13 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof TestBean tb2)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); + return (this == other || (other instanceof TestBean that && + ObjectUtils.nullSafeEquals(this.name, that.name) && this.age == that.age)); } @Override public int hashCode() { - return this.age; + return TestBean.class.hashCode(); } @Override diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java index b81512728b..34693866ee 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java @@ -51,13 +51,8 @@ public abstract class JCacheOperationSourcePointcut extends StaticMethodMatcherP @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof JCacheOperationSourcePointcut otherPc)) { - return false; - } - return ObjectUtils.nullSafeEquals(getCacheOperationSource(), otherPc.getCacheOperationSource()); + return (this == other || (other instanceof JCacheOperationSourcePointcut that && + ObjectUtils.nullSafeEquals(getCacheOperationSource(), that.getCacheOperationSource()))); } @Override diff --git a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java index 047dcd9865..81657e9045 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java +++ b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.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. @@ -223,20 +223,15 @@ public class SimpleMailMessage implements MailMessage, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SimpleMailMessage otherMessage)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.from, otherMessage.from) && - ObjectUtils.nullSafeEquals(this.replyTo, otherMessage.replyTo) && - ObjectUtils.nullSafeEquals(this.to, otherMessage.to) && - ObjectUtils.nullSafeEquals(this.cc, otherMessage.cc) && - ObjectUtils.nullSafeEquals(this.bcc, otherMessage.bcc) && - ObjectUtils.nullSafeEquals(this.sentDate, otherMessage.sentDate) && - ObjectUtils.nullSafeEquals(this.subject, otherMessage.subject) && - ObjectUtils.nullSafeEquals(this.text, otherMessage.text)); + return (this == other || (other instanceof SimpleMailMessage that && + ObjectUtils.nullSafeEquals(this.from, that.from) && + ObjectUtils.nullSafeEquals(this.replyTo, that.replyTo) && + ObjectUtils.nullSafeEquals(this.to, that.to) && + ObjectUtils.nullSafeEquals(this.cc, that.cc) && + ObjectUtils.nullSafeEquals(this.bcc, that.bcc) && + ObjectUtils.nullSafeEquals(this.sentDate, that.sentDate) && + ObjectUtils.nullSafeEquals(this.subject, that.subject) && + ObjectUtils.nullSafeEquals(this.text, that.text))); } @Override diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index 20bcb55dc6..11c651fc6b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -853,14 +853,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof CacheOperationCacheKey otherKey)) { - return false; - } - return (this.cacheOperation.equals(otherKey.cacheOperation) && - this.methodCacheKey.equals(otherKey.methodCacheKey)); + return (this == other || (other instanceof CacheOperationCacheKey that && + this.cacheOperation.equals(that.cacheOperation) && + this.methodCacheKey.equals(that.methodCacheKey))); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java index b2d29bca55..207722a4c5 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.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. @@ -65,7 +65,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex * through {@link #register} calls and then manually {@linkplain #refresh refreshed}. */ public AnnotationConfigApplicationContext() { - StartupStep createAnnotatedBeanDefReader = this.getApplicationStartup().start("spring.context.annotated-bean-reader.create"); + StartupStep createAnnotatedBeanDefReader = getApplicationStartup().start("spring.context.annotated-bean-reader.create"); this.reader = new AnnotatedBeanDefinitionReader(this); createAnnotatedBeanDefReader.end(); this.scanner = new ClassPathBeanDefinitionScanner(this); @@ -163,7 +163,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex @Override public void register(Class... componentClasses) { Assert.notEmpty(componentClasses, "At least one component class must be specified"); - StartupStep registerComponentClass = this.getApplicationStartup().start("spring.context.component-classes.register") + StartupStep registerComponentClass = getApplicationStartup().start("spring.context.component-classes.register") .tag("classes", () -> Arrays.toString(componentClasses)); this.reader.register(componentClasses); registerComponentClass.end(); @@ -180,7 +180,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex @Override public void scan(String... basePackages) { Assert.notEmpty(basePackages, "At least one base package must be specified"); - StartupStep scanPackages = this.getApplicationStartup().start("spring.context.base-packages.scan") + StartupStep scanPackages = getApplicationStartup().start("spring.context.base-packages.scan") .tag("packages", () -> Arrays.toString(basePackages)); this.scanner.scan(basePackages); scanPackages.end(); diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index e1f60b9302..43b6ddd89d 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -397,14 +397,9 @@ public abstract class AbstractApplicationEventMulticaster @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ListenerCacheKey otherKey)) { - return false; - } - return (this.eventType.equals(otherKey.eventType) && - ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType)); + return (this == other || (other instanceof ListenerCacheKey that && + this.eventType.equals(that.eventType) && + ObjectUtils.nullSafeEquals(this.sourceType, that.sourceType))); } @Override diff --git a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java index 6476217f32..194d6ca133 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java +++ b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.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. @@ -52,14 +52,9 @@ public final class AnnotatedElementKey implements Comparable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MethodClassKey otherKey)) { - return false; - } - return (this.method.equals(otherKey.method) && - ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass)); + return (this == other || (other instanceof MethodClassKey that && + this.method.equals(that.method) && + ObjectUtils.nullSafeEquals(this.targetClass, that.targetClass))); } @Override 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 8004b87a2f..8f12df23bc 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -750,17 +750,12 @@ public class MethodParameter { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MethodParameter otherParam)) { - return false; - } - return (getContainingClass() == otherParam.getContainingClass() && - ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, otherParam.typeIndexesPerLevel) && - this.nestingLevel == otherParam.nestingLevel && - this.parameterIndex == otherParam.parameterIndex && - this.executable.equals(otherParam.executable)); + return (this == other || (other instanceof MethodParameter that && + getContainingClass() == that.getContainingClass() && + ObjectUtils.nullSafeEquals(this.typeIndexesPerLevel, that.typeIndexesPerLevel) && + this.nestingLevel == that.nestingLevel && + this.parameterIndex == that.parameterIndex && + this.executable.equals(that.executable))); } @Override 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 8316e4a4ef..4746299e1f 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1577,14 +1577,9 @@ public class ResolvableType implements Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ParameterizedType otherType)) { - return false; - } - return (otherType.getOwnerType() == null && this.rawType.equals(otherType.getRawType()) && - Arrays.equals(this.typeArguments, otherType.getActualTypeArguments())); + return (this == other || (other instanceof ParameterizedType that && + that.getOwnerType() == null && this.rawType.equals(that.getRawType()) && + Arrays.equals(this.typeArguments, that.getActualTypeArguments()))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/Property.java b/spring-core/src/main/java/org/springframework/core/convert/Property.java index d35d44951e..1e774106cd 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/Property.java +++ b/spring-core/src/main/java/org/springframework/core/convert/Property.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. @@ -260,16 +260,11 @@ public final class Property { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Property otherProperty)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.objectType, otherProperty.objectType) && - ObjectUtils.nullSafeEquals(this.name, otherProperty.name) && - ObjectUtils.nullSafeEquals(this.readMethod, otherProperty.readMethod) && - ObjectUtils.nullSafeEquals(this.writeMethod, otherProperty.writeMethod)); + return (this == other || (other instanceof Property that && + ObjectUtils.nullSafeEquals(this.objectType, that.objectType) && + ObjectUtils.nullSafeEquals(this.name, that.name) && + ObjectUtils.nullSafeEquals(this.readMethod, that.readMethod) && + ObjectUtils.nullSafeEquals(this.writeMethod, that.writeMethod))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java index d2b893ab46..d2d50eac6a 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java @@ -387,7 +387,7 @@ public class GenericConversionService implements ConfigurableConversionService { @Override public String toString() { - return (this.typeInfo + " : " + this.converter); + return this.typeInfo + " : " + this.converter; } } @@ -438,7 +438,7 @@ public class GenericConversionService implements ConfigurableConversionService { @Override public String toString() { - return (this.typeInfo + " : " + this.converterFactory); + return this.typeInfo + " : " + this.converterFactory; } } @@ -459,25 +459,19 @@ public class GenericConversionService implements ConfigurableConversionService { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ConverterCacheKey otherKey)) { - return false; - } - return (this.sourceType.equals(otherKey.sourceType)) && - this.targetType.equals(otherKey.targetType); + return (this == other || (other instanceof ConverterCacheKey that && + this.sourceType.equals(that.sourceType)) && + this.targetType.equals(that.targetType)); } @Override public int hashCode() { - return (this.sourceType.hashCode() * 29 + this.targetType.hashCode()); + return this.sourceType.hashCode() * 29 + this.targetType.hashCode(); } @Override public String toString() { - return ("ConverterCacheKey [sourceType = " + this.sourceType + - ", targetType = " + this.targetType + "]"); + return "ConverterCacheKey [sourceType = " + this.sourceType + ", targetType = " + this.targetType + "]"; } @Override diff --git a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java index 0f80080d1d..c317f5e2dc 100644 --- a/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.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. @@ -252,7 +252,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou @Override public final boolean containsProperty(String name) { if (this.nonOptionArgsPropertyName.equals(name)) { - return !this.getNonOptionArgs().isEmpty(); + return !getNonOptionArgs().isEmpty(); } return this.containsOption(name); } @@ -270,7 +270,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou @Nullable public final String getProperty(String name) { if (this.nonOptionArgsPropertyName.equals(name)) { - Collection nonOptionArguments = this.getNonOptionArgs(); + Collection nonOptionArguments = getNonOptionArgs(); if (nonOptionArguments.isEmpty()) { return null; } @@ -278,7 +278,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou return StringUtils.collectionToCommaDelimitedString(nonOptionArguments); } } - Collection optionValues = this.getOptionValues(name); + Collection optionValues = getOptionValues(name); if (optionValues == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index c60583a573..def3ccf396 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -482,15 +482,10 @@ public class DefaultDataBuffer implements DataBuffer { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof DefaultDataBuffer otherBuffer)) { - return false; - } - return (this.readPosition == otherBuffer.readPosition && - this.writePosition == otherBuffer.writePosition && - this.byteBuffer.equals(otherBuffer.byteBuffer)); + return (this == other || (other instanceof DefaultDataBuffer that && + this.readPosition == that.readPosition && + this.writePosition == that.writePosition && + this.byteBuffer.equals(that.byteBuffer))); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java index c6c4635577..c052a3ca5b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/EncodedResource.java @@ -184,15 +184,10 @@ public class EncodedResource implements InputStreamSource { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof EncodedResource otherResource)) { - return false; - } - return (this.resource.equals(otherResource.resource) && - ObjectUtils.nullSafeEquals(this.charset, otherResource.charset) && - ObjectUtils.nullSafeEquals(this.encoding, otherResource.encoding)); + return (this == other || (other instanceof EncodedResource that && + this.resource.equals(that.resource) && + ObjectUtils.nullSafeEquals(this.charset, that.charset) && + ObjectUtils.nullSafeEquals(this.encoding, that.encoding))); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index 7e38af7a0b..4337aca263 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -751,28 +751,22 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen return previous; } + @Override + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof Map.Entry that && + ObjectUtils.nullSafeEquals(getKey(), that.getKey()) && + ObjectUtils.nullSafeEquals(getValue(), that.getValue()))); + } + + @Override + public int hashCode() { + return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value)); + } + @Override public String toString() { return (this.key + "=" + this.value); } - - @Override - @SuppressWarnings("rawtypes") - public final boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Map.Entry otherEntry)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getKey(), otherEntry.getKey()) && - ObjectUtils.nullSafeEquals(getValue(), otherEntry.getValue())); - } - - @Override - public final int hashCode() { - return (ObjectUtils.nullSafeHashCode(this.key) ^ ObjectUtils.nullSafeHashCode(this.value)); - } } diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index 47d58fc39e..1043279d96 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -410,7 +410,7 @@ public class MimeType implements Comparable, Serializable { return (thisSuffix.equals(other.getSubtype()) || thisSuffix.equals(otherSuffix)); } else if (other.isWildcardSubtype() && otherSuffix != null) { - return (this.getSubtype().equals(otherSuffix) || otherSuffix.equals(thisSuffix)); + return (getSubtype().equals(otherSuffix) || otherSuffix.equals(thisSuffix)); } } } @@ -451,15 +451,10 @@ public class MimeType implements Comparable, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MimeType otherType)) { - return false; - } - return (this.type.equalsIgnoreCase(otherType.type) && + return (this == other || (other instanceof MimeType otherType && + this.type.equalsIgnoreCase(otherType.type) && this.subtype.equalsIgnoreCase(otherType.subtype) && - parametersAreEqual(otherType)); + parametersAreEqual(otherType))); } /** diff --git a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java index ddedb43094..ab131ad7fe 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.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. @@ -107,16 +107,10 @@ public class NullSafeComparator implements Comparator { @Override - @SuppressWarnings("unchecked") public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof NullSafeComparator otherComparator)) { - return false; - } - return (this.nonNullComparator.equals(otherComparator.nonNullComparator) - && this.nullsLow == otherComparator.nullsLow); + return (this == other || (other instanceof NullSafeComparator that && + this.nonNullComparator.equals(that.nonNullComparator) && + this.nullsLow == that.nullsLow)); } @Override diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java index ae4944ddcc..f6b444d139 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.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. @@ -99,7 +99,7 @@ public class MockPropertySource extends PropertiesPropertySource { * @return this {@link MockPropertySource} instance */ public MockPropertySource withProperty(String name, Object value) { - this.setProperty(name, value); + setProperty(name, value); return this; } diff --git a/spring-expression/src/main/java/org/springframework/expression/TypedValue.java b/spring-expression/src/main/java/org/springframework/expression/TypedValue.java index a4f2427cc0..ccd8b57235 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypedValue.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypedValue.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. @@ -82,16 +82,11 @@ public class TypedValue { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof TypedValue otherTv)) { - return false; - } // Avoid TypeDescriptor initialization if not necessary - return (ObjectUtils.nullSafeEquals(this.value, otherTv.value) && - ((this.typeDescriptor == null && otherTv.typeDescriptor == null) || - ObjectUtils.nullSafeEquals(getTypeDescriptor(), otherTv.getTypeDescriptor()))); + return (this == other || (other instanceof TypedValue that && + ObjectUtils.nullSafeEquals(this.value, that.value) && + ((this.typeDescriptor == null && that.typeDescriptor == null) || + ObjectUtils.nullSafeEquals(getTypeDescriptor(), that.getTypeDescriptor())))); } @Override diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java index 61f1100db2..fa2cd34fbc 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java @@ -591,14 +591,9 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof PropertyCacheKey otherKey)) { - return false; - } - return (this.clazz == otherKey.clazz && this.property.equals(otherKey.property) && - this.targetIsClass == otherKey.targetIsClass); + return (this == other || (other instanceof PropertyCacheKey that && + this.clazz == that.clazz && this.property.equals(that.property) && + this.targetIsClass == that.targetIsClass)); } @Override diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index b308b5a21f..589c8cc098 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -615,22 +615,17 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ConsumerCacheKey otherKey)) { - return false; - } - return (destinationEquals(otherKey) && - ObjectUtils.nullSafeEquals(this.selector, otherKey.selector) && - ObjectUtils.nullSafeEquals(this.noLocal, otherKey.noLocal) && - ObjectUtils.nullSafeEquals(this.subscription, otherKey.subscription) && - this.durable == otherKey.durable); + return (this == other || (other instanceof ConsumerCacheKey that && + destinationEquals(that) && + ObjectUtils.nullSafeEquals(this.selector, that.selector) && + ObjectUtils.nullSafeEquals(this.noLocal, that.noLocal) && + ObjectUtils.nullSafeEquals(this.subscription, that.subscription) && + this.durable == that.durable)); } @Override public int hashCode() { - return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector)); + return super.hashCode() * 31 + ObjectUtils.nullSafeHashCode(this.selector); } @Override diff --git a/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java b/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java index 9f627cf089..39ee533489 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.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. @@ -111,21 +111,15 @@ public class QosSettings { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof QosSettings otherSettings)) { - return false; - } - - return (this.deliveryMode == otherSettings.deliveryMode && - this.priority == otherSettings.priority && - this.timeToLive == otherSettings.timeToLive); + return (this == other || (other instanceof QosSettings that && + this.deliveryMode == that.deliveryMode && + this.priority == that.priority && + this.timeToLive == that.timeToLive)); } @Override public int hashCode() { - return (this.deliveryMode * 31 + this.priority); + return this.deliveryMode * 31 + this.priority; } @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 f10bd29055..2d2f254aba 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 @@ -532,14 +532,9 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SimpSubscription otherSubscription)) { - return false; - } - return (getId().equals(otherSubscription.getId()) && - ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession())); + return (this == other || (other instanceof SimpSubscription that && + getId().equals(that.getId()) && + ObjectUtils.nullSafeEquals(getSession(), that.getSession()))); } @Override diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java b/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java index dbb2efa0b7..b81401a94b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java @@ -90,20 +90,15 @@ public class GenericMessage implements Message, Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof GenericMessage otherMsg)) { - return false; - } // Using nullSafeEquals for proper array equals comparisons - return (ObjectUtils.nullSafeEquals(this.payload, otherMsg.payload) && this.headers.equals(otherMsg.headers)); + return (this == other || (other instanceof GenericMessage that && + ObjectUtils.nullSafeEquals(this.payload, that.payload) && this.headers.equals(that.headers))); } @Override public int hashCode() { // Using nullSafeHashCode for proper array hashCode handling - return (ObjectUtils.nullSafeHashCode(this.payload) * 23 + this.headers.hashCode()); + return ObjectUtils.nullSafeHashCode(this.payload) * 23 + this.headers.hashCode(); } @Override diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java index 3cdad9c50a..1cc9ffb576 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java @@ -59,14 +59,9 @@ public class TestSimpSubscription implements SimpSubscription { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SimpSubscription otherSubscription)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getSession(), otherSubscription.getSession()) && - this.id.equals(otherSubscription.getId())); + return (this == other || (other instanceof SimpSubscription that && + ObjectUtils.nullSafeEquals(getSession(), that.getSession()) && + this.id.equals(that.getId()))); } @Override diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java index fd5e36da31..8975e15f45 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.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. @@ -54,7 +54,7 @@ public class MockEnvironment extends AbstractEnvironment { * @see MockPropertySource#withProperty */ public MockEnvironment withProperty(String key, String value) { - this.setProperty(key, value); + setProperty(key, value); return this; } diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java index 2f3eb44151..5bf297c1e2 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. diff --git a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java index e7e598bfdf..591ee45fc9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.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. @@ -334,20 +334,15 @@ public class ContextConfigurationAttributes { */ @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ContextConfigurationAttributes otherAttr)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.declaringClass, otherAttr.declaringClass) && - Arrays.equals(this.classes, otherAttr.classes)) && - Arrays.equals(this.locations, otherAttr.locations) && - this.inheritLocations == otherAttr.inheritLocations && - Arrays.equals(this.initializers, otherAttr.initializers) && - this.inheritInitializers == otherAttr.inheritInitializers && - ObjectUtils.nullSafeEquals(this.name, otherAttr.name) && - ObjectUtils.nullSafeEquals(this.contextLoaderClass, otherAttr.contextLoaderClass); + return (this == other || (other instanceof ContextConfigurationAttributes that && + ObjectUtils.nullSafeEquals(this.declaringClass, that.declaringClass) && + Arrays.equals(this.classes, that.classes)) && + Arrays.equals(this.locations, that.locations) && + this.inheritLocations == that.inheritLocations && + Arrays.equals(this.initializers, that.initializers) && + this.inheritInitializers == that.inheritInitializers && + ObjectUtils.nullSafeEquals(this.name, that.name) && + ObjectUtils.nullSafeEquals(this.contextLoaderClass, that.contextLoaderClass)); } /** diff --git a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java index 19255b7365..026d0527f9 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.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. @@ -112,7 +112,7 @@ public class XpathExpectationsHelper { Document document = parseXmlByteArray(content, encoding); NodeList nodeList = evaluateXpath(document, XPathConstants.NODESET, NodeList.class); - MatcherAssert.assertThat("XPath " + this.getXpathExpression(), nodeList, matcher); + MatcherAssert.assertThat("XPath " + getXpathExpression(), nodeList, matcher); } /** diff --git a/spring-test/src/test/java/org/springframework/test/web/Person.java b/spring-test/src/test/java/org/springframework/test/web/Person.java index e172d0f71e..c3f11753b7 100644 --- a/spring-test/src/test/java/org/springframework/test/web/Person.java +++ b/spring-test/src/test/java/org/springframework/test/web/Person.java @@ -68,15 +68,10 @@ public class Person { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Person otherPerson)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.name, otherPerson.name) && - ObjectUtils.nullSafeEquals(this.someDouble, otherPerson.someDouble) && - ObjectUtils.nullSafeEquals(this.someBoolean, otherPerson.someBoolean)); + return (this == other || (other instanceof Person that && + ObjectUtils.nullSafeEquals(this.name, that.name) && + ObjectUtils.nullSafeEquals(this.someDouble, that.someDouble) && + ObjectUtils.nullSafeEquals(this.someBoolean, that.someBoolean))); } @Override diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java index d1f068dbf4..4f94d16f19 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.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. @@ -65,13 +65,8 @@ public class MatchAlwaysTransactionAttributeSource implements TransactionAttribu @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof MatchAlwaysTransactionAttributeSource otherTas)) { - return false; - } - return ObjectUtils.nullSafeEquals(this.transactionAttribute, otherTas.transactionAttribute); + return (this == other || (other instanceof MatchAlwaysTransactionAttributeSource that && + ObjectUtils.nullSafeEquals(this.transactionAttribute, that.transactionAttribute))); } @Override diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java index d06d981ce1..0762a9ae79 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.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. @@ -180,13 +180,8 @@ public class RollbackRuleAttribute implements Serializable{ @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof RollbackRuleAttribute rhs)) { - return false; - } - return this.exceptionPattern.equals(rhs.exceptionPattern); + return (this == other || (other instanceof RollbackRuleAttribute that && + this.exceptionPattern.equals(that.exceptionPattern))); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java index ca4c93d7d9..5600bb16e4 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -227,20 +227,15 @@ public final class ContentDisposition { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ContentDisposition otherCd)) { - return false; - } - return (ObjectUtils.nullSafeEquals(this.type, otherCd.type) && - ObjectUtils.nullSafeEquals(this.name, otherCd.name) && - ObjectUtils.nullSafeEquals(this.filename, otherCd.filename) && - ObjectUtils.nullSafeEquals(this.charset, otherCd.charset) && - ObjectUtils.nullSafeEquals(this.size, otherCd.size) && - ObjectUtils.nullSafeEquals(this.creationDate, otherCd.creationDate)&& - ObjectUtils.nullSafeEquals(this.modificationDate, otherCd.modificationDate)&& - ObjectUtils.nullSafeEquals(this.readDate, otherCd.readDate)); + return (this == other || (other instanceof ContentDisposition that && + ObjectUtils.nullSafeEquals(this.type, that.type) && + ObjectUtils.nullSafeEquals(this.name, that.name) && + ObjectUtils.nullSafeEquals(this.filename, that.filename) && + ObjectUtils.nullSafeEquals(this.charset, that.charset) && + ObjectUtils.nullSafeEquals(this.size, that.size) && + ObjectUtils.nullSafeEquals(this.creationDate, that.creationDate)&& + ObjectUtils.nullSafeEquals(this.modificationDate, that.modificationDate)&& + ObjectUtils.nullSafeEquals(this.readDate, that.readDate))); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/HttpCookie.java b/spring-web/src/main/java/org/springframework/http/HttpCookie.java index 01fb12b90f..e85bd9f9c8 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpCookie.java +++ b/spring-web/src/main/java/org/springframework/http/HttpCookie.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. @@ -57,19 +57,14 @@ public class HttpCookie { @Override - public int hashCode() { - return this.name.hashCode(); + public boolean equals(@Nullable Object other) { + return (this == other || (other instanceof HttpCookie that && + this.name.equalsIgnoreCase(that.getName()))); } @Override - public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof HttpCookie otherCookie)) { - return false; - } - return (this.name.equalsIgnoreCase(otherCookie.getName())); + public int hashCode() { + return this.name.hashCode(); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/HttpRange.java b/spring-web/src/main/java/org/springframework/http/HttpRange.java index 262639307b..445f046653 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpRange.java +++ b/spring-web/src/main/java/org/springframework/http/HttpRange.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. @@ -269,14 +269,9 @@ public abstract class HttpRange { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ByteRange otherRange)) { - return false; - } - return (this.firstPos == otherRange.firstPos && - ObjectUtils.nullSafeEquals(this.lastPos, otherRange.lastPos)); + return (this == other || (other instanceof ByteRange that && + this.firstPos == that.firstPos && + ObjectUtils.nullSafeEquals(this.lastPos, that.lastPos))); } @Override @@ -331,13 +326,8 @@ public abstract class HttpRange { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SuffixByteRange otherRange)) { - return false; - } - return (this.suffixLength == otherRange.suffixLength); + return (this == other || (other instanceof SuffixByteRange that && + this.suffixLength == that.suffixLength)); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java index fb5dfe6d5a..cbe60aa353 100644 --- a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java +++ b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java @@ -233,18 +233,13 @@ public class ProblemDetail { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ProblemDetail otherDetail)) { - return false; - } - return (getType().equals(otherDetail.getType()) && - ObjectUtils.nullSafeEquals(getTitle(), otherDetail.getTitle()) && - this.status == otherDetail.status && - ObjectUtils.nullSafeEquals(this.detail, otherDetail.detail) && - ObjectUtils.nullSafeEquals(this.instance, otherDetail.instance) && - ObjectUtils.nullSafeEquals(this.properties, otherDetail.properties)); + return (this == other || (other instanceof ProblemDetail that && + getType().equals(that.getType()) && + ObjectUtils.nullSafeEquals(getTitle(), that.getTitle()) && + this.status == that.status && + ObjectUtils.nullSafeEquals(this.detail, that.detail) && + ObjectUtils.nullSafeEquals(this.instance, that.instance) && + ObjectUtils.nullSafeEquals(this.properties, that.properties))); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java index cba43ff387..e0b69e0e87 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseCookie.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. @@ -144,15 +144,10 @@ public final class ResponseCookie extends HttpCookie { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ResponseCookie otherCookie)) { - return false; - } - return (getName().equalsIgnoreCase(otherCookie.getName()) && - ObjectUtils.nullSafeEquals(this.path, otherCookie.getPath()) && - ObjectUtils.nullSafeEquals(this.domain, otherCookie.getDomain())); + return (this == other ||(other instanceof ResponseCookie that && + getName().equalsIgnoreCase(that.getName()) && + ObjectUtils.nullSafeEquals(this.path, that.getPath()) && + ObjectUtils.nullSafeEquals(this.domain, that.getDomain()))); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java b/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java index c3c494c4c4..43a056e2a7 100644 --- a/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java +++ b/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.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. @@ -41,7 +41,7 @@ public class ClientRequestObservationContext extends RequestReplySenderContext= 100 && code < 200) || code == 204 || code == 205 || method.equals(HttpMethod.HEAD) || getHeaders().getContentLength() == 0); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java index b6209eda38..cb8e8ffb89 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java @@ -244,13 +244,8 @@ public class ServletContextResource extends AbstractFileResolvingResource implem */ @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ServletContextResource otherRes)) { - return false; - } - return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path)); + return (this == other || (other instanceof ServletContextResource that && + this.path.equals(that.path) && this.servletContext.equals(that.servletContext))); } /** diff --git a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java index c57cda1267..345a772d9a 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java +++ b/spring-web/src/main/java/org/springframework/web/filter/DelegatingFilterProxy.java @@ -161,10 +161,10 @@ public class DelegatingFilterProxy extends GenericFilterBean { */ public DelegatingFilterProxy(String targetBeanName, @Nullable WebApplicationContext wac) { Assert.hasText(targetBeanName, "Target Filter bean name must not be null or empty"); - this.setTargetBeanName(targetBeanName); + setTargetBeanName(targetBeanName); this.webApplicationContext = wac; if (wac != null) { - this.setEnvironment(wac.getEnvironment()); + setEnvironment(wac.getEnvironment()); } } diff --git a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java index 4402dd37bf..969213552c 100644 --- a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java +++ b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.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. @@ -257,13 +257,8 @@ public class ControllerAdviceBean implements Ordered { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ControllerAdviceBean otherAdvice)) { - return false; - } - return (this.beanOrName.equals(otherAdvice.beanOrName) && this.beanFactory == otherAdvice.beanFactory); + return (this == other || (other instanceof ControllerAdviceBean that && + this.beanOrName.equals(that.beanOrName) && this.beanFactory == that.beanFactory)); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/server/session/HeaderWebSessionIdResolver.java b/spring-web/src/main/java/org/springframework/web/server/session/HeaderWebSessionIdResolver.java index 9647875ef4..fdf1c60681 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/HeaderWebSessionIdResolver.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/HeaderWebSessionIdResolver.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. @@ -74,7 +74,7 @@ public class HeaderWebSessionIdResolver implements WebSessionIdResolver { @Override public void expireSession(ServerWebExchange exchange) { - this.setSessionId(exchange, ""); + setSessionId(exchange, ""); } } diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index 50ad767e48..7314cf92eb 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.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. @@ -554,19 +554,14 @@ final class HierarchicalUriComponents extends UriComponents { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof HierarchicalUriComponents otherComp)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) && - ObjectUtils.nullSafeEquals(getUserInfo(), otherComp.getUserInfo()) && - ObjectUtils.nullSafeEquals(getHost(), otherComp.getHost()) && - getPort() == otherComp.getPort() && - this.path.equals(otherComp.path) && - this.queryParams.equals(otherComp.queryParams) && - ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment())); + return (this == other || (other instanceof HierarchicalUriComponents that && + ObjectUtils.nullSafeEquals(getScheme(), that.getScheme()) && + ObjectUtils.nullSafeEquals(getUserInfo(), that.getUserInfo()) && + ObjectUtils.nullSafeEquals(getHost(), that.getHost()) && + getPort() == that.getPort() && + this.path.equals(that.path) && + this.queryParams.equals(that.queryParams) && + ObjectUtils.nullSafeEquals(getFragment(), that.getFragment()))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java index f6a231c470..3c886b4523 100644 --- a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.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. @@ -158,15 +158,10 @@ final class OpaqueUriComponents extends UriComponents { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof OpaqueUriComponents otherComp)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getScheme(), otherComp.getScheme()) && - ObjectUtils.nullSafeEquals(this.ssp, otherComp.ssp) && - ObjectUtils.nullSafeEquals(getFragment(), otherComp.getFragment())); + return (this == other || (other instanceof OpaqueUriComponents that && + ObjectUtils.nullSafeEquals(getScheme(), that.getScheme()) && + ObjectUtils.nullSafeEquals(this.ssp, that.ssp) && + ObjectUtils.nullSafeEquals(getFragment(), that.getFragment()))); } @Override diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 597c0df057..95876951ae 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -432,12 +432,10 @@ public class PathPattern implements Comparable { @Override public boolean equals(@Nullable Object other) { - if (!(other instanceof PathPattern otherPattern)) { - return false; - } - return (this.patternString.equals(otherPattern.getPatternString()) && - getSeparator() == otherPattern.getSeparator() && - this.caseSensitive == otherPattern.caseSensitive); + return (this == other || (other instanceof PathPattern that && + this.patternString.equals(that.getPatternString()) && + getSeparator() == that.getSeparator() && + this.caseSensitive == that.caseSensitive)); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java index 98cf2eb188..351348431b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.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. @@ -167,18 +167,13 @@ public abstract class ExchangeFilterFunctions { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof Credentials otherCred)) { - return false; - } - return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password)); + return (this == other ||(other instanceof Credentials that && + this.username.equals(that.username) && this.password.equals(that.password))); } @Override public int hashCode() { - return 31 * this.username.hashCode() + this.password.hashCode(); + return this.username.hashCode() * 31 + this.password.hashCode(); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java index 2ed0f123bc..0bb8f0398d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java @@ -282,13 +282,8 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof ContentChunkInfo otherCci)) { - return false; - } - return (this.start == otherCci.start && this.end == otherCci.end); + return (this == other || (other instanceof ContentChunkInfo that && + this.start == that.start && this.end == that.end)); } @Override diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java index c529b9a96f..88d304374d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.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. @@ -95,7 +95,7 @@ abstract class AbstractMediaTypeExpression implements Comparable implements Comparabl @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof FlashMap otherFlashMap)) { - return false; - } - return (super.equals(otherFlashMap) && - ObjectUtils.nullSafeEquals(this.targetRequestPath, otherFlashMap.targetRequestPath) && - this.targetRequestParams.equals(otherFlashMap.targetRequestParams)); + return (this == other || (other instanceof FlashMap that && + super.equals(other) && + ObjectUtils.nullSafeEquals(this.targetRequestPath, that.targetRequestPath) && + this.targetRequestParams.equals(that.targetRequestParams))); } @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java index fbdb53d63c..f13fdccd2d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.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. @@ -68,7 +68,7 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa @Override public int compareTo(AbstractMediaTypeExpression other) { - MediaType mediaType1 = this.getMediaType(); + MediaType mediaType1 = getMediaType(); MediaType mediaType2 = other.getMediaType(); if (mediaType1.isMoreSpecific(mediaType2)) { return -1; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java index e8e8135c98..3371114693 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java @@ -475,19 +475,14 @@ public final class RequestMappingInfo implements RequestCondition implements WebSocketMessage @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof AbstractWebSocketMessage otherMessage)) { - return false; - } - return ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload); + return (this == other || (other instanceof AbstractWebSocketMessage that && + ObjectUtils.nullSafeEquals(this.payload, that.payload))); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java index 0e1fb747c9..70192c72fb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java @@ -207,13 +207,8 @@ public final class CloseStatus implements Serializable { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof CloseStatus otherStatus)) { - return false; - } - return (this.code == otherStatus.code && ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason)); + return (this == other || (other instanceof CloseStatus that && + this.code == that.code && ObjectUtils.nullSafeEquals(this.reason, that.reason))); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java index 56afb69815..08cd92c371 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketHttpHeaders.java @@ -309,13 +309,8 @@ public class WebSocketHttpHeaders extends HttpHeaders { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof WebSocketHttpHeaders otherHeaders)) { - return false; - } - return this.headers.equals(otherHeaders.headers); + return (this == other || (other instanceof WebSocketHttpHeaders that && + this.headers.equals(that.headers))); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java index ba9d1f9e54..3a5a0f69de 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistry.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. @@ -238,8 +238,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { - return (this == other || - (other instanceof SimpUser otherSimpUser && getName().equals(otherSimpUser.getName()))); + return (this == other || (other instanceof SimpUser that && getName().equals(that.getName()))); } @Override @@ -294,8 +293,7 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { - return (this == other || - (other instanceof SimpSubscription otherSubscription && getId().equals(otherSubscription.getId()))); + return (this == other || (other instanceof SimpSubscription that && getId().equals(that.getId()))); } @Override @@ -344,14 +342,9 @@ public class DefaultSimpUserRegistry implements SimpUserRegistry, SmartApplicati @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SimpSubscription otherSubscription)) { - return false; - } - return (getId().equals(otherSubscription.getId()) && - getSession().getId().equals(otherSubscription.getSession().getId())); + return (this == other || (other instanceof SimpSubscription that && + getId().equals(that.getId()) && + getSession().getId().equals(that.getSession().getId()))); } @Override diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java index 35cf0fbff6..f197e52b1b 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsFrame.java @@ -122,13 +122,8 @@ public class SockJsFrame { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof SockJsFrame otherFrame)) { - return false; - } - return (this.type.equals(otherFrame.type) && this.content.equals(otherFrame.content)); + return (this == other || (other instanceof SockJsFrame that && + this.type.equals(that.type) && this.content.equals(that.content))); } @Override