001: package org.acm.seguin.pmd;
002:
003: import org.acm.seguin.pmd.stat.Metric;
004:
005: import java.util.ArrayList;
006: import java.util.HashSet;
007: import java.util.Iterator;
008: import java.util.List;
009: import java.util.Set;
010: import java.util.TreeSet;
011:
012: public class Report {
013:
014: public static class ProcessingError {
015: private String msg;
016: private String file;
017:
018: public ProcessingError(String msg, String file) {
019: this .msg = msg;
020: this .file = file;
021: }
022:
023: public String getMsg() {
024: return msg;
025: }
026:
027: public String getFile() {
028: return file;
029: }
030: }
031:
032: private Set violations = new TreeSet(
033: new RuleViolation.RuleViolationComparator());
034: private Set metrics = new HashSet();
035: private List listeners = new ArrayList();
036: private List errors = new ArrayList();
037:
038: public void addListener(ReportListener listener) {
039: listeners.add(listener);
040: }
041:
042: public void addRuleViolation(RuleViolation violation) {
043: violations.add(violation);
044: for (Iterator i = listeners.iterator(); i.hasNext();) {
045: ReportListener listener = (ReportListener) i.next();
046: listener.ruleViolationAdded(violation);
047: }
048: }
049:
050: public void addMetric(Metric metric) {
051: metrics.add(metric);
052: for (Iterator i = listeners.iterator(); i.hasNext();) {
053: ReportListener listener = (ReportListener) i.next();
054: listener.metricAdded(metric);
055: }
056: }
057:
058: public void addError(ProcessingError error) {
059: errors.add(error);
060: }
061:
062: public boolean hasMetrics() {
063: return !metrics.isEmpty();
064: }
065:
066: public Iterator metrics() {
067: return metrics.iterator();
068: }
069:
070: public boolean isEmpty() {
071: return violations.isEmpty();
072: }
073:
074: public Iterator iterator() {
075: return violations.iterator();
076: }
077:
078: public Iterator errors() {
079: return errors.iterator();
080: }
081:
082: public int size() {
083: return violations.size();
084: }
085:
086: public String toString() {
087: //throw new RuntimeException("toString()");
088: StringBuffer sb = new StringBuffer("Violations={");
089: Iterator i = iterator();
090: while (i.hasNext()) {
091: sb.append(i.next()).append(",");
092: }
093: sb.append("}\r\nErrors={");
094: i = errors();
095: while (i.hasNext()) {
096: sb.append(i.next()).append(",");
097: }
098: sb.append("}");
099: return sb.toString();
100: }
101: }
|