Skip to content

Commit

Permalink
Merge pull request #48 from wschaf/integrate
Browse files Browse the repository at this point in the history
Integrate
  • Loading branch information
wschaf authored Dec 6, 2021
2 parents 4918198 + 8edcba1 commit 98925e2
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 40 deletions.
48 changes: 8 additions & 40 deletions src/main/java/edu/odu/cs/cs350/DupDetector.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <nSuggestions> "
+ "<properties file>[OPTIONAL] <path/of/file1> <path/of/file2>");
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());
}
}
82 changes: 82 additions & 0 deletions src/main/java/edu/odu/cs/cs350/Input.java
Original file line number Diff line number Diff line change
@@ -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<File> files;
private List<Token> tokens;

Input() {
this.nSuggestions = 0;
files = new ArrayList<File>();
tokens = new ArrayList<Token>();
}

Input(String args[]) throws Exception {
if (args.length == 0) {
System.err.println("Usage: java -jar build/libs/DupDetector.jar <nSuggestions> "
+ "<properties file>[OPTIONAL] <path/of/file1> <path/of/file2>");
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<Token>();
for (File file : this.getFiles()) {
TokenAnalyzer t = new TokenAnalyzer(file);
this.tokens.add(t.getTokens());
}
}

public List<File> getFiles() {
return this.files;
}

public List<Token> getTokens() {
return this.tokens;
}

public int getNSuggestions() {
return this.nSuggestions;
}
}
13 changes: 13 additions & 0 deletions src/main/java/edu/odu/cs/cs350/TokenAnalyzer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +22,8 @@ public class TokenAnalyzer implements Iterable<Token> {

/** 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.
Expand All @@ -42,6 +45,12 @@ public TokenAnalyzer(Reader input) {
scanner = new LexerAnalyzer(input);
}

public TokenAnalyzer(File file) {
tokensContainer = new LinkedList<Token>();
this.file = file;
scanner = new LexerAnalyzer(input);
}

/**
* Divides source codes into tokens.
* The function will scan each token and add it to the
Expand Down Expand Up @@ -84,4 +93,8 @@ public final Iterator<Token> iterator() {
public String toString() {
return Integer.toString(getFileTokenCount());
}

public Token getTokens() {
return null;
}
}

0 comments on commit 98925e2

Please sign in to comment.