Skip to content

Commit f8f9610

Browse files
committed
Add equals/hashCode support for Unpaged.
Closes #3061
1 parent ee75b8c commit f8f9610

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/org/springframework/data/domain/Unpaged.java

+17
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,21 @@ public Pageable withPage(int pageNumber) {
8989

9090
throw new UnsupportedOperationException();
9191
}
92+
93+
@Override
94+
public boolean equals(Object o) {
95+
if (this == o) {
96+
return true;
97+
}
98+
if (!(o instanceof Unpaged unpaged)) {
99+
return false;
100+
}
101+
102+
return sort.equals(unpaged.sort);
103+
}
104+
105+
@Override
106+
public int hashCode() {
107+
return sort.hashCode();
108+
}
92109
}

src/test/java/org/springframework/data/domain/PageRequestUnitTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ void equalsRegardsSortCorrectly() {
5858

5959
// Is not equal to instance with another sort
6060
assertNotEqualsAndHashcode(request, PageRequest.of(1, 10, Direction.ASC, "foo"));
61+
62+
// Equaliity for unpaged
63+
assertEqualsAndHashcode(Pageable.unpaged(), Pageable.unpaged(Sort.unsorted()));
64+
65+
assertNotEqualsAndHashcode(Pageable.unpaged(), Pageable.unpaged(Sort.by("foo")));
6166
}
6267

6368
@Test // DATACMNS-1581

0 commit comments

Comments
 (0)