File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed
main/java/org/springframework/data/domain
test/java/org/springframework/data/domain Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 1717
1818import org .springframework .data .domain .Limit .Limited ;
1919import org .springframework .data .domain .Limit .Unlimited ;
20- import org .springframework .util . ClassUtils ;
20+ import org .springframework .lang . Nullable ;
2121
2222/**
2323 * {@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) {
9494 if (obj == null ) {
9595 return false ;
9696 }
97- if (!ClassUtils .isAssignable (Limit .class , obj .getClass ())) {
97+
98+ if (!(obj instanceof Limit that )) {
9899 return false ;
99100 }
100- Limit that = ( Limit ) obj ;
101- if (this .isUnlimited () && that .isUnlimited ()) {
102- return true ;
101+
102+ if (this .isUnlimited () ^ that .isUnlimited ()) {
103+ return false ;
103104 }
104- return max () == that .max ();
105+
106+ return this .isUnlimited () && that .isUnlimited ()
107+ || max () == that .max ();
105108 }
106109
107110 @ Override
Original file line number Diff line number Diff line change @@ -55,4 +55,15 @@ void isUnlimitedReturnsFalseIfLimited(int value) {
5555 void unlimitedErrorsOnMax () {
5656 assertThatExceptionOfType (IllegalStateException .class ).isThrownBy (() -> Limit .unlimited ().max ());
5757 }
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+ }
5869}
You can’t perform that action at this time.
0 commit comments