More minor refactoring
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1628 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -12,7 +12,7 @@ public class CPD {
|
||||
|
||||
private int minimumTileSize;
|
||||
private TokenSets tokenSets = new TokenSets();
|
||||
private MatchAlgorithm matchAlgorithm;
|
||||
private MatchAlgorithm matchAlgorithm = new MatchAlgorithm();
|
||||
private CPDListener listener = new CPDNullListener();
|
||||
|
||||
public CPD(int minimumTileSize) {
|
||||
@ -24,12 +24,11 @@ public class CPD {
|
||||
}
|
||||
|
||||
public void go() {
|
||||
matchAlgorithm = new MatchAlgorithm(listener);
|
||||
for (Iterator i = tokenSets.iterator(); i.hasNext();) {
|
||||
TokenList tl = (TokenList)i.next();
|
||||
for (Iterator j = tl.iterator();j.hasNext();) {
|
||||
TokenEntry te = (TokenEntry)j.next();
|
||||
matchAlgorithm.add(te, new Locator(te.getTokenSrcID(), te.getBeginLine(), te.getIndex()));
|
||||
matchAlgorithm.add(te, new Locator(te.getTokenSrcID(), te.getBeginLine(), te.getIndex()), listener);
|
||||
}
|
||||
}
|
||||
matchAlgorithm.findMatches(minimumTileSize);
|
||||
|
@ -10,40 +10,20 @@ import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MatchAlgorithm {
|
||||
// using a treemap means I don't actually sort my flyweight tokens.
|
||||
|
||||
private Map pool = new TreeMap();
|
||||
private List code = new ArrayList();
|
||||
private List marks = new ArrayList();
|
||||
// separate what the token is from where it is. Locator is only used if we need to see the code at that location.
|
||||
|
||||
private List matchesList = new ArrayList();
|
||||
private CPDListener cpdListener;
|
||||
|
||||
public MatchAlgorithm(CPDListener cpdListener) {
|
||||
this.cpdListener = cpdListener;
|
||||
}
|
||||
|
||||
public void add(TokenEntry token, Locator locator) {
|
||||
pool.put(token, token);
|
||||
public void add(TokenEntry token, Locator locator, CPDListener cpdListener) {
|
||||
if (!pool.containsKey(token)) {
|
||||
pool.put(token, token);
|
||||
}
|
||||
code.add(token);
|
||||
marks.add(new Mark(code, code.size(), locator, cpdListener));
|
||||
/*
|
||||
MyToken flyweight = (MyToken)pool.get(token);
|
||||
if (flyweight == null) {
|
||||
pool.put(token, token);
|
||||
flyweight = token;
|
||||
}
|
||||
code.add(flyweight);
|
||||
if (flyweight.isMarkToken()) {
|
||||
marks.add(new Mark(code, code.size(), locator));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
Should return something, or notify someone with locators - that
|
||||
kind of thing ;)
|
||||
*/
|
||||
public void findMatches(int min) {
|
||||
/*
|
||||
Assign sort codes to all the pooled code. This should speed
|
||||
@ -54,9 +34,8 @@ public class MatchAlgorithm {
|
||||
TokenEntry token = (TokenEntry)iter.next();
|
||||
token.setSortCode(count++);
|
||||
}
|
||||
// use quicksort on the marks, same as the perl version
|
||||
Collections.sort(marks);
|
||||
|
||||
Collections.sort(marks);
|
||||
|
||||
Set soFar = new HashSet();
|
||||
for (int i = 1; i < marks.size(); i++) {
|
||||
|
Reference in New Issue
Block a user