Skip to content

Commit

Permalink
Merge pull request #566 from jplag/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings of Sonarcloud
  • Loading branch information
tsaglam authored Aug 3, 2022
2 parents 1ae04f2 + 6d705b9 commit 0c569ae
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
4 changes: 1 addition & 3 deletions jplag.frontend.cpp/src/main/javacc/CPP.jj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import de.jplag.cpp.NewlineStream;

public class CPPScanner implements CPPTokenConstants {
private static Scanner delegatingScanner;
private Scanner delegatingScanner;

public static boolean scanFile(File dir, String fileName, Scanner delegatingScanner) {
CPPScanner scanner;
Expand Down
23 changes: 13 additions & 10 deletions jplag/src/main/java/de/jplag/JPlagComparison.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.jplag;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

/**
* This method represents the whole result of a comparison between two submissions.
*/
public class JPlagComparison implements Comparator<JPlagComparison> { // FIXME TS: contains a lot of code duplication
public class JPlagComparison { // FIXME TS: contains a lot of code duplication

private static final int ROUNDING_FACTOR = 10;

Expand Down Expand Up @@ -35,18 +35,21 @@ public JPlagComparison(Submission firstSubmission, Submission secondSubmission)
matches.add(new Match(startOfFirst, startOfSecond, length));
}

@Override
public int compare(JPlagComparison comparison1, JPlagComparison comparison2) {
return Float.compare(comparison2.similarity(), comparison1.similarity()); // comparison2 first!
}

// TODO DF: hashCode is not implemented!!
@Override
public boolean equals(Object other) {
if (!(other instanceof JPlagComparison)) {
if (other == this) {
return true;
}
if (!(other instanceof JPlagComparison otherComparison)) {
return false;
}
return (compare(this, (JPlagComparison) other) == 0);
return firstSubmission.equals(otherComparison.getFirstSubmission()) && secondSubmission.equals(otherComparison.getSecondSubmission())
&& matches.equals(otherComparison.matches);
}

@Override
public int hashCode() {
return Objects.hash(firstSubmission, secondSubmission, matches);
}

/**
Expand Down
18 changes: 17 additions & 1 deletion jplag/src/main/java/de/jplag/Submission.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -75,10 +76,25 @@ public Submission(String name, File submissionRootFile, boolean isNew, Collectio

@Override
public int compareTo(Submission other) {
// TODO DF: "equals(Object obj)" should be overridden along with the "compareTo(T obj)" method
return name.compareTo(other.name);
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Submission otherSubmission)) {
return false;
}
return otherSubmission.getName().equals(name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}

/**
* @return base code comparison
*/
Expand Down
40 changes: 20 additions & 20 deletions jplag/src/main/java/de/jplag/SubmissionSetBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,27 @@ private void checkForNonOverlappingRootDirectories(Set<File> submissionDirectori

private Optional<Submission> loadBaseCode(Set<File> submissionDirectories, Set<File> oldSubmissionDirectories,
Map<File, Submission> foundSubmissions) throws ExitException {
// Extract the basecode submission if necessary.
Optional<Submission> baseCodeSubmission = Optional.empty();
if (options.hasBaseCode()) {
String baseCodeName = options.getBaseCodeSubmissionName().orElseThrow();
Submission baseCode = loadBaseCodeAsPath(baseCodeName);
if (baseCode == null) {
int numberOfRootDirectories = submissionDirectories.size() + oldSubmissionDirectories.size();
if (numberOfRootDirectories > 1) {
throw new BasecodeException("The base code submission needs to be specified by path instead of by name!");
}

// There is one root directory, and the submissionDirectories variable has been checked to be non-empty.
// That set thus contains the one and only root directory.
File rootDirectory = submissionDirectories.iterator().next();

// Single root-directory, try the legacy way of specifying basecode.
baseCode = loadBaseCodeViaName(baseCodeName, rootDirectory, foundSubmissions);
if (!options.hasBaseCode()) {
return Optional.empty();
}

String baseCodeName = options.getBaseCodeSubmissionName().orElseThrow();
Submission baseCode = loadBaseCodeAsPath(baseCodeName);
if (baseCode == null) {
int numberOfRootDirectories = submissionDirectories.size() + oldSubmissionDirectories.size();
if (numberOfRootDirectories > 1) {
throw new BasecodeException("The base code submission needs to be specified by path instead of by name!");
}
// TODO DF: Here the method assumes that baseCode can be null. later, this is not assumed anymore
baseCodeSubmission = Optional.ofNullable(baseCode);

// There is one root directory, and the submissionDirectories variable has been checked to be non-empty.
// That set thus contains the one and only root directory.
File rootDirectory = submissionDirectories.iterator().next();

// Single root-directory, try the legacy way of specifying basecode.
baseCode = loadBaseCodeViaName(baseCodeName, rootDirectory, foundSubmissions);
}

if (baseCode != null) {
logger.info("Basecode directory \"{}\" will be used.", baseCode.getName());

// Basecode may also be registered as a user submission. If so, remove the latter.
Expand All @@ -158,7 +158,7 @@ private Optional<Submission> loadBaseCode(Set<File> submissionDirectories, Set<F
logger.info("Submission \"{}\" is the specified basecode, it will be skipped during comparison.", removed.getName());
}
}
return baseCodeSubmission;
return Optional.ofNullable(baseCode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class BayesianOptimization {
* @param lengthScale width parameter for the matern kernel
*/
public BayesianOptimization(RealVector minima, RealVector maxima, int initPoints, int maxEvaluations, double noise, RealVector lengthScale) {
if (minima.getDimension() == 0) {
throw new IllegalArgumentException("explored parameters must at least have one dimension");
}
if (minima.getDimension() != maxima.getDimension()) {
throw new DimensionMismatchException(minima.getDimension(), maxima.getDimension());
}
Expand Down Expand Up @@ -162,7 +165,6 @@ public <T> OptimizationResult<T> maximize(Function<RealVector, OptimizationResul
if (debug && logger.isDebugEnabled()) {
logger.debug(gpr.toString(minima, maxima, 100, 25, 0));
}
// TODO Check that best is not null here
coordinates = maxAcq(gpr, best.score, poiSampler, zeroAcquisitionsCounter);
testedCoordinates.add(coordinates);
}
Expand All @@ -173,7 +175,6 @@ public <T> OptimizationResult<T> maximize(Function<RealVector, OptimizationResul
best = result;
}
}

return best;
}

Expand Down

0 comments on commit 0c569ae

Please sign in to comment.