View Javadoc

    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;
    9
    10
    11  public class CSVRenderer implements Renderer {
    12
    13  	private char separator;
    14
    15  	public static final char DEFAULT_SEPARATOR = ',';
    16
    17  	public CSVRenderer() {
    18  		this(DEFAULT_SEPARATOR);
    19  	}
    20
    21  	public CSVRenderer(char separatorChar) {
    22  		separator = separatorChar;
    23  	}
    24
    25      public String render(Iterator<Match> matches) {
    26          StringBuilder rpt = new StringBuilder(1000);
    27          rpt.append("lines").append(separator);
    28          rpt.append("tokens").append(separator);
    29          rpt.append("occurrences");
    30          rpt.append(PMD.EOL);
    31
    32          while (matches.hasNext()) {
    33              Match match = matches.next();
    34              rpt.append(match.getLineCount()).append(separator);
    35              rpt.append(match.getTokenCount()).append(separator);
    36              rpt.append(match.getMarkCount()).append(separator);
    37              for (Iterator<TokenEntry> marks = match.iterator(); marks.hasNext();) {
    38                  TokenEntry mark = marks.next();
    39                  rpt.append(mark.getBeginLine()).append(separator);
    40                  rpt.append(mark.getTokenSrcID());
    41                  if (marks.hasNext()) {
    42                      rpt.append(separator);
    43                  }
    44              }
    45              rpt.append(PMD.EOL);
    46          }
    47          return rpt.toString();
    48      }
    49  }