Clover Coverage Report - Maven Cloud Front Plugin 1.0.27
Coverage timestamp: Fri Apr 15 2011 13:39:31 EST
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
33   90   15   5.5
14   64   0.45   6
6     2.5  
1    
 
  DisplayRowComparator       Line # 13 33 0% 15 4 92.5% 0.9245283
 
  (9)
 
1    package org.kuali.maven.mojo.s3;
2   
3    import java.util.Comparator;
4   
5    import org.apache.commons.lang.StringUtils;
6   
7    /**
8    * Provide non-alphanumeric sorting for version numbers.
9    *
10    * 1.1.10 sorts after 1.1.2<br>
11    * 1.1.10-SNAPSHOT sorts before 1.1.10
12    */
 
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   
 
19  10 toggle @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   
 
62  17 toggle 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    // Intentionally ignore this
69    }
70  2 return token1.compareTo(token2);
71   
72    }
73   
 
74  1 toggle public String getSeparators() {
75  1 return separators;
76    }
77   
 
78  1 toggle public void setSeparators(String separators) {
79  1 this.separators = separators;
80    }
81   
 
82  0 toggle public String getDelimiter() {
83  0 return delimiter;
84    }
85   
 
86  0 toggle public void setDelimiter(String delimiter) {
87  0 this.delimiter = delimiter;
88    }
89   
90    }