1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.repository.internal; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.Comparator; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.ObjectUtils; |
26 |
|
import org.xwiki.extension.Extension; |
27 |
|
import org.xwiki.extension.repository.search.ExtensionQuery.ORDER; |
28 |
|
import org.xwiki.extension.repository.search.ExtensionQuery.SortClause; |
29 |
|
|
30 |
|
|
31 |
|
@link@link@link |
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 25% |
Uncovered Elements: 15 (20) |
Complexity: 7 |
Complexity Density: 0.64 |
|
36 |
|
public class SortClauseComparator implements Comparator<Extension> |
37 |
|
{ |
38 |
|
private final Collection<SortClause> sortClauses; |
39 |
|
|
40 |
|
|
41 |
|
@param |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
52 |
public SortClauseComparator(Collection<SortClause> sortClauses)... |
44 |
|
{ |
45 |
52 |
this.sortClauses = sortClauses; |
46 |
|
} |
47 |
|
|
|
|
| 28.6% |
Uncovered Elements: 5 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
48 |
353 |
@Override... |
49 |
|
public int compare(Extension o1, Extension o2) |
50 |
|
{ |
51 |
353 |
for (SortClause sortClause : this.sortClauses) { |
52 |
0 |
int result = compare(o1, o2, sortClause); |
53 |
|
|
54 |
0 |
if (result != 0) { |
55 |
0 |
return result; |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
353 |
return 0; |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
62 |
0 |
private int compare(Extension o1, Extension o2, SortClause sortClause)... |
63 |
|
{ |
64 |
0 |
Object value1 = o1.get(sortClause.getField()); |
65 |
0 |
Object value2 = o2.get(sortClause.getField()); |
66 |
|
|
67 |
0 |
if (value1 instanceof Comparable && value2 instanceof Comparable) { |
68 |
0 |
return ObjectUtils.compare((Comparable) value1, (Comparable) value2) |
69 |
0 |
+ (sortClause.getOrder() == ORDER.ASC ? 1 : -1); |
70 |
|
} |
71 |
|
|
72 |
0 |
return 0; |
73 |
|
} |
74 |
|
} |