Skip to content

Commit c16f582

Browse files
committed
Consistent equals implementations in AOP support classes
1 parent 6931106 commit c16f582

File tree

12 files changed

+52
-119
lines changed

12 files changed

+52
-119
lines changed

spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java

Lines changed: 4 additions & 9 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.
@@ -196,14 +196,9 @@ protected boolean matchesPattern(String signatureString) {
196196

197197
@Override
198198
public boolean equals(@Nullable Object other) {
199-
if (this == other) {
200-
return true;
201-
}
202-
if (!(other instanceof AbstractRegexpMethodPointcut otherPointcut)) {
203-
return false;
204-
}
205-
return (Arrays.equals(this.patterns, otherPointcut.patterns) &&
206-
Arrays.equals(this.excludedPatterns, otherPointcut.excludedPatterns));
199+
return (this == other || (other instanceof AbstractRegexpMethodPointcut otherPointcut &&
200+
Arrays.equals(this.patterns, otherPointcut.patterns) &&
201+
Arrays.equals(this.excludedPatterns, otherPointcut.excludedPatterns)));
207202
}
208203

209204
@Override

spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -187,14 +187,9 @@ public MethodMatcher getMethodMatcher() {
187187

188188
@Override
189189
public boolean equals(@Nullable Object other) {
190-
if (this == other) {
191-
return true;
192-
}
193-
if (!(other instanceof ComposablePointcut otherPointcut)) {
194-
return false;
195-
}
196-
return (this.classFilter.equals(otherPointcut.classFilter) &&
197-
this.methodMatcher.equals(otherPointcut.methodMatcher));
190+
return (this == other || (other instanceof ComposablePointcut otherPointcut &&
191+
this.classFilter.equals(otherPointcut.classFilter) &&
192+
this.methodMatcher.equals(otherPointcut.methodMatcher)));
198193
}
199194

200195
@Override

spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.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.
@@ -125,13 +125,9 @@ public MethodMatcher getMethodMatcher() {
125125

126126
@Override
127127
public boolean equals(@Nullable Object other) {
128-
if (this == other) {
129-
return true;
130-
}
131-
if (!(other instanceof ControlFlowPointcut that)) {
132-
return false;
133-
}
134-
return (this.clazz.equals(that.clazz)) && ObjectUtils.nullSafeEquals(this.methodName, that.methodName);
128+
return (this == other || (other instanceof ControlFlowPointcut that &&
129+
this.clazz.equals(that.clazz)) &&
130+
ObjectUtils.nullSafeEquals(this.methodName, that.methodName));
135131
}
136132

137133
@Override

spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -143,13 +143,8 @@ public boolean matches(Method method, Class<?> targetClass, Object... args) {
143143

144144
@Override
145145
public boolean equals(@Nullable Object other) {
146-
if (this == other) {
147-
return true;
148-
}
149-
if (!(other instanceof UnionMethodMatcher that)) {
150-
return false;
151-
}
152-
return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2));
146+
return (this == other || (other instanceof UnionMethodMatcher that &&
147+
this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2)));
153148
}
154149

155150
@Override
@@ -307,13 +302,8 @@ public boolean matches(Method method, Class<?> targetClass, Object... args) {
307302

308303
@Override
309304
public boolean equals(@Nullable Object other) {
310-
if (this == other) {
311-
return true;
312-
}
313-
if (!(other instanceof IntersectionMethodMatcher that)) {
314-
return false;
315-
}
316-
return (this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2));
305+
return (this == other || (other instanceof IntersectionMethodMatcher that &&
306+
this.mm1.equals(that.mm1) && this.mm2.equals(that.mm2)));
317307
}
318308

319309
@Override

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -68,13 +68,9 @@ public boolean matches(Class<?> clazz) {
6868

6969
@Override
7070
public boolean equals(@Nullable Object other) {
71-
if (this == other) {
72-
return true;
73-
}
74-
if (!(other instanceof AnnotationClassFilter otherCf)) {
75-
return false;
76-
}
77-
return (this.annotationType.equals(otherCf.annotationType) && this.checkInherited == otherCf.checkInherited);
71+
return (this == other || (other instanceof AnnotationClassFilter otherCf &&
72+
this.annotationType.equals(otherCf.annotationType) &&
73+
this.checkInherited == otherCf.checkInherited));
7874
}
7975

8076
@Override

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,9 @@ public MethodMatcher getMethodMatcher() {
121121

122122
@Override
123123
public boolean equals(@Nullable Object other) {
124-
if (this == other) {
125-
return true;
126-
}
127-
if (!(other instanceof AnnotationMatchingPointcut otherPointcut)) {
128-
return false;
129-
}
130-
return (this.classFilter.equals(otherPointcut.classFilter) &&
131-
this.methodMatcher.equals(otherPointcut.methodMatcher));
124+
return (this == other || (other instanceof AnnotationMatchingPointcut otherPointcut &&
125+
this.classFilter.equals(otherPointcut.classFilter) &&
126+
this.methodMatcher.equals(otherPointcut.methodMatcher)));
132127
}
133128

134129
@Override
@@ -183,14 +178,9 @@ public boolean matches(Class<?> clazz) {
183178
}
184179

185180
@Override
186-
public boolean equals(@Nullable Object obj) {
187-
if (this == obj) {
188-
return true;
189-
}
190-
if (!(obj instanceof AnnotationCandidateClassFilter that)) {
191-
return false;
192-
}
193-
return this.annotationType.equals(that.annotationType);
181+
public boolean equals(@Nullable Object other) {
182+
return (this == other || (other instanceof AnnotationCandidateClassFilter that &&
183+
this.annotationType.equals(that.annotationType)));
194184
}
195185

196186
@Override

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 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.
@@ -27,10 +27,9 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30-
* Simple {@link org.springframework.aop.MethodMatcher MethodMatcher} that looks
31-
* for a specific annotation being present on a method (checking both the method
32-
* on the invoked interface, if any, and the corresponding method on the target
33-
* class).
30+
* Simple {@link org.springframework.aop.MethodMatcher MethodMatcher} that looks for
31+
* a specific annotation being present on a method (checking both the method on the
32+
* invoked interface, if any, and the corresponding method on the target class).
3433
*
3534
* @author Juergen Hoeller
3635
* @author Sam Brannen
@@ -90,13 +89,9 @@ private boolean matchesMethod(Method method) {
9089

9190
@Override
9291
public boolean equals(@Nullable Object other) {
93-
if (this == other) {
94-
return true;
95-
}
96-
if (!(other instanceof AnnotationMethodMatcher otherMm)) {
97-
return false;
98-
}
99-
return (this.annotationType.equals(otherMm.annotationType) && this.checkInherited == otherMm.checkInherited);
92+
return (this == other || (other instanceof AnnotationMethodMatcher otherMm &&
93+
this.annotationType.equals(otherMm.annotationType) &&
94+
this.checkInherited == otherMm.checkInherited));
10095
}
10196

10297
@Override

spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java

Lines changed: 4 additions & 9 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,14 +165,9 @@ protected boolean allowPublicMethodsOnly() {
165165

166166
@Override
167167
public boolean equals(@Nullable Object other) {
168-
if (this == other) {
169-
return true;
170-
}
171-
if (!(other instanceof AnnotationCacheOperationSource otherCos)) {
172-
return false;
173-
}
174-
return (this.annotationParsers.equals(otherCos.annotationParsers) &&
175-
this.publicMethodsOnly == otherCos.publicMethodsOnly);
168+
return (this == other || (other instanceof AnnotationCacheOperationSource otherCos &&
169+
this.annotationParsers.equals(otherCos.annotationParsers) &&
170+
this.publicMethodsOnly == otherCos.publicMethodsOnly));
176171
}
177172

178173
@Override

spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.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.
@@ -111,13 +111,8 @@ protected boolean isMatch(String methodName, String mappedName) {
111111

112112
@Override
113113
public boolean equals(@Nullable Object other) {
114-
if (this == other) {
115-
return true;
116-
}
117-
if (!(other instanceof NameMatchCacheOperationSource otherTas)) {
118-
return false;
119-
}
120-
return ObjectUtils.nullSafeEquals(this.nameMap, otherTas.nameMap);
114+
return (this == other || (other instanceof NameMatchCacheOperationSource otherCos &&
115+
ObjectUtils.nullSafeEquals(this.nameMap, otherCos.nameMap)));
121116
}
122117

123118
@Override
@@ -129,4 +124,5 @@ public int hashCode() {
129124
public String toString() {
130125
return getClass().getName() + ": " + this.nameMap;
131126
}
127+
132128
}

spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java

Lines changed: 4 additions & 9 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.
@@ -191,14 +191,9 @@ protected boolean allowPublicMethodsOnly() {
191191

192192
@Override
193193
public boolean equals(@Nullable Object other) {
194-
if (this == other) {
195-
return true;
196-
}
197-
if (!(other instanceof AnnotationTransactionAttributeSource otherTas)) {
198-
return false;
199-
}
200-
return (this.annotationParsers.equals(otherTas.annotationParsers) &&
201-
this.publicMethodsOnly == otherTas.publicMethodsOnly);
194+
return (this == other || (other instanceof AnnotationTransactionAttributeSource otherTas &&
195+
this.annotationParsers.equals(otherTas.annotationParsers) &&
196+
this.publicMethodsOnly == otherTas.publicMethodsOnly));
202197
}
203198

204199
@Override

spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java

Lines changed: 3 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.
@@ -239,13 +239,8 @@ public TransactionAttribute getTransactionAttribute(Method method, @Nullable Cla
239239

240240
@Override
241241
public boolean equals(@Nullable Object other) {
242-
if (this == other) {
243-
return true;
244-
}
245-
if (!(other instanceof MethodMapTransactionAttributeSource otherTas)) {
246-
return false;
247-
}
248-
return ObjectUtils.nullSafeEquals(this.methodMap, otherTas.methodMap);
242+
return (this == other || (other instanceof MethodMapTransactionAttributeSource otherTas &&
243+
ObjectUtils.nullSafeEquals(this.methodMap, otherTas.methodMap)));
249244
}
250245

251246
@Override

spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java

Lines changed: 3 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.
@@ -164,13 +164,8 @@ protected boolean isMatch(String methodName, String mappedName) {
164164

165165
@Override
166166
public boolean equals(@Nullable Object other) {
167-
if (this == other) {
168-
return true;
169-
}
170-
if (!(other instanceof NameMatchTransactionAttributeSource otherTas)) {
171-
return false;
172-
}
173-
return ObjectUtils.nullSafeEquals(this.nameMap, otherTas.nameMap);
167+
return (this == other || (other instanceof NameMatchTransactionAttributeSource otherTas &&
168+
ObjectUtils.nullSafeEquals(this.nameMap, otherTas.nameMap)));
174169
}
175170

176171
@Override

0 commit comments

Comments
 (0)