Skip to content

Commit

Permalink
Remove unused code and fix visibility of fields and methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaglam committed Jun 7, 2021
1 parent 1f9f97f commit 409007b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 192 deletions.
3 changes: 0 additions & 3 deletions jplag/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>jplag/version.properties</include>
</includes>
</resource>

<resource>
Expand Down
31 changes: 16 additions & 15 deletions jplag/src/main/java/jplag/JPlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,19 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Vector;
import java.util.stream.Collectors;

import jplag.options.LanguageOption;
import jplag.strategy.ComparisonMode;
import jplag.strategy.ComparisonStrategy;
import jplag.strategy.NormalComparisonStrategy;
import jplagUtils.PropertiesLoader;

/**
* This class coordinates the whole program flow.
*/
public class JPlag implements ProgramI {

// CONSTANTS:
private static final Properties versionProps = PropertiesLoader.loadProps("jplag/version.properties");
public static final String name = "JPlag" + versionProps.getProperty("version", "devel");
public static final String name_long = "JPlag (Version " + versionProps.getProperty("version", "devel") + ")";

// INPUT:
private Submission baseCodeSubmission = null;
private HashSet<String> excludedFileNames = null; // Set of file names to be excluded in comparison.
Expand Down Expand Up @@ -77,7 +70,7 @@ public JPlagResult run() throws ExitException {
throw new ExitException(options.getRootDirName() + " is not a directory!");
}
readExclusionFile(); // This file contains all files names which are excluded

// 2. Parse and validate submissions:
Vector<Submission> submissions = findSubmissions(rootDir);
parseAllSubmissions(submissions, baseCodeSubmission);
Expand All @@ -87,7 +80,7 @@ public JPlagResult run() throws ExitException {
throw new ExitException("Not enough valid submissions! (found " + submissions.size() + " valid submissions)",
ExitException.NOT_ENOUGH_SUBMISSIONS_ERROR);
}

// 3. Compare valid submissions:
errorVector = null; // errorVector is not needed anymore
System.gc();
Expand All @@ -96,23 +89,31 @@ public JPlagResult run() throws ExitException {
return result;
}

/**
* Add an error to the errorVector.
*/
@Override
public void addError(String errorMessage) {
errorVector.add("[" + currentSubmissionName + "]\n" + errorMessage);
print(errorMessage, null);
}

/**
* @return the configured language in which the submissions are written.
*/
public Language getLanguage() {
return language;
}

public JPlagOptions getOptions() {
return this.options;
/**
* @return the program options which allow to configure JPlag.
*/
protected JPlagOptions getOptions() {
return this.options; // TS: Should not be accessible, as options should be set before passing them to this class.
}

/**
* Checks if a file has a valid suffix for the current language.
* @param file is the file to check.
* @return true if the file suffix matches the language.
*/
public boolean hasValidSuffix(File file) {
String[] validSuffixes = options.getFileSuffixes();
if (validSuffixes == null || validSuffixes.length == 0) {
Expand All @@ -122,7 +123,7 @@ public boolean hasValidSuffix(File file) {
}

/**
* Check if a file is excluded or not.
* Checks if a file is excluded or not.
*/
public boolean isFileExcluded(File file) {
if (excludedFileNames == null) {
Expand Down
108 changes: 2 additions & 106 deletions jplag/src/main/java/jplag/JPlagComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,6 @@ public final int[] sort_permutation(int s) { // bubblesort!!!
return perm;
}

/*
* sort start indexes of subA
*/
public final void sort() { // bubblesort!!!
Match tmp;
int size = matches.size();
int i, j;

for (i = 1; i < size; i++) {
for (j = 0; j < (size - i); j++) {
if (matches.get(j).startA > matches.get(j + 1).startA) {
tmp = matches.get(j);
matches.set(j, matches.get(j + 1));
matches.set(j + 1, tmp);
}
}
}
}

/*
* A few methods to calculate some statistical data
*/
Expand Down Expand Up @@ -118,10 +99,6 @@ private int biggestMatch() {
return erg;
}

public final boolean moreThan(float percent) {
return (percent() > percent);
}

public final float roundedPercent() {
float percent = percent();
return ((int) (percent * 10)) / (float) 10;
Expand Down Expand Up @@ -159,11 +136,6 @@ public final float percentB() {
return (divisor == 0 ? 0f : (getNumberOfMatchedTokens() * 100 / (float) divisor));
}

public final float roundedPercentMaxAB() {
float percent = percentMaxAB();
return ((int) (percent * 10)) / (float) 10;
}

public final float percentMaxAB() {
float a = percentA();
float b = percentB();
Expand All @@ -174,11 +146,6 @@ public final float percentMaxAB() {
}
}

public final float roundedPercentMinAB() {
float percent = percentMinAB();
return ((int) (percent * 10)) / (float) 10;
}

public final float percentMinAB() {
float a = percentA();
float b = percentB();
Expand All @@ -189,12 +156,12 @@ public final float percentMinAB() {
}
}

public final float percentBasecodeA() {
private final float percentBasecodeA() {
float sa = firstSubmission.getNumberOfTokens() - firstSubmission.files.size();
return bcMatchesA.getNumberOfMatchedTokens() * 100 / sa;
}

public final float percentBasecodeB() {
private final float percentBasecodeB() {
float sb = secondSubmission.getNumberOfTokens() - secondSubmission.files.size();
return bcMatchesB.getNumberOfMatchedTokens() * 100 / sb;
}
Expand Down Expand Up @@ -263,44 +230,6 @@ public String color(int anz) {
return "#" + help + "0000";
}

/*
* This method returns the name of all files that are represented by at least one token.
*/
public final String[] allFiles(int sub) {
Structure struct = (sub == 0 ? firstSubmission : secondSubmission).tokenList;
int count = 1;
for (int i = 1; i < struct.size(); i++) {
if (!struct.tokens[i].file.equals(struct.tokens[i - 1].file)) {
count++;
}
}
String[] res = new String[count];
if (count > 0) {
res[0] = struct.tokens[0].file;
}
count = 1;
for (int i = 1; i < struct.size(); i++) {
if (!struct.tokens[i].file.equals(struct.tokens[i - 1].file)) {
res[count++] = struct.tokens[i].file;
}
}

/*
* bubblesort by file name. (so that equally named files are displayed approximately side by side.)
*/
for (int a = 1; a < res.length; a++) {
for (int b = 1; b < (res.length - a); b++) {
if (res[b - 1].compareTo(res[b]) < 0) {
String hilf = res[b - 1];
res[b - 1] = res[b];
res[b] = hilf;
}
}
}

return res;
}

@Override
public int compare(JPlagComparison o1, JPlagComparison o2) {
float p1 = o1.percent();
Expand Down Expand Up @@ -328,37 +257,4 @@ public String toString() {
return firstSubmission.name + " <-> " + secondSubmission.name;
}

public static class AvgComparator implements Comparator<JPlagComparison> {

@Override
public int compare(JPlagComparison o1, JPlagComparison o2) {
float p1 = o1.percent();
float p2 = o2.percent();
return Float.compare(p2, p1);
}

}

public static class AvgReversedComparator implements Comparator<JPlagComparison> {

@Override
public int compare(JPlagComparison o1, JPlagComparison o2) {
float p1 = o1.percent();
float p2 = o2.percent();
return Float.compare(p1, p2);
}

}

public static class MaxComparator implements Comparator<JPlagComparison> {

@Override
public int compare(JPlagComparison o1, JPlagComparison o2) {
float p1 = o1.percentMaxAB();
float p2 = o2.percentMaxAB();
return Float.compare(p2, p1);
}

}

}
9 changes: 2 additions & 7 deletions jplag/src/main/java/jplag/JPlagOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

public class JPlagOptions {

/**
* This is related to `storeMatches`.
*/
public static final int MAX_RESULT_PAIRS = 1000;

/**
* Language used to parse the submissions.
*/
Expand Down Expand Up @@ -142,11 +137,11 @@ public boolean hasBaseCode() {
return this.baseCodeSubmissionName != null;
}

public boolean hasFileSuffixes() {
private boolean hasFileSuffixes() {
return this.fileSuffixes != null && this.fileSuffixes.length > 0;
}

public boolean hasMinTokenMatch() {
private boolean hasMinTokenMatch() {
return this.minTokenMatch != null;
}

Expand Down
10 changes: 1 addition & 9 deletions jplag/src/main/java/jplag/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class Match {
public int length;

public Match() {
// non-parameterized constructor for uninitialized matches
}

public Match(int startA, int startB, int length) {
Expand All @@ -21,15 +22,6 @@ public void set(int startA, int startB, int length) {
this.length = length;
}

public final boolean contains(int index, int sub) {
int start = (sub == 0 ? startA : startB);
return (start <= index && index < (start + length));
}

public final boolean overlap(Match other) {
return overlap(other.startA, other.startB, other.length);
}

public final boolean overlap(int oStartA, int oStartB, int oLength) {
if (startA < oStartA) {
if ((oStartA - startA) < length) {
Expand Down
36 changes: 0 additions & 36 deletions jplag/src/main/java/jplag/SortedVector.java

This file was deleted.

4 changes: 2 additions & 2 deletions jplag/src/main/java/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Submission implements Comparable<Submission> {
*/
public String name;

public File submissionFile;
private File submissionFile;

/**
* List of files this submission consists of.
Expand Down Expand Up @@ -115,7 +115,7 @@ public String toString() {
* @param files - List of files to map.
* @return an array of file paths relative to the submission directory.
*/
public String[] getRelativeFilePaths(File baseFile, List<File> files) {
private String[] getRelativeFilePaths(File baseFile, List<File> files) {
Path baseFilePath = baseFile.toPath();

return files.stream().map(File::toPath).map(baseFilePath::relativize).map(Path::toString).toArray(String[]::new);
Expand Down
4 changes: 0 additions & 4 deletions jplag/src/main/java/jplag/reporting/BufferedCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public BufferedCounter(Writer out) {
count = 0;
}

public BufferedCounter(Writer out, int sz) {
super(out, sz);
count = 0;
}

@Override
public void write(int c) throws IOException {
Expand Down
Loading

0 comments on commit 409007b

Please sign in to comment.