diff --git a/src/main/java/edu/odu/cs/cs350/DupDetector.java b/src/main/java/edu/odu/cs/cs350/DupDetector.java index cbb7294..466fe39 100644 --- a/src/main/java/edu/odu/cs/cs350/DupDetector.java +++ b/src/main/java/edu/odu/cs/cs350/DupDetector.java @@ -1,6 +1,5 @@ package edu.odu.cs.cs350; -import java.io.FileNotFoundException; /** * DupDetector is the main class for the system. It will call * each subsystem of the program, passing input/output between @@ -9,44 +8,13 @@ public class DupDetector { public static void main(String args[]) throws Exception { - /** - * input file will be invoked using command line arguments - * args[0] is reserved for the number of suggestions the user wants to print - * args[1] is an optional input to load a properties file, if no properties - * file is loaded, it will set to default properties - * args[i] i will be any number of files supplied in the command line - */ - if (args.length == 0) { - System.err.println ("Usage: java -jar build/libs/DupDetector.jar " - + "[OPTIONAL] "); - System.exit(-1); - } - int nSuggestions = Integer.parseInt(args[0]); - if(args[1].endsWith(".ini")) { - for (int i = 2; i < args.length; i++) { - try { - String startDir = args[i]; - RecursiveSearch r = new RecursiveSearch(); - Output out = new Output(); - out.setFiles(r.searchWithProperties(startDir, args[1])); - System.out.println(out.getSectionOne()); - } catch(FileNotFoundException e) { - System.out.println(e.getMessage()); - } - } - } - else { - for (int i = 1; i < args.length; i++) { - try { - String startDir = args[i]; - RecursiveSearch r = new RecursiveSearch(); - Output out = new Output(); - out.setFiles(r.searchDirectory(startDir)); - System.out.println(out.getSectionOne()); - } catch(FileNotFoundException e) { - System.out.println(e.getMessage()); - } - } - } + Input input = new Input(args); + Recommender recommender = new Recommender(input.getTokens()); + Output output = new Output( + input.getNSuggestions(), + input.getFiles(), + recommender.getRefactorings() + ); + System.out.println(output.getCompleteOutput()); } } diff --git a/src/main/java/edu/odu/cs/cs350/Input.java b/src/main/java/edu/odu/cs/cs350/Input.java new file mode 100644 index 0000000..632ee3d --- /dev/null +++ b/src/main/java/edu/odu/cs/cs350/Input.java @@ -0,0 +1,82 @@ +package edu.odu.cs.cs350; + +import java.io.FileNotFoundException; +import java.io.File; +import java.util.*; + +/** + * Input file will be invoked using command line arguments. + * args[0] is reserved for the number of suggestions the user wants + * to print. + * args[1] is an optional input to load a properties file, if no + * properties file is loaded, it will set to default properties. + * args[i] i will be any number of files supplied in the command + * line. + */ +public class Input { + + private int nSuggestions; + private List files; + private List tokens; + + Input() { + this.nSuggestions = 0; + files = new ArrayList(); + tokens = new ArrayList(); + } + + Input(String args[]) throws Exception { + if (args.length == 0) { + System.err.println("Usage: java -jar build/libs/DupDetector.jar " + + "[OPTIONAL] "); + System.exit(-1); + } + + this.nSuggestions = Integer.parseInt(args[0]); + + if(args[1].endsWith(".ini")) { + for (int i = 2; i < args.length; i++) { + try { + String startDir = args[i]; + RecursiveSearch r = new RecursiveSearch(); + this.files = r.searchWithProperties(startDir, args[1]); + } catch(FileNotFoundException e) { + System.out.println(e.getMessage()); + } + } + } + else { + for (int i = 1; i < args.length; i++) { + try { + String startDir = args[i]; + RecursiveSearch r = new RecursiveSearch(); + this.files = r.searchDirectory(startDir); + } catch(FileNotFoundException e) { + System.out.println(e.getMessage()); + } + } + } + + this.setTokens(); + } + + public void setTokens() { + this.tokens = new ArrayList(); + for (File file : this.getFiles()) { + TokenAnalyzer t = new TokenAnalyzer(file); + this.tokens.add(t.getTokens()); + } + } + + public List getFiles() { + return this.files; + } + + public List getTokens() { + return this.tokens; + } + + public int getNSuggestions() { + return this.nSuggestions; + } +} diff --git a/src/main/java/edu/odu/cs/cs350/TokenAnalyzer.java b/src/main/java/edu/odu/cs/cs350/TokenAnalyzer.java index 5cb622c..4d2e67f 100644 --- a/src/main/java/edu/odu/cs/cs350/TokenAnalyzer.java +++ b/src/main/java/edu/odu/cs/cs350/TokenAnalyzer.java @@ -1,5 +1,6 @@ package edu.odu.cs.cs350; +import java.io.File; import java.io.IOException; import java.io.Reader; import java.util.List; @@ -21,6 +22,8 @@ public class TokenAnalyzer implements Iterable { /** Token object found in the file. Contains necessary metadata defined in Token class. */ private Token token; + + private File file; /** * The default constructor for token analyzer. @@ -42,6 +45,12 @@ public TokenAnalyzer(Reader input) { scanner = new LexerAnalyzer(input); } + public TokenAnalyzer(File file) { + tokensContainer = new LinkedList(); + this.file = file; + scanner = new LexerAnalyzer(input); + } + /** * Divides source codes into tokens. * The function will scan each token and add it to the @@ -84,4 +93,8 @@ public final Iterator iterator() { public String toString() { return Integer.toString(getFileTokenCount()); } + + public Token getTokens() { + return null; + } }