This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 27bfee2 Trivial refactoring: extract common method
27bfee2 is described below
commit 27bfee283cd1a3cbc161f0e481570a9cd8da07bd
Author: Daniel Sun <[email protected]>
AuthorDate: Mon Dec 28 18:43:48 2020 +0800
Trivial refactoring: extract common method
---
.../collection/runtime/QueryableCollection.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
index 73130d7..749fa22 100644
---
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
+++
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
@@ -228,10 +228,18 @@ class QueryableCollection<T> implements Queryable<T>,
Serializable {
@Override
public <U extends Comparable<? super U>> Queryable<T> orderBy(Order<?
super T, ? extends U>... orders) {
- if (null == orders || 0 == orders.length) {
+ Comparator<T> comparator = makeComparator(orders);
+ if (null == comparator) {
return this;
}
+ return from(this.stream().sorted(comparator));
+ }
+
+ protected <U extends Comparable<? super U>> Comparator<T>
makeComparator(Order<? super T, ? extends U>... orders) {
+ if (null == orders || 0 == orders.length) {
+ return null;
+ }
Comparator<T> comparator = null;
for (int i = 0, n = orders.length; i < n; i++) {
Order<? super T, ? extends U> order = orders[i];
@@ -241,12 +249,7 @@ class QueryableCollection<T> implements Queryable<T>,
Serializable {
? Comparator.comparing(order.getKeyExtractor(),
ascOrDesc)
:
comparator.thenComparing(order.getKeyExtractor(), ascOrDesc);
}
-
- if (null == comparator) {
- return this;
- }
-
- return from(this.stream().sorted(comparator));
+ return comparator;
}
@Override