diff --git a/jplag/src/main/java/jplag/CLI.java b/jplag/src/main/java/jplag/CLI.java index 2c6c04091..42b97f43b 100644 --- a/jplag/src/main/java/jplag/CLI.java +++ b/jplag/src/main/java/jplag/CLI.java @@ -4,6 +4,7 @@ import java.io.File; +import jplag.options.JPlagOptions; import jplag.options.LanguageOption; import jplag.options.Verbosity; import jplag.reporting.Report; diff --git a/jplag/src/main/java/jplag/JPlag.java b/jplag/src/main/java/jplag/JPlag.java index 285e0875f..8efba116b 100644 --- a/jplag/src/main/java/jplag/JPlag.java +++ b/jplag/src/main/java/jplag/JPlag.java @@ -17,6 +17,7 @@ import java.util.Vector; import java.util.stream.Collectors; +import jplag.options.JPlagOptions; import jplag.options.LanguageOption; import jplag.strategy.ComparisonMode; import jplag.strategy.ComparisonStrategy; diff --git a/jplag/src/main/java/jplag/JPlagResult.java b/jplag/src/main/java/jplag/JPlagResult.java index dde97ce35..842dd61ec 100644 --- a/jplag/src/main/java/jplag/JPlagResult.java +++ b/jplag/src/main/java/jplag/JPlagResult.java @@ -2,6 +2,8 @@ import java.util.List; +import jplag.options.JPlagOptions; + /** * Encapsulates the results of a comparison of a set of source code submissions. */ diff --git a/jplag/src/main/java/jplag/JPlagOptions.java b/jplag/src/main/java/jplag/options/JPlagOptions.java similarity index 97% rename from jplag/src/main/java/jplag/JPlagOptions.java rename to jplag/src/main/java/jplag/options/JPlagOptions.java index 1d7fd1055..5046c5259 100644 --- a/jplag/src/main/java/jplag/JPlagOptions.java +++ b/jplag/src/main/java/jplag/options/JPlagOptions.java @@ -1,10 +1,8 @@ -package jplag; +package jplag.options; import static jplag.strategy.ComparisonMode.NORMAL; -import jplag.options.LanguageOption; -import jplag.options.SimilarityMetric; -import jplag.options.Verbosity; +import jplag.Language; import jplag.strategy.ComparisonMode; public class JPlagOptions { @@ -115,7 +113,7 @@ public JPlagOptions(String rootDirName, LanguageOption languageOption) { * not set by the user. * @param language - initialized language instance */ - void setLanguageDefaults(Language language) { + public void setLanguageDefaults(Language language) { if (!this.hasMinTokenMatch()) { this.minTokenMatch = language.min_token_match(); } @@ -203,7 +201,7 @@ public SimilarityMetric getSimilarityMetric() { return similarityMetric; } - void setLanguage(Language language) { + public void setLanguage(Language language) { this.language = language; } diff --git a/jplag/src/main/java/jplag/reporting/BufferedCounter.java b/jplag/src/main/java/jplag/reporting/BufferedCounter.java index ad8da7b2d..63c07ced2 100644 --- a/jplag/src/main/java/jplag/reporting/BufferedCounter.java +++ b/jplag/src/main/java/jplag/reporting/BufferedCounter.java @@ -4,8 +4,8 @@ import java.io.IOException; import java.io.Writer; -/* - * This class counts the number of printed characters. +/** + * A buffered writer that counts the number of printed characters. */ public class BufferedCounter extends BufferedWriter { @@ -16,7 +16,6 @@ public BufferedCounter(Writer out) { count = 0; } - @Override public void write(int c) throws IOException { super.write(c); diff --git a/jplag/src/main/java/jplag/reporting/HTMLFile.java b/jplag/src/main/java/jplag/reporting/HTMLFile.java index c57ae6b97..1e4d6a8d5 100644 --- a/jplag/src/main/java/jplag/reporting/HTMLFile.java +++ b/jplag/src/main/java/jplag/reporting/HTMLFile.java @@ -1,6 +1,5 @@ package jplag.reporting; -import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -10,25 +9,22 @@ public class HTMLFile extends PrintWriter { - private BufferedCounter bc; + private BufferedCounter counter; /** * Static factory method to instantiate an HTMLFile objects. */ public static HTMLFile fromFile(File file) throws IOException { - BufferedCounter bc = new BufferedCounter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); - - HTMLFile htmlFile = new HTMLFile(bc); - htmlFile.bc = bc; - - return htmlFile; + BufferedCounter counter = new BufferedCounter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); + return new HTMLFile(counter); } - private HTMLFile(BufferedWriter writer) { - super(writer); + private HTMLFile(BufferedCounter counter) { + super(counter); + this.counter = counter; } public int bytesWritten() { - return bc.bytesWritten(); + return counter.bytesWritten(); } } diff --git a/jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java b/jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java index 8c8c36c37..1fb0bb9b9 100644 --- a/jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java +++ b/jplag/src/main/java/jplag/strategy/AbstractComparisonStrategy.java @@ -6,8 +6,8 @@ import jplag.GreedyStringTiling; import jplag.JPlagBaseCodeComparison; import jplag.JPlagComparison; -import jplag.JPlagOptions; import jplag.Submission; +import jplag.options.JPlagOptions; import jplag.options.SimilarityMetric; public abstract class AbstractComparisonStrategy implements ComparisonStrategy { @@ -16,28 +16,28 @@ public abstract class AbstractComparisonStrategy implements ComparisonStrategy { // Hashtable that maps the name of a submissions to its matches with the provided base code. protected Hashtable baseCodeMatches = new Hashtable<>(30); - protected GreedyStringTiling gSTiling; + protected GreedyStringTiling greedyStringTiling; protected JPlagOptions options; - public AbstractComparisonStrategy(JPlagOptions options, GreedyStringTiling gSTiling) { - this.gSTiling = gSTiling; + public AbstractComparisonStrategy(JPlagOptions options, GreedyStringTiling greedyStringTiling) { + this.greedyStringTiling = greedyStringTiling; this.options = options; } protected void compareSubmissionsToBaseCode(Vector submissions, Submission baseCodeSubmission) { int numberOfSubmissions = submissions.size(); - JPlagBaseCodeComparison bcMatch; + JPlagBaseCodeComparison baseCodeMatch; Submission currentSubmission; for (int i = 0; i < (numberOfSubmissions); i++) { currentSubmission = submissions.elementAt(i); - bcMatch = this.gSTiling.compareWithBaseCode(currentSubmission, baseCodeSubmission); - baseCodeMatches.put(currentSubmission.name, bcMatch); + baseCodeMatch = greedyStringTiling.compareWithBaseCode(currentSubmission, baseCodeSubmission); + baseCodeMatches.put(currentSubmission.name, baseCodeMatch); - this.gSTiling.resetBaseSubmission(baseCodeSubmission); + greedyStringTiling.resetBaseSubmission(baseCodeSubmission); } } diff --git a/jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java b/jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java index e524c038c..916f0da08 100644 --- a/jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java +++ b/jplag/src/main/java/jplag/strategy/NormalComparisonStrategy.java @@ -6,60 +6,50 @@ import jplag.GreedyStringTiling; import jplag.JPlagComparison; -import jplag.JPlagOptions; import jplag.JPlagResult; import jplag.Submission; +import jplag.options.JPlagOptions; public class NormalComparisonStrategy extends AbstractComparisonStrategy { - public NormalComparisonStrategy(JPlagOptions options, GreedyStringTiling gSTiling) { - super(options, gSTiling); + public NormalComparisonStrategy(JPlagOptions options, GreedyStringTiling greedyStringTiling) { + super(options, greedyStringTiling); } - + @Override public JPlagResult compareSubmissions(Vector submissions, Submission baseCodeSubmission) { if (baseCodeSubmission != null) { compareSubmissionsToBaseCode(submissions, baseCodeSubmission); } - + long timeBeforeStartInMillis = System.currentTimeMillis(); int i, j, numberOfSubmissions = submissions.size(); Submission first, second; - JPlagComparison comparison; - List comparisons = new ArrayList<>(); - + JPlagComparison comparison; + for (i = 0; i < (numberOfSubmissions - 1); i++) { first = submissions.elementAt(i); - if (first.tokenList == null) { continue; } - for (j = (i + 1); j < numberOfSubmissions; j++) { second = submissions.elementAt(j); - if (second.tokenList == null) { continue; } - - comparison = this.gSTiling.compare(first, second); - + comparison = greedyStringTiling.compare(first, second); System.out.println("Comparing " + first.name + "-" + second.name + ": " + comparison.percent()); - if (baseCodeSubmission != null) { comparison.bcMatchesA = baseCodeMatches.get(comparison.firstSubmission.name); comparison.bcMatchesB = baseCodeMatches.get(comparison.secondSubmission.name); } - if (isAboveSimilarityThreshold(comparison)) { comparisons.add(comparison); } } } - long durationInMillis = System.currentTimeMillis() - timeBeforeStartInMillis; - return new JPlagResult(comparisons, durationInMillis, numberOfSubmissions, options); }