-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Greedy String Tiling out of bounds #2179
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,8 @@ private static Version loadVersion() { | |
|
||
/** | ||
* Creates and initializes a JPlag instance, parameterized by a set of options. | ||
* @deprecated in favor of static {@link #run(JPlagOptions)}. | ||
* @param options determines the parameterization. | ||
* @deprecated in favor of static {@link #run(JPlagOptions)}. | ||
*/ | ||
@Deprecated(since = "4.3.0") | ||
public JPlag(JPlagOptions options) { | ||
|
@@ -49,9 +49,9 @@ public JPlag(JPlagOptions options) { | |
|
||
/** | ||
* Main procedure, executes the comparison of source code submissions. | ||
* @deprecated in favor of static {@link #run(JPlagOptions)}. | ||
* @return the results of the comparison, specifically the submissions whose similarity exceeds a set threshold. | ||
* @throws ExitException if JPlag exits preemptively. | ||
* @deprecated in favor of static {@link #run(JPlagOptions)}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
*/ | ||
@Deprecated(since = "4.3.0") | ||
public JPlagResult run() throws ExitException { | ||
|
@@ -66,11 +66,14 @@ public JPlagResult run() throws ExitException { | |
*/ | ||
public static JPlagResult run(JPlagOptions options) throws ExitException { | ||
checkForConfigurationConsistency(options); | ||
GreedyStringTiling coreAlgorithm = new GreedyStringTiling(options); | ||
ComparisonStrategy comparisonStrategy = new ParallelComparisonStrategy(options, coreAlgorithm); | ||
|
||
// Parse and validate submissions. | ||
SubmissionSetBuilder builder = new SubmissionSetBuilder(options); | ||
SubmissionSet submissionSet = builder.buildSubmissionSet(); | ||
|
||
GreedyStringTiling coreAlgorithm = new GreedyStringTiling(options, TokenValueMapper.generateTokenValueMapper(submissionSet)); | ||
ComparisonStrategy comparisonStrategy = new ParallelComparisonStrategy(options, coreAlgorithm); | ||
|
||
if (options.normalize() && options.language().supportsNormalization() && options.language().requiresCoreNormalization()) { | ||
submissionSet.normalizeSubmissions(); | ||
} | ||
|
@@ -113,7 +116,7 @@ private static void checkForConfigurationConsistency(JPlagOptions options) throw | |
} | ||
|
||
List<String> duplicateNames = getDuplicateSubmissionFolderNames(options); | ||
if (duplicateNames.size() > 0) { | ||
if (!duplicateNames.isEmpty()) { | ||
throw new RootDirectoryException(String.format("Duplicate root directory names found: %s", String.join(", ", duplicateNames))); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.jplag; | ||
|
||
import java.util.HashMap; | ||
import java.util.IdentityHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import de.jplag.logging.ProgressBarLogger; | ||
import de.jplag.logging.ProgressBarType; | ||
|
||
public class TokenValueMapper { | ||
private final Map<TokenType, Integer> tokenTypeValues; | ||
private final Map<Submission, int[]> tokenValueMap; | ||
|
||
public TokenValueMapper() { | ||
this.tokenTypeValues = new HashMap<>(); | ||
this.tokenValueMap = new IdentityHashMap<>(); | ||
|
||
this.tokenTypeValues.put(SharedTokenType.FILE_END, 0); | ||
} | ||
|
||
public void addSubmissions(SubmissionSet submissionSet) { | ||
ProgressBarLogger.iterate(ProgressBarType.HASH_CREATION, submissionSet.getSubmissions(), this::addSingleSubmission); | ||
} | ||
|
||
public void addSingleSubmission(Submission submission) { | ||
List<Token> tokens = submission.getTokenList(); | ||
int[] tokenValues = new int[tokens.size()]; | ||
for (int i = 0; i < tokens.size(); i++) { | ||
TokenType type = tokens.get(i).getType(); | ||
tokenTypeValues.putIfAbsent(type, tokenTypeValues.size()); | ||
tokenValues[i] = tokenTypeValues.get(type); | ||
} | ||
this.tokenValueMap.put(submission, tokenValues); | ||
} | ||
|
||
public int[] getTokenValuesFor(Submission submission) { | ||
return this.tokenValueMap.get(submission); | ||
} | ||
|
||
public static TokenValueMapper generateTokenValueMapper(SubmissionSet submissionSet) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a special reason to have this generator method and not use the constrcutor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of. Usually constructors should not contain application logic, at least the way I learned it. So having a constructor create the entire map automatically feels like it's bad code. |
||
TokenValueMapper tokenValueMapper = new TokenValueMapper(); | ||
tokenValueMapper.addSubmissions(submissionSet); | ||
if (submissionSet.hasBaseCode()) { | ||
tokenValueMapper.addSingleSubmission(submissionSet.getBaseCode()); | ||
} | ||
return tokenValueMapper; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this move down due to spotless?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I'm pretty sure I didn't touch the Javadoc. But I think this is the canonical order.