Ordered stream access on ObjectProvider with strong order guarantees

Issue: SPR-17272
This commit is contained in:
Juergen Hoeller
2018-09-14 23:56:25 +02:00
parent 12240c7524
commit 41d4cb5cbf
6 changed files with 92 additions and 71 deletions

View File

@@ -59,7 +59,7 @@ public class OrderComparator implements Comparator<Object> {
* @return the adapted comparator
* @since 4.1
*/
public Comparator<Object> withSourceProvider(final OrderSourceProvider sourceProvider) {
public Comparator<Object> withSourceProvider(OrderSourceProvider sourceProvider) {
return (o1, o2) -> doCompare(o1, o2, sourceProvider);
}
@@ -78,10 +78,9 @@ public class OrderComparator implements Comparator<Object> {
return 1;
}
// Direct evaluation instead of Integer.compareTo to avoid unnecessary object creation.
int i1 = getOrder(o1, sourceProvider);
int i2 = getOrder(o2, sourceProvider);
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;
return Integer.compare(i1, i2);
}
/**