split renderers into separate classes

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@639 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-08-07 13:56:59 +00:00
parent d186cc65d1
commit 89e8b4f11f
4 changed files with 45 additions and 24 deletions

View File

@ -143,17 +143,8 @@ public class CPD {
cpd.setMinimumTileSize(26);
cpd.go();
System.out.println((System.currentTimeMillis() - start));
Results results = cpd.getResults();
for (Iterator i = results.getTiles(); i.hasNext();) {
Tile tile = (Tile)i.next();
System.out.println("=============================================================");
System.out.println("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
TokenEntry tok = (TokenEntry)j.next();
System.out.println(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
}
System.out.println(cpd.getImage(tile));
}
CPDRenderer renderer = new TextRenderer();
System.out.println(renderer.render(cpd));
}
}

View File

@ -0,0 +1,10 @@
/*
* User: tom
* Date: Aug 7, 2002
* Time: 9:44:21 AM
*/
package net.sourceforge.pmd.cpd;
public interface CPDRenderer {
public String render(CPD cpd);
}

View File

@ -43,9 +43,8 @@ public class GUI implements CPDListener {
private JTextField expandingTileField = new JTextField(50);
private JCheckBox recurseCheckbox = new JCheckBox("Recurse?", true);
private JFrame f;
public GUI() {
f = new JFrame("PMD Cut and Paste Detector");
JFrame f = new JFrame("PMD Cut and Paste Detector");
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(4,2));
inputPanel.add(new JLabel("Enter a root src directory"));
@ -98,17 +97,8 @@ public class GUI implements CPDListener {
cpd.addAllInDirectory(rootDirectoryField.getText());
}
cpd.go();
Results results = cpd.getResults();
for (Iterator i = results.getTiles(); i.hasNext();) {
Tile tile = (Tile)i.next();
System.out.println("=============================================================");
System.out.println("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
TokenEntry tok = (TokenEntry)j.next();
System.out.println(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
}
System.out.println(cpd.getImage(tile));
}
CPDRenderer renderer = new TextRenderer();
System.out.println(renderer.render(cpd));
} catch (IOException ioe) {
ioe.printStackTrace();
}

View File

@ -0,0 +1,30 @@
/*
* User: tom
* Date: Aug 7, 2002
* Time: 9:44:40 AM
*/
package net.sourceforge.pmd.cpd;
import java.util.Iterator;
public class TextRenderer implements CPDRenderer {
public String render(CPD cpd) {
Results results = cpd.getResults();
StringBuffer sb = new StringBuffer();
for (Iterator i = results.getTiles(); i.hasNext();) {
Tile tile = (Tile)i.next();
sb.append("=============================================================");
sb.append(System.getProperty("line.separator"));
sb.append("A " + cpd.getLineCountFor(tile) + " line (" + tile.getTokenCount() + " tokens) duplication in these files:");
sb.append(System.getProperty("line.separator"));
for (Iterator j = cpd.getResults().getOccurrences(tile); j.hasNext();) {
TokenEntry tok = (TokenEntry)j.next();
sb.append(tok.getBeginLine() + "\t" + tok.getTokenSrcID());
sb.append(System.getProperty("line.separator"));
}
sb.append(cpd.getImage(tile));
sb.append(System.getProperty("line.separator"));
}
return sb.toString();
}
}