1 |
|
package org.kuali.maven.mojo.s3; |
2 |
|
|
3 |
|
import java.util.Comparator; |
4 |
|
|
5 |
|
import org.apache.commons.lang.StringUtils; |
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
|
|
| 92.5% |
Uncovered Elements: 4 (53) |
Complexity: 15 |
Complexity Density: 0.45 |
|
13 |
|
public class DisplayRowComparator implements Comparator<DisplayRow> { |
14 |
|
public static final String DEFAULT_SEPARATORS = ".-"; |
15 |
|
public static final String DEFAULT_DELIMITER = "/"; |
16 |
|
String separators = DEFAULT_SEPARATORS; |
17 |
|
String delimiter = DEFAULT_DELIMITER; |
18 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (38) |
Complexity: 9 |
Complexity Density: 0.38 |
|
19 |
10
|
@Override... |
20 |
|
public int compare(DisplayRow one, DisplayRow two) { |
21 |
10
|
String show1 = one.getShow(); |
22 |
10
|
String show2 = two.getShow(); |
23 |
|
|
24 |
10
|
if (show1 == null && show2 == null) { |
25 |
2
|
return 0; |
26 |
|
} |
27 |
|
|
28 |
8
|
if (show1 == null) { |
29 |
1
|
return -1; |
30 |
|
} |
31 |
|
|
32 |
7
|
if (show2 == null) { |
33 |
2
|
return 1; |
34 |
|
} |
35 |
|
|
36 |
5
|
show1 = StringUtils.strip(show1, delimiter); |
37 |
5
|
show2 = StringUtils.strip(show2, delimiter); |
38 |
|
|
39 |
5
|
String[] tokens1 = StringUtils.split(show1, separators); |
40 |
5
|
String[] tokens2 = StringUtils.split(show2, separators); |
41 |
|
|
42 |
5
|
int len = Math.min(tokens1.length, tokens2.length); |
43 |
|
|
44 |
20
|
for (int i = 0; i < len; i++) { |
45 |
17
|
String token1 = tokens1[i]; |
46 |
17
|
String token2 = tokens2[i]; |
47 |
17
|
int compareTo = compareTokens(token1, token2); |
48 |
17
|
if (compareTo != 0) { |
49 |
2
|
return compareTo; |
50 |
|
} |
51 |
|
} |
52 |
|
|
53 |
3
|
if (tokens1.length > tokens2.length) { |
54 |
1
|
return -1; |
55 |
2
|
} else if (tokens1.length < tokens2.length) { |
56 |
1
|
return 1; |
57 |
|
} else { |
58 |
1
|
return 0; |
59 |
|
} |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
62 |
17
|
protected int compareTokens(String token1, String token2) {... |
63 |
17
|
try { |
64 |
17
|
Double d1 = new Double(token1); |
65 |
15
|
Double d2 = new Double(token2); |
66 |
15
|
return d1.compareTo(d2); |
67 |
|
} catch (NumberFormatException e) { |
68 |
|
|
69 |
|
} |
70 |
2
|
return token1.compareTo(token2); |
71 |
|
|
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
74 |
1
|
public String getSeparators() {... |
75 |
1
|
return separators; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
1
|
public void setSeparators(String separators) {... |
79 |
1
|
this.separators = separators; |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0
|
public String getDelimiter() {... |
83 |
0
|
return delimiter; |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
public void setDelimiter(String delimiter) {... |
87 |
0
|
this.delimiter = delimiter; |
88 |
|
} |
89 |
|
|
90 |
|
} |