KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > cpd > CSVRenderer


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.cpd;
5
6 import net.sourceforge.pmd.PMD;
7
8 import java.util.Iterator JavaDoc;
9
10
11 public class CSVRenderer implements Renderer {
12
13     private char separator;
14     
15     public static final char defaultSeparator = ',';
16     
17     public CSVRenderer() {
18         this(defaultSeparator);
19     }
20     
21     public CSVRenderer(char separatorChar) {
22         separator = separatorChar;
23     }
24     
25     public String JavaDoc render(Iterator JavaDoc matches) {
26         StringBuffer JavaDoc rpt = new StringBuffer JavaDoc(1000);
27         rpt.append("lines").append(separator);
28         rpt.append("tokens").append(separator);
29         rpt.append("occurrences");
30         rpt.append(PMD.EOL);
31         
32         Match match;
33         TokenEntry mark;
34         
35         while (matches.hasNext()) {
36             match = (Match) matches.next();
37             rpt.append(match.getLineCount()).append(separator);
38             rpt.append(match.getTokenCount()).append(separator);
39             rpt.append(match.getMarkCount()).append(separator);
40             for (Iterator JavaDoc marks = match.iterator(); marks.hasNext();) {
41                 mark = (TokenEntry) marks.next();
42                 rpt.append(mark.getBeginLine()).append(separator);
43                 rpt.append(mark.getTokenSrcID());
44                 if (marks.hasNext()) {
45                     rpt.append(separator);
46                 }
47             }
48             rpt.append(PMD.EOL);
49         }
50         return rpt.toString();
51     }
52 }
Popular Tags