Skip to content

Commit 2f33e77

Browse files
committed
Consistent equals/hashCode style (and related polishing)
1 parent bbcc788 commit 2f33e77

File tree

98 files changed

+408
-830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+408
-830
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,8 @@ public boolean matches(Method method, Class<?> targetClass) {
714714

715715
@Override
716716
public boolean equals(@Nullable Object other) {
717-
if (this == other) {
718-
return true;
719-
}
720-
if (!(other instanceof AdviceExcludingMethodMatcher otherMm)) {
721-
return false;
722-
}
723-
return this.adviceMethod.equals(otherMm.adviceMethod);
717+
return (this == other || (other instanceof AdviceExcludingMethodMatcher that &&
718+
this.adviceMethod.equals(that.adviceMethod)));
724719
}
725720

726721
@Override

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ private PointcutParser initializePointcutParser(@Nullable ClassLoader classLoade
243243

244244
/**
245245
* If a pointcut expression has been specified in XML, the user cannot
246-
* write {@code and} as "&&" (though &amp;&amp; will work).
247-
* We also allow {@code and} between two pointcut sub-expressions.
246+
* write "and" as "&&" (though {@code &amp;&amp;} will work).
247+
* <p>We also allow "and" between two pointcut sub-expressions.
248248
* <p>This method converts back to {@code &&} for the AspectJ pointcut parser.
249249
*/
250250
private String replaceBooleanOperators(String pcExpr) {
@@ -516,21 +516,16 @@ else if (shadowMatch.maybeMatches() && fallbackExpression != null) {
516516

517517
@Override
518518
public boolean equals(@Nullable Object other) {
519-
if (this == other) {
520-
return true;
521-
}
522-
if (!(other instanceof AspectJExpressionPointcut otherPc)) {
523-
return false;
524-
}
525-
return ObjectUtils.nullSafeEquals(this.getExpression(), otherPc.getExpression()) &&
526-
ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, otherPc.pointcutDeclarationScope) &&
527-
ObjectUtils.nullSafeEquals(this.pointcutParameterNames, otherPc.pointcutParameterNames) &&
528-
ObjectUtils.nullSafeEquals(this.pointcutParameterTypes, otherPc.pointcutParameterTypes);
519+
return (this == other || (other instanceof AspectJExpressionPointcut that &&
520+
ObjectUtils.nullSafeEquals(getExpression(), that.getExpression()) &&
521+
ObjectUtils.nullSafeEquals(this.pointcutDeclarationScope, that.pointcutDeclarationScope) &&
522+
ObjectUtils.nullSafeEquals(this.pointcutParameterNames, that.pointcutParameterNames) &&
523+
ObjectUtils.nullSafeEquals(this.pointcutParameterTypes, that.pointcutParameterTypes)));
529524
}
530525

531526
@Override
532527
public int hashCode() {
533-
int hashCode = ObjectUtils.nullSafeHashCode(this.getExpression());
528+
int hashCode = ObjectUtils.nullSafeHashCode(getExpression());
534529
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutDeclarationScope);
535530
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterNames);
536531
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterTypes);

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,8 @@ public String getAspectName() {
8989

9090
@Override
9191
public boolean equals(@Nullable Object other) {
92-
if (this == other) {
93-
return true;
94-
}
95-
if (!(other instanceof AspectJPointcutAdvisor otherAdvisor)) {
96-
return false;
97-
}
98-
return this.advice.equals(otherAdvisor.advice);
92+
return (this == other || (other instanceof AspectJPointcutAdvisor that &&
93+
this.advice.equals(that.advice)));
9994
}
10095

10196
@Override

spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,10 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy
597597
}
598598
if (other instanceof Factory factory) {
599599
Callback callback = factory.getCallback(INVOKE_EQUALS);
600-
if (!(callback instanceof EqualsInterceptor equalsInterceptor)) {
601-
return false;
602-
}
603-
AdvisedSupport otherAdvised = equalsInterceptor.advised;
604-
return AopProxyUtils.equalsInProxy(this.advised, otherAdvised);
605-
}
606-
else {
607-
return false;
600+
return (callback instanceof EqualsInterceptor that &&
601+
AopProxyUtils.equalsInProxy(this.advised, that.advised));
608602
}
603+
return false;
609604
}
610605
}
611606

@@ -920,20 +915,14 @@ public int accept(Method method) {
920915

921916
@Override
922917
public boolean equals(@Nullable Object other) {
923-
if (this == other) {
924-
return true;
925-
}
926-
if (!(other instanceof ProxyCallbackFilter otherCallbackFilter)) {
927-
return false;
928-
}
929-
AdvisedSupport otherAdvised = otherCallbackFilter.advised;
930-
return (this.advised.getAdvisorKey().equals(otherAdvised.getAdvisorKey()) &&
931-
AopProxyUtils.equalsProxiedInterfaces(this.advised, otherAdvised) &&
932-
ObjectUtils.nullSafeEquals(this.advised.getTargetClass(), otherAdvised.getTargetClass()) &&
933-
this.advised.getTargetSource().isStatic() == otherAdvised.getTargetSource().isStatic() &&
934-
this.advised.isFrozen() == otherAdvised.isFrozen() &&
935-
this.advised.isExposeProxy() == otherAdvised.isExposeProxy() &&
936-
this.advised.isOpaque() == otherAdvised.isOpaque());
918+
return (this == other || (other instanceof ProxyCallbackFilter that &&
919+
this.advised.getAdvisorKey().equals(that.advised.getAdvisorKey()) &&
920+
AopProxyUtils.equalsProxiedInterfaces(this.advised, that.advised) &&
921+
ObjectUtils.nullSafeEquals(this.advised.getTargetClass(), that.advised.getTargetClass()) &&
922+
this.advised.getTargetSource().isStatic() == that.advised.getTargetSource().isStatic() &&
923+
this.advised.isFrozen() == that.advised.isFrozen() &&
924+
this.advised.isExposeProxy() == that.advised.isExposeProxy() &&
925+
this.advised.isOpaque() == that.advised.isOpaque()));
937926
}
938927

939928
@Override

spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,9 @@ private Object readResolve() {
133133

134134
@Override
135135
public boolean equals(@Nullable Object other) {
136-
if (this == other) {
137-
return true;
138-
}
139-
if (!(other instanceof EmptyTargetSource otherTs)) {
140-
return false;
141-
}
142-
return (ObjectUtils.nullSafeEquals(this.targetClass, otherTs.targetClass) && this.isStatic == otherTs.isStatic);
136+
return (this == other || (other instanceof EmptyTargetSource that &&
137+
ObjectUtils.nullSafeEquals(this.targetClass, that.targetClass) &&
138+
this.isStatic == that.isStatic));
143139
}
144140

145141
@Override

spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,15 +82,10 @@ public Object getSource() {
8282

8383
@Override
8484
public boolean equals(@Nullable Object other) {
85-
if (this == other) {
86-
return true;
87-
}
88-
if (!(other instanceof BeanMetadataAttribute otherMa)) {
89-
return false;
90-
}
91-
return (this.name.equals(otherMa.name) &&
92-
ObjectUtils.nullSafeEquals(this.value, otherMa.value) &&
93-
ObjectUtils.nullSafeEquals(this.source, otherMa.source));
85+
return (this == other ||(other instanceof BeanMetadataAttribute that &&
86+
this.name.equals(that.name) &&
87+
ObjectUtils.nullSafeEquals(this.value, that.value) &&
88+
ObjectUtils.nullSafeEquals(this.source, that.source)));
9489
}
9590

9691
@Override

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,11 @@ public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
491491
*/
492492
@Override
493493
public boolean equals(@Nullable Object other) {
494-
if (this == other) {
495-
return true;
496-
}
497-
if (!(other instanceof IndexedPropertyDescriptor otherPd)) {
498-
return false;
499-
}
500-
return (ObjectUtils.nullSafeEquals(getIndexedReadMethod(), otherPd.getIndexedReadMethod()) &&
501-
ObjectUtils.nullSafeEquals(getIndexedWriteMethod(), otherPd.getIndexedWriteMethod()) &&
502-
ObjectUtils.nullSafeEquals(getIndexedPropertyType(), otherPd.getIndexedPropertyType()) &&
503-
PropertyDescriptorUtils.equals(this, otherPd));
494+
return (this == other || (other instanceof IndexedPropertyDescriptor that &&
495+
ObjectUtils.nullSafeEquals(getIndexedReadMethod(), that.getIndexedReadMethod()) &&
496+
ObjectUtils.nullSafeEquals(getIndexedWriteMethod(), that.getIndexedWriteMethod()) &&
497+
ObjectUtils.nullSafeEquals(getIndexedPropertyType(), that.getIndexedPropertyType()) &&
498+
PropertyDescriptorUtils.equals(this, that)));
504499
}
505500

506501
@Override

spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -165,13 +165,9 @@ public Class<?> getPropertyEditorClass() {
165165

166166
@Override
167167
public boolean equals(@Nullable Object other) {
168-
if (this == other) {
169-
return true;
170-
}
171-
if (!(other instanceof GenericTypeAwarePropertyDescriptor otherPd)) {
172-
return false;
173-
}
174-
return (getBeanClass().equals(otherPd.getBeanClass()) && PropertyDescriptorUtils.equals(this, otherPd));
168+
return (this == other || (other instanceof GenericTypeAwarePropertyDescriptor that &&
169+
getBeanClass().equals(that.getBeanClass()) &&
170+
PropertyDescriptorUtils.equals(this, that)));
175171
}
176172

177173
@Override

spring-beans/src/main/java/org/springframework/beans/PropertyValue.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,10 @@ public synchronized Object getConvertedValue() {
189189

190190
@Override
191191
public boolean equals(@Nullable Object other) {
192-
if (this == other) {
193-
return true;
194-
}
195-
if (!(other instanceof PropertyValue otherPv)) {
196-
return false;
197-
}
198-
return (this.name.equals(otherPv.name) &&
199-
ObjectUtils.nullSafeEquals(this.value, otherPv.value) &&
200-
ObjectUtils.nullSafeEquals(getSource(), otherPv.getSource()));
192+
return (this == other || (other instanceof PropertyValue that &&
193+
this.name.equals(that.name) &&
194+
ObjectUtils.nullSafeEquals(this.value, that.value) &&
195+
ObjectUtils.nullSafeEquals(getSource(), that.getSource())));
201196
}
202197

203198
@Override

spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,8 @@ protected Object getResourceToInject(Object target, @Nullable String requestingB
340340

341341
@Override
342342
public boolean equals(@Nullable Object other) {
343-
if (this == other) {
344-
return true;
345-
}
346-
if (!(other instanceof InjectedElement otherElement)) {
347-
return false;
348-
}
349-
return this.member.equals(otherElement.member);
343+
return (this == other || (other instanceof InjectedElement that &&
344+
this.member.equals(that.member)));
350345
}
351346

352347
@Override

0 commit comments

Comments
 (0)