Skip to content

Commit 18966d0

Browse files
committed
Consistent equals/hashCode style (and related polishing)
1 parent 7e6612a commit 18966d0

File tree

56 files changed

+195
-285
lines changed

Some content is hidden

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

56 files changed

+195
-285
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ private String replaceBooleanOperators(String pcExpr) {
117117
}
118118

119119
@Override
120-
public boolean equals(@Nullable Object obj) {
121-
return (this == obj || (obj instanceof TypePatternClassFilter that &&
120+
public boolean equals(@Nullable Object other) {
121+
return (this == other || (other instanceof TypePatternClassFilter that &&
122122
ObjectUtils.nullSafeEquals(this.typePattern, that.typePattern)));
123123
}
124124

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public boolean matches(Class<?> clazz) {
109109
}
110110

111111
@Override
112-
public boolean equals(@Nullable Object obj) {
113-
return (this == obj || (obj instanceof UnionClassFilter that &&
112+
public boolean equals(@Nullable Object other) {
113+
return (this == other || (other instanceof UnionClassFilter that &&
114114
ObjectUtils.nullSafeEquals(this.filters, that.filters)));
115115
}
116116

@@ -150,8 +150,8 @@ public boolean matches(Class<?> clazz) {
150150
}
151151

152152
@Override
153-
public boolean equals(@Nullable Object obj) {
154-
return (this == obj || (obj instanceof IntersectionClassFilter that &&
153+
public boolean equals(@Nullable Object other) {
154+
return (this == other || (other instanceof IntersectionClassFilter that &&
155155
ObjectUtils.nullSafeEquals(this.filters, that.filters)));
156156
}
157157

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ protected boolean isMatch(String methodName, String mappedName) {
100100

101101

102102
@Override
103-
public boolean equals(@Nullable Object obj) {
104-
return (this == obj || (obj instanceof NameMatchMethodPointcut that &&
103+
public boolean equals(@Nullable Object other) {
104+
return (this == other || (other instanceof NameMatchMethodPointcut that &&
105105
this.mappedNames.equals(that.mappedNames)));
106106
}
107107

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public boolean matches(Class<?> candidate) {
4646
}
4747

4848
@Override
49-
public boolean equals(@Nullable Object obj) {
50-
return (this == obj || (obj instanceof RootClassFilter that &&
49+
public boolean equals(@Nullable Object other) {
50+
return (this == other || (other instanceof RootClassFilter that &&
5151
this.clazz.equals(that.clazz)));
5252
}
5353

spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,8 @@ public int getCount() {
4747

4848

4949
@Override
50-
public boolean equals(@Nullable Object obj) {
51-
if (this == obj) {
52-
return true;
53-
}
54-
if (!(obj instanceof NopInterceptor that)) {
55-
return false;
56-
}
57-
return this.count == that.count;
50+
public boolean equals(@Nullable Object other) {
51+
return (this == other || (other instanceof NopInterceptor that && this.count == that.count));
5852
}
5953

6054
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
338338
}
339339

340340
@Override
341-
public boolean equals(@Nullable Object obj) {
342-
return (this == obj || (obj instanceof PropertyDescriptor that &&
341+
public boolean equals(@Nullable Object other) {
342+
return (this == other || (other instanceof PropertyDescriptor that &&
343343
PropertyDescriptorUtils.equals(this, that)));
344344
}
345345

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ public boolean isConverted() {
366366

367367

368368
@Override
369-
public boolean equals(@Nullable Object obj) {
370-
return (this == obj || (obj instanceof MutablePropertyValues that &&
369+
public boolean equals(@Nullable Object other) {
370+
return (this == other || (other instanceof MutablePropertyValues that &&
371371
this.propertyValueList.equals(that.propertyValueList)));
372372
}
373373

spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -52,8 +52,8 @@ private Object readResolve() {
5252

5353

5454
@Override
55-
public boolean equals(@Nullable Object obj) {
56-
return (this == obj);
55+
public boolean equals(@Nullable Object other) {
56+
return (this == other);
5757
}
5858

5959
@Override

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public String getDescription() {
8181
* This implementation compares the underlying BeanDefinition.
8282
*/
8383
@Override
84-
public boolean equals(@Nullable Object obj) {
85-
return (this == obj || (obj instanceof BeanDefinitionResource that &&
84+
public boolean equals(@Nullable Object other) {
85+
return (this == other || (other instanceof BeanDefinitionResource that &&
8686
this.beanDefinition.equals(that.beanDefinition)));
8787
}
8888

spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -40,8 +40,8 @@ final class NullBean {
4040

4141

4242
@Override
43-
public boolean equals(@Nullable Object obj) {
44-
return (this == obj || obj == null);
43+
public boolean equals(@Nullable Object other) {
44+
return (this == other || other == null);
4545
}
4646

4747
@Override

spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ public SimpleKey(Object... elements) {
6161

6262

6363
@Override
64-
public boolean equals(@Nullable Object obj) {
65-
return (this == obj ||
66-
(obj instanceof SimpleKey that && Arrays.deepEquals(this.params, that.params)));
64+
public boolean equals(@Nullable Object other) {
65+
return (this == other || (other instanceof SimpleKey that && Arrays.deepEquals(this.params, that.params)));
6766
}
6867

6968
@Override

spring-context/src/main/java/org/springframework/cache/support/NullValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -50,8 +50,8 @@ private Object readResolve() {
5050

5151

5252
@Override
53-
public boolean equals(@Nullable Object obj) {
54-
return (this == obj || obj == null);
53+
public boolean equals(@Nullable Object other) {
54+
return (this == other || other == null);
5555
}
5656

5757
@Override

spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ final class BeanMethod extends ConfigurationMethod {
3939
super(metadata, configurationClass);
4040
}
4141

42+
4243
@Override
4344
public void validate(ProblemReporter problemReporter) {
4445
if (getMetadata().isStatic()) {
@@ -55,9 +56,8 @@ public void validate(ProblemReporter problemReporter) {
5556
}
5657

5758
@Override
58-
public boolean equals(@Nullable Object obj) {
59-
return (this == obj ||
60-
(obj instanceof BeanMethod that && this.metadata.equals(that.metadata)));
59+
public boolean equals(@Nullable Object other) {
60+
return (this == other || (other instanceof BeanMethod that && this.metadata.equals(that.metadata)));
6161
}
6262

6363
@Override
@@ -70,6 +70,7 @@ public String toString() {
7070
return "BeanMethod: " + this.metadata;
7171
}
7272

73+
7374
private class NonOverridableMethodError extends Problem {
7475

7576
NonOverridableMethodError() {

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ void validate(ProblemReporter problemReporter) {
237237
}
238238

239239
@Override
240-
public boolean equals(@Nullable Object obj) {
241-
return (this == obj || (obj instanceof ConfigurationClass that &&
240+
public boolean equals(@Nullable Object other) {
241+
return (this == other || (other instanceof ConfigurationClass that &&
242242
getMetadata().getClassName().equals(that.getMetadata().getClassName())));
243243
}
244244

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ public Set<ConfigurationClass> getConfigurationClasses() {
211211
}
212212

213213
List<PropertySourceDescriptor> getPropertySourceDescriptors() {
214-
return (this.propertySourceRegistry != null ? this.propertySourceRegistry.getDescriptors()
215-
: Collections.emptyList());
214+
return (this.propertySourceRegistry != null ? this.propertySourceRegistry.getDescriptors() :
215+
Collections.emptyList());
216216
}
217217

218218
protected void processConfigurationClass(ConfigurationClass configClass, Predicate<String> filter) throws IOException {
@@ -1005,8 +1005,8 @@ private SourceClass getRelated(String className) throws IOException {
10051005
}
10061006

10071007
@Override
1008-
public boolean equals(@Nullable Object obj) {
1009-
return (this == obj || (obj instanceof SourceClass that &&
1008+
public boolean equals(@Nullable Object other) {
1009+
return (this == other || (other instanceof SourceClass that &&
10101010
this.metadata.getClassName().equals(that.metadata.getClassName())));
10111011
}
10121012

spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static ClassFiles of(ClassFile... ClassFiles) {
6161
return none().and(ClassFiles);
6262
}
6363

64+
6465
/**
6566
* Return a new {@link ClassFiles} instance that merges classes from
6667
* another array of {@link ClassFile} instances.
@@ -116,15 +117,10 @@ public ClassFile get(String name) {
116117
return this.files.get(name);
117118
}
118119

120+
119121
@Override
120-
public boolean equals(@Nullable Object obj) {
121-
if (this == obj) {
122-
return true;
123-
}
124-
if (obj == null || getClass() != obj.getClass()) {
125-
return false;
126-
}
127-
return this.files.equals(((ClassFiles) obj).files);
122+
public boolean equals(@Nullable Object other) {
123+
return (this == other || (other instanceof ClassFiles that && this.files.equals(that.files)));
128124
}
129125

130126
@Override

spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.IOException;
2020
import java.nio.charset.StandardCharsets;
21-
import java.util.Objects;
2221

2322
import org.springframework.lang.Nullable;
2423
import org.springframework.util.Assert;
@@ -81,22 +80,16 @@ public String getPath() {
8180
return this.path;
8281
}
8382

83+
8484
@Override
85-
public boolean equals(@Nullable Object obj) {
86-
if (this == obj) {
87-
return true;
88-
}
89-
if (obj == null || getClass() != obj.getClass()) {
90-
return false;
91-
}
92-
DynamicFile other = (DynamicFile) obj;
93-
return Objects.equals(this.path, other.path)
94-
&& Objects.equals(this.content, other.content);
85+
public boolean equals(@Nullable Object other) {
86+
return (this == other || (other instanceof DynamicFile that &&
87+
this.path.equals(that.path) && this.content.equals(that.content)));
9588
}
9689

9790
@Override
9891
public int hashCode() {
99-
return Objects.hash(this.path, this.content);
92+
return this.path.hashCode();
10093
}
10194

10295
@Override

spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ final class DynamicFiles<F extends DynamicFile> implements Iterable<F> {
3939

4040
private static final DynamicFiles<?> NONE = new DynamicFiles<>(Collections.emptyMap());
4141

42-
4342
private final Map<String, F> files;
4443

4544

@@ -101,15 +100,10 @@ F getSingle(Predicate<F> filter) {
101100
return files.iterator().next();
102101
}
103102

103+
104104
@Override
105-
public boolean equals(@Nullable Object obj) {
106-
if (this == obj) {
107-
return true;
108-
}
109-
if (obj == null || getClass() != obj.getClass()) {
110-
return false;
111-
}
112-
return this.files.equals(((DynamicFiles<?>) obj).files);
105+
public boolean equals(@Nullable Object other) {
106+
return (this == other || (other instanceof DynamicFiles<?> that && this.files.equals(that.files)));
113107
}
114108

115109
@Override

spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,10 @@ public ResourceFile getSingle() throws IllegalStateException {
130130
return this.files.getSingle();
131131
}
132132

133+
133134
@Override
134-
public boolean equals(@Nullable Object obj) {
135-
if (this == obj) {
136-
return true;
137-
}
138-
if (obj == null || getClass() != obj.getClass()) {
139-
return false;
140-
}
141-
return this.files.equals(((ResourceFiles) obj).files);
135+
public boolean equals(@Nullable Object other) {
136+
return (this == other || (other instanceof ResourceFiles that && this.files.equals(that.files)));
142137
}
143138

144139
@Override

spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.core.test.tools;
1818

1919
import java.util.Iterator;
20-
import java.util.Objects;
2120
import java.util.regex.Pattern;
2221
import java.util.stream.Stream;
2322

@@ -155,19 +154,14 @@ private SourceFile getSingle(Pattern pattern) {
155154
* one file
156155
*/
157156
public SourceFile getSingleFromPackage(String packageName) {
158-
return this.files.getSingle(candidate -> Objects.equals(packageName,
159-
ClassUtils.getPackageName(candidate.getClassName())));
157+
return this.files.getSingle(candidate ->
158+
ClassUtils.getPackageName(candidate.getClassName()).equals(packageName));
160159
}
161160

161+
162162
@Override
163-
public boolean equals(@Nullable Object obj) {
164-
if (this == obj) {
165-
return true;
166-
}
167-
if (obj == null || getClass() != obj.getClass()) {
168-
return false;
169-
}
170-
return this.files.equals(((SourceFiles) obj).files);
163+
public boolean equals(@Nullable Object other) {
164+
return (this == other || (other instanceof SourceFiles that && this.files.equals(that.files)));
171165
}
172166

173167
@Override

0 commit comments

Comments
 (0)