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 net.sourceforge.pmd.Rule;
7   
8   import java.util.Random;
9   
10  /***
11   * @author David Dixon-Peugh
12   * Aug 8, 2002 DataPoint.java
13   */
14  public class DataPoint implements java.lang.Comparable {
15      private int lineNumber;
16      private int random;
17      private double score;
18      private String message;
19      private Rule rule;
20  
21      /***
22       * Constructor for DataPoint.
23       */
24      public DataPoint() {
25          super();
26          // Random number is so that the TreeSet doesn't
27          // whack things with the same score.
28          Random rand = new Random();
29          random = rand.nextInt(11061973);
30      }
31  
32      public int compareTo(Object object) {
33  
34          DataPoint rhs = (DataPoint) object;
35  
36          Double lhsScore = new Double(score);
37          Double rhsScore = new Double(rhs.getScore());
38  
39          if (lhsScore.doubleValue() != rhsScore.doubleValue()) {
40              return lhsScore.compareTo(rhsScore);
41          }
42  
43          Integer lhsRand = new Integer(random);
44          Integer rhsRand = new Integer(rhs.random);
45  
46          return lhsRand.compareTo(rhsRand);
47      }
48  
49      /***
50       * Returns the lineNumber.
51       * @return int
52       */
53      public int getLineNumber() {
54          return lineNumber;
55      }
56  
57      /***
58       * Sets the lineNumber.
59       * @param lineNumber The lineNumber to set
60       */
61      public void setLineNumber(int lineNumber) {
62          this.lineNumber = lineNumber;
63      }
64  
65      /***
66       * Returns the message.
67       * @return String
68       */
69      public String getMessage() {
70          return message;
71      }
72  
73      /***
74       * Returns the rule.
75       * @return Rule
76       */
77      public Rule getRule() {
78          return rule;
79      }
80  
81      /***
82       * Sets the message.
83       * @param message The message to set
84       */
85      public void setMessage(String message) {
86          this.message = message;
87      }
88  
89      /***
90       * Sets the rule.
91       * @param rule The rule to set
92       */
93      public void setRule(Rule rule) {
94          this.rule = rule;
95      }
96  
97      /***
98       * Returns the score.
99       * @return double
100      */
101     public double getScore() {
102         return score;
103     }
104 
105     /***
106      * Sets the score.
107      * @param score The score to set
108      */
109     public void setScore(double score) {
110         this.score = score;
111     }
112 
113     /***
114      * Sets the score.
115      * @param score The score to set
116      */
117     public void setScore(int score) {
118         this.score = (double) score;
119     }
120 
121 }