Skip to content

Commit

Permalink
Cleanup Code
Browse files Browse the repository at this point in the history
  • Loading branch information
nestabentum committed Aug 3, 2022
1 parent 419daea commit 7315125
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
6 changes: 3 additions & 3 deletions jplag/src/main/java/de/jplag/JPlagResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ private int[] calculateDistributionFor(List<JPlagComparison> comparisons, Functi
for (JPlagComparison comparison : comparisons) {
float similarity = similarityExtractor.apply(comparison); // extract similarity in percent: 0f <= similarity <= 100f
int index = (int) (similarity / similarityDistributionBucketSize); // divide similarity by bucket size to find index of correct bucket.
if (index == SIMILARITY_DISTRIBUTION_SIZE)
index--; // index is out of bounds when similarity is 100%. decrease by one to count towards the highest value bucket
index = Math.min(index, SIMILARITY_DISTRIBUTION_SIZE - 1);// index is out of bounds when similarity is 100%. decrease by one to count
// towards the highest value bucket
similarityDistribution[SIMILARITY_DISTRIBUTION_SIZE - 1 - index]++; // count comparison towards its determined bucket. bucket order is
// reversed, so that the highest value bucket has the lowest index
// reversed, so that the highest value bucket has the lowest index
}
return similarityDistribution;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ public static void createAndSaveReport(JPlagResult result, String path) {

private static File createDirectory(String path, String name) {
File directory = new File(path.concat("/").concat(name));
if (!directory.exists()) {
if (!directory.mkdirs()) {
logger.error("Failed to create dir.");
}
if (!directory.exists() && !directory.mkdirs()) {
logger.error("Failed to create dir.");
}
return directory;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.jplag.reporting.reportobject.mapper;

import java.util.List;
import java.util.stream.Collectors;

import de.jplag.*;
import de.jplag.reporting.jsonfactory.FileWriter;
Expand Down Expand Up @@ -34,23 +33,22 @@ private void writeComparisons(JPlagResult jPlagResult, String path, List<JPlagCo

private List<Match> convertMatchesToReportMatches(JPlagResult result, JPlagComparison comparison) {
return comparison.getMatches().stream()
.map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().usesIndex()))
.collect(Collectors.toList());
.map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList();
}

private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, Boolean usesIndex) {
private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean usesIndex) {
TokenList tokensFirst = comparison.getFirstSubmission().getTokenList();
TokenList tokensSecond = comparison.getSecondSubmission().getTokenList();
Token startTokenFirst = tokensFirst.getToken(match.getStartOfFirst());
Token endTokenFirst = tokensFirst.getToken(match.getStartOfFirst() + match.getLength() - 1);
Token startTokenSecond = tokensSecond.getToken(match.getStartOfSecond());
Token endTokenSecond = tokensSecond.getToken(match.getStartOfSecond() + match.getLength() - 1);
Token startTokenFirst = tokensFirst.getToken(match.startOfFirst());
Token endTokenFirst = tokensFirst.getToken(match.startOfFirst() + match.length() - 1);
Token startTokenSecond = tokensSecond.getToken(match.startOfSecond());
Token endTokenSecond = tokensSecond.getToken(match.startOfSecond() + match.length() - 1);

int startFirst = usesIndex ? startTokenFirst.getIndex() : startTokenFirst.getLine();
int endFirst = usesIndex ? endTokenFirst.getIndex() : endTokenFirst.getLine();
int startSecond = usesIndex ? startTokenSecond.getIndex() : startTokenSecond.getLine();
int endSecond = usesIndex ? endTokenSecond.getIndex() : endTokenSecond.getLine();
int tokens = match.getLength();
int tokens = match.length();

return new Match(startTokenFirst.getFile(), startTokenSecond.getFile(), startFirst, endFirst, startSecond, endSecond, tokens);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static List<TopComparison> getTopComparisons(List<JPlagComparison> compa
return comparisons.stream().sorted(Comparator.comparing(similarityExtractor).reversed())
.map(comparison -> new TopComparison(comparison.getFirstSubmission().getName(), comparison.getSecondSubmission().getName(),
similarityExtractor.apply(comparison)))
.collect(Collectors.toList());
.toList();
}

private static List<TopComparison> getTopComparisons(List<JPlagComparison> comparisons) {
Expand Down

0 comments on commit 7315125

Please sign in to comment.