Consistent equals/hashCode style (and related polishing)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user