001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023: package org.hammurapi.results.persistent.jdbc;
024:
025: import java.sql.PreparedStatement;
026: import java.sql.SQLException;
027: import java.text.MessageFormat;
028: import java.util.Date;
029:
030: import org.hammurapi.results.persistent.jdbc.sql.BasicResultTotal;
031: import org.hammurapi.results.simple.SimpleAggregatedResults;
032:
033: import com.pavelvlasov.sql.Parameterizer;
034:
035: /**
036: * @author Pavel Vlasov
037: *
038: * @version $Revision: 1.5 $
039: */
040: public class BasicResults implements org.hammurapi.results.BasicResults {
041:
042: public Number getMaxSeverity() {
043: return maxSeverity;
044: }
045:
046: protected Parameterizer idParameterizer = new Parameterizer() {
047: public void parameterize(PreparedStatement ps)
048: throws SQLException {
049: ps.setInt(1, getId());
050: }
051: };
052:
053: public String getSigma() {
054: double p = 1.0 - violationLevel / reviews;
055: if (reviews == 0) {
056: return "No results";
057: } else if (p <= 0) {
058: return "Full incompliance";
059: } else if (p >= 1) {
060: return "Full compliance";
061: } else {
062: return MessageFormat.format("{0,number,#.###}",
063: new Object[] { new Double(SimpleAggregatedResults
064: .normsinv(p) + 1.5) })
065: + (hasWarnings() ? " (not accurate because of warnings)"
066: : "");
067: }
068: }
069:
070: public String getDPMO() {
071: if (reviews == 0) {
072: return "Not available, no reviews";
073: }
074:
075: return String
076: .valueOf((int) (1000000 * violationLevel / reviews))
077: + (hasWarnings() ? " (not accurate because of warnings)"
078: : "");
079: }
080:
081: public boolean hasWarnings() {
082: return hasWarnings;
083: }
084:
085: public int getWaivedViolationsNumber() {
086: return waivedViolationsNumber;
087: }
088:
089: public Date getDate() {
090: return date;
091: }
092:
093: protected Date date = new Date();
094:
095: public int getViolationsNumber() {
096: return violationsNumber;
097: }
098:
099: public long getCodeBase() {
100: return codeBase;
101: }
102:
103: public long getReviewsNumber() {
104: return reviews;
105: }
106:
107: public double getViolationLevel() {
108: return violationLevel;
109: }
110:
111: protected int getId() {
112: return id;
113: }
114:
115: protected int id;
116: protected ResultsFactory factory;
117: protected boolean hasWarnings = false;
118: protected Number maxSeverity;
119: protected int waivedViolationsNumber = 0;
120: protected int violationsNumber = 0;
121: protected double violationLevel = 0;
122: protected long reviews = 0;
123: protected long codeBase = 0;
124:
125: protected BasicResults(ResultsFactory factory) {
126: this .factory = factory;
127: }
128:
129: public BasicResults(int id, ResultsFactory factory)
130: throws SQLException {
131: this (factory);
132: this .id = id;
133: factory.addToCache(this );
134: BasicResultTotal data = factory.getResultsEngine()
135: .getBasicResultTotal(id);
136: codeBase = data.getCodebase();
137: date = data.getResultDate();
138: reviews = data.getReviews();
139: violationLevel = data.getViolationLevel();
140: violationsNumber = (int) data.getViolations();
141: waivedViolationsNumber = (int) data.getWaivedViolations();
142: maxSeverity = data.getMaxSeverity();
143: hasWarnings = data.getHasWarnings() > 0;
144: }
145:
146: }
|