KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > results > persistent > jdbc > BasicResults


1 /*
2   * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22   */

23 package org.hammurapi.results.persistent.jdbc;
24
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.SQLException JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.Date JavaDoc;
29
30 import org.hammurapi.results.persistent.jdbc.sql.BasicResultTotal;
31 import org.hammurapi.results.simple.SimpleAggregatedResults;
32
33 import com.pavelvlasov.sql.Parameterizer;
34
35
36 /**
37  * @author Pavel Vlasov
38  *
39  * @version $Revision: 1.5 $
40  */

41 public class BasicResults implements org.hammurapi.results.BasicResults {
42
43     public Number JavaDoc getMaxSeverity() {
44         return maxSeverity;
45     }
46
47     protected Parameterizer idParameterizer = new Parameterizer() {
48                 public void parameterize(PreparedStatement JavaDoc ps) throws SQLException JavaDoc {
49                     ps.setInt(1, getId());
50                 }
51             };
52
53     public String JavaDoc getSigma() {
54         double p=1.0-violationLevel/reviews;
55         if (reviews==0) {
56             return "No results";
57         } else if (p<=0) {
58             return "Full incompliance";
59         } else if (p>=1) {
60             return "Full compliance";
61         } else {
62             return MessageFormat.format("{0,number,#.###}", new Object JavaDoc[] {new Double JavaDoc(SimpleAggregatedResults.normsinv(p)+1.5)}) + (hasWarnings() ? " (not accurate because of warnings)" : "");
63         }
64     }
65
66     public String JavaDoc getDPMO() {
67         if (reviews==0) {
68             return "Not available, no reviews";
69         }
70         
71         return String.valueOf((int) (1000000*violationLevel/reviews)) + (hasWarnings() ? " (not accurate because of warnings)" : "");
72     }
73
74     public boolean hasWarnings() {
75         return hasWarnings;
76     }
77
78     public int getWaivedViolationsNumber() {
79         return waivedViolationsNumber;
80     }
81
82     public Date JavaDoc getDate() {
83         return date;
84     }
85
86     protected Date JavaDoc date = new Date JavaDoc();
87
88     public int getViolationsNumber() {
89         return violationsNumber;
90     }
91
92     public long getCodeBase() {
93         return codeBase;
94     }
95
96     public long getReviewsNumber() {
97         return reviews;
98     }
99
100     public double getViolationLevel() {
101         return violationLevel;
102     }
103
104     protected int getId() {
105         return id;
106     }
107
108     protected int id;
109     protected ResultsFactory factory;
110     protected boolean hasWarnings = false;
111     protected Number JavaDoc maxSeverity;
112     protected int waivedViolationsNumber = 0;
113     protected int violationsNumber = 0;
114     protected double violationLevel = 0;
115     protected long reviews = 0;
116     protected long codeBase = 0;
117     
118     protected BasicResults(ResultsFactory factory) {
119         this.factory=factory;
120     }
121
122     public BasicResults(int id, ResultsFactory factory) throws SQLException JavaDoc {
123         this(factory);
124         this.id=id;
125         factory.addToCache(this);
126         BasicResultTotal data = factory.getResultsEngine().getBasicResultTotal(id);
127         codeBase=data.getCodebase();
128         date=data.getResultDate();
129         reviews=data.getReviews();
130         violationLevel=data.getViolationLevel();
131         violationsNumber=(int) data.getViolations();
132         waivedViolationsNumber=(int) data.getWaivedViolations();
133         maxSeverity=data.getMaxSeverity();
134         hasWarnings=data.getHasWarnings()>0;
135     }
136     
137 }
138
Popular Tags