Allow combining Sort and TypedSort using Sort.and(…).

We now retain properly the collection of orders by using accessor methods instead of relying on using the orders field. TypedSort orders are not using the orders field, instead they iterate over recorded persistent property paths.

Closes #2103
Original pull request: #2377.
This commit is contained in:
Mark Paluch
2021-06-10 14:59:27 +02:00
parent f97b4b98ca
commit 9242b2c7b2
2 changed files with 18 additions and 5 deletions

View File

@@ -170,7 +170,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
}
public boolean isSorted() {
return !orders.isEmpty();
return !isEmpty();
}
public boolean isUnsorted() {
@@ -188,7 +188,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Assert.notNull(sort, "Sort must not be null!");
ArrayList<Order> these = new ArrayList<>(this.orders);
ArrayList<Order> these = new ArrayList<>(this.toList());
for (Order order : sort) {
these.add(order);
@@ -240,7 +240,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
Sort that = (Sort) obj;
return this.orders.equals(that.orders);
return toList().equals(that.toList());
}
/*
@@ -261,7 +261,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
*/
@Override
public String toString() {
return orders.isEmpty() ? "UNSORTED" : StringUtils.collectionToCommaDelimitedString(orders);
return isEmpty() ? "UNSORTED" : StringUtils.collectionToCommaDelimitedString(orders);
}
/**
@@ -272,7 +272,7 @@ public class Sort implements Streamable<org.springframework.data.domain.Sort.Ord
*/
private Sort withDirection(Direction direction) {
return Sort.by(orders.stream().map(it -> new Order(direction, it.getProperty())).collect(Collectors.toList()));
return Sort.by(stream().map(it -> new Order(direction, it.getProperty())).collect(Collectors.toList()));
}
/**