View Javadoc

1   // %583496668:hoplugins.teamAnalyzer.comparator%
2   package hoplugins.teamAnalyzer.comparator;
3   
4   import hoplugins.teamAnalyzer.report.Report;
5   
6   import java.util.Comparator;
7   
8   
9   /***
10   * Comparator that orders based on number of performanceand rating as secondary parameter
11   *
12   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
13   */
14  public class PerformanceComparator implements Comparator {
15      //~ Methods ------------------------------------------------------------------------------------
16  
17      /***
18       * Compare two objects
19       *
20       * @param o1
21       * @param o2
22       *
23       * @return
24       */
25      public int compare(Object o1, Object o2) {
26          int s1 = ((Report) o1).getAppearance();
27          int s2 = ((Report) o2).getAppearance();
28  
29          if (s1 > s2) {
30              return -1;
31          }
32  
33          if (s2 > s1) {
34              return 1;
35          }
36  
37          double n1 = ((Report) o1).getRating();
38          double n2 = ((Report) o2).getRating();
39  
40          if (n1 > n2) {
41              return -1;
42          }
43  
44          if (n2 > n1) {
45              return 1;
46          }
47  
48          return 1;
49      }
50  }