Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 208   Methods: 25
NCLOC: 161   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
Report.java 76.9% 75.7% 72% 75.2%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd;
 5   
 6    import net.sourceforge.pmd.dfa.report.ReportTree;
 7    import net.sourceforge.pmd.stat.Metric;
 8   
 9    import java.util.ArrayList;
 10    import java.util.HashMap;
 11    import java.util.HashSet;
 12    import java.util.Iterator;
 13    import java.util.List;
 14    import java.util.Map;
 15    import java.util.Set;
 16    import java.util.TreeSet;
 17   
 18    public class Report {
 19   
 20    public static class ReadableDuration {
 21    private long duration;
 22  14 public ReadableDuration(long duration) {
 23  14 this.duration = duration;
 24    }
 25  14 public String getTime() {
 26  14 long seconds = 0;
 27  14 long minutes = 0;
 28  14 long hours = 0;
 29   
 30  14 if (duration > 1000) {
 31  4 seconds = duration / 1000;
 32    }
 33   
 34  14 if (seconds > 60) {
 35  3 minutes = seconds / 60;
 36  3 seconds = seconds % 60;
 37    }
 38   
 39  14 if (minutes > 60) {
 40  1 hours = minutes / 60;
 41  1 minutes = minutes % 60;
 42    }
 43   
 44  14 StringBuffer res = new StringBuffer();
 45  14 if (hours > 0) {
 46  1 res.append(hours + "h ");
 47    }
 48  14 if (hours > 0 || minutes > 0) {
 49  3 res.append(minutes + "m ");
 50    }
 51  14 res.append(seconds + "s");
 52  14 return res.toString();
 53    }
 54    }
 55   
 56    public static class ProcessingError {
 57    private String msg;
 58    private String file;
 59   
 60  1 public ProcessingError(String msg, String file) {
 61  1 this.msg = msg;
 62  1 this.file = file;
 63    }
 64   
 65  1 public String getMsg() {
 66  1 return msg;
 67    }
 68   
 69  1 public String getFile() {
 70  1 return file;
 71    }
 72    }
 73   
 74    /*
 75    * The idea is to store the violations in a tree instead of a list, to do
 76    * better and faster sort and filter mechanism and to visualize the result
 77    * als tree. (ide plugins).
 78    * */
 79    private ReportTree violationTree = new ReportTree();
 80   
 81    // Note that this and the above data structure are both being maintained for a bit
 82    private Set violations = new TreeSet(new RuleViolation.RuleViolationComparator());
 83    private Set metrics = new HashSet();
 84    private List listeners = new ArrayList();
 85    private List errors = new ArrayList();
 86    private Set linesToExclude = new HashSet();
 87    private long start;
 88    private long end;
 89   
 90  754 public void exclude(Set lines) {
 91  754 linesToExclude = lines;
 92    }
 93   
 94  0 public Map getCountSummary() {
 95  0 Map summary = new HashMap();
 96  0 for (Iterator iter = violationTree.iterator(); iter.hasNext();) {
 97  0 RuleViolation rv = (RuleViolation) iter.next();
 98  0 String key = (rv.getPackageName() == "" ? "" : (rv.getPackageName() + ".")) + rv.getClassName();
 99  0 Object o = summary.get(key);
 100  0 if (o == null) {
 101  0 Integer value = new Integer(1);
 102  0 summary.put(key, value);
 103    } else {
 104  0 Integer value = (Integer) o;
 105  0 summary.put(key, new Integer(value.intValue() + 1));
 106    }
 107    }
 108  0 return summary;
 109    }
 110   
 111  0 public ReportTree getViolationTree() {
 112  0 return this.violationTree;
 113    }
 114   
 115   
 116    /**
 117    * @return a Map summarizing the Report: String (rule name) ->Integer (count of violations)
 118    */
 119  1 public Map getSummary() {
 120  1 Map summary = new HashMap();
 121  1 for (Iterator i = violations.iterator(); i.hasNext();) {
 122  3 RuleViolation rv = (RuleViolation) i.next();
 123  3 if (!summary.containsKey(rv.getRule().getName())) {
 124  2 summary.put(rv.getRule().getName(), new Integer(0));
 125    }
 126  3 Integer count = (Integer) summary.get(rv.getRule().getName());
 127  3 count = new Integer(count.intValue() + 1);
 128  3 summary.put(rv.getRule().getName(), count);
 129    }
 130  1 return summary;
 131    }
 132   
 133  2 public void addListener(ReportListener listener) {
 134  2 listeners.add(listener);
 135    }
 136   
 137  3234 public void addRuleViolation(RuleViolation violation) {
 138  3234 if (linesToExclude.contains(new Integer(violation.getLine()))) {
 139  1 return;
 140    }
 141  3233 violations.add(violation);
 142  3233 violationTree.addRuleViolation(violation);
 143  3233 for (Iterator i = listeners.iterator(); i.hasNext();) {
 144  2 ReportListener listener = (ReportListener) i.next();
 145  2 listener.ruleViolationAdded(violation);
 146    }
 147    }
 148   
 149  177 public void addMetric(Metric metric) {
 150  177 metrics.add(metric);
 151  177 for (Iterator i = listeners.iterator(); i.hasNext();) {
 152  1 ReportListener listener = (ReportListener) i.next();
 153  1 listener.metricAdded(metric);
 154    }
 155    }
 156   
 157  1 public void addError(ProcessingError error) {
 158  1 errors.add(error);
 159    }
 160   
 161  3 public boolean hasMetrics() {
 162  3 return !metrics.isEmpty();
 163    }
 164   
 165  2 public Iterator metrics() {
 166  2 return metrics.iterator();
 167    }
 168   
 169  2 public boolean isEmpty() {
 170  2 return !violations.iterator().hasNext() && errors.isEmpty();
 171    }
 172   
 173  0 public boolean treeIsEmpty() {
 174  0 return !violationTree.iterator().hasNext();
 175    }
 176   
 177  0 public Iterator treeIterator() {
 178  0 return violationTree.iterator();
 179    }
 180   
 181  16 public Iterator iterator() {
 182  16 return violations.iterator();
 183    }
 184   
 185  9 public Iterator errors() {
 186  9 return errors.iterator();
 187    }
 188   
 189  0 public int treeSize() {
 190  0 return violationTree.size();
 191    }
 192   
 193  954 public int size() {
 194  954 return violations.size();
 195    }
 196   
 197  0 public void start() {
 198  0 start = System.currentTimeMillis();
 199    }
 200   
 201  0 public void end() {
 202  0 end = System.currentTimeMillis();
 203    }
 204   
 205  9 public long getElapsedTimeInMillis() {
 206  9 return end-start;
 207    }
 208    }