View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.stat;
5   
6   import java.util.Random;
7   
8   import net.sourceforge.pmd.lang.ast.Node;
9   import net.sourceforge.pmd.lang.java.rule.codesize.AbstractNcssCountRule;
10  
11  /**
12   * Datapoint used for rules that deal with metrics.
13   * @author David Dixon-Peugh
14   * @since Aug 8, 2002
15   * @see AbstractNcssCountRule
16   */
17  public class DataPoint implements Comparable<DataPoint> {
18  
19      private Node node;
20      private int random;
21      private double score;
22      private String message;
23  
24      /**
25       * Constructor for DataPoint.
26       */
27      public DataPoint() {
28          super();
29          // Random number is so that the TreeSet doesn't
30          // whack things with the same score.
31          Random rand = new Random();
32          random = rand.nextInt(11061973);
33      }
34  
35      /**
36       * Compares this data point with the given datapoint.
37       * @param rhs the other data point
38       * @return 0 if equal; a value less than 0 if this point's score is smaller than the other data point;
39       * a value greater than 0 if this point's score is greater than the other data point.
40       */
41      public int compareTo(DataPoint rhs) {
42          if (score != rhs.getScore()) {
43              return Double.compare(score, rhs.getScore());
44          }
45          return random - rhs.random;
46      }
47  
48      public Node getNode() {
49          return node;
50      }
51  
52      public void setNode(Node node) {
53          this.node = node;
54      }
55  
56      public String getMessage() {
57          return message;
58      }
59  
60      public void setMessage(String message) {
61          this.message = message;
62      }
63  
64      public double getScore() {
65          return score;
66      }
67  
68      public void setScore(double score) {
69          this.score = score;
70      }
71  }