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