File tree 2 files changed +20
-6
lines changed
main/java/org/springframework/data/domain
test/java/org/springframework/data/domain
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import org .springframework .data .domain .Limit .Limited ;
19
19
import org .springframework .data .domain .Limit .Unlimited ;
20
- import org .springframework .util . ClassUtils ;
20
+ import org .springframework .lang . Nullable ;
21
21
22
22
/**
23
23
* {@link Limit} represents the maximum value up to which an operation should continue processing. It may be used for
@@ -94,14 +94,17 @@ public boolean equals(Object obj) {
94
94
if (obj == null ) {
95
95
return false ;
96
96
}
97
- if (!ClassUtils .isAssignable (Limit .class , obj .getClass ())) {
97
+
98
+ if (!(obj instanceof Limit that )) {
98
99
return false ;
99
100
}
100
- Limit that = ( Limit ) obj ;
101
- if (this .isUnlimited () && that .isUnlimited ()) {
102
- return true ;
101
+
102
+ if (this .isUnlimited () ^ that .isUnlimited ()) {
103
+ return false ;
103
104
}
104
- return max () == that .max ();
105
+
106
+ return this .isUnlimited () && that .isUnlimited ()
107
+ || max () == that .max ();
105
108
}
106
109
107
110
@ Override
Original file line number Diff line number Diff line change @@ -55,4 +55,15 @@ void isUnlimitedReturnsFalseIfLimited(int value) {
55
55
void unlimitedErrorsOnMax () {
56
56
assertThatExceptionOfType (IllegalStateException .class ).isThrownBy (() -> Limit .unlimited ().max ());
57
57
}
58
+
59
+ @ Test // GH-3023
60
+ void equalsProperly () {
61
+
62
+ Limit unlimited = Limit .unlimited ();
63
+ Limit limited = Limit .of (5 );
64
+
65
+ assertThat (limited .equals (unlimited )).isFalse ();
66
+ assertThat (unlimited .equals (limited )).isFalse ();
67
+ assertThat (unlimited .equals (unlimited )).isTrue ();
68
+ }
58
69
}
You can’t perform that action at this time.
0 commit comments