From b280143c28bbd3c037bf703bfc1329a847c40590 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 13:04:04 +0100 Subject: [PATCH 1/6] Use default values for CLI --- cli/src/main/java/de/jplag/cli/CliOptions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index da249342c..d812bed67 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -116,13 +116,13 @@ public static class ClusteringEnabled { } public static class Merging { - @Option(names = {"--match-merging"}, description = "Enables match merging (default: false)%n") + @Option(names = {"--match-merging"}, defaultValue = "false", description = "Enables match merging (default: false)%n") public boolean enabled; - @Option(names = {"--neighbor-length"}, description = "Defines how short a match can be, to be considered (default: 2)%n") + @Option(names = {"--neighbor-length"}, defaultValue = "2", description = "Defines how short a match can be, to be considered (default: 2)%n") public int minimumNeighborLength; - @Option(names = {"--gap-size"}, description = "Defines how many token there can be between two neighboring matches (default: 6)%n") + @Option(names = {"--gap-size"}, defaultValue = "6", description = "Defines how many token there can be between two neighboring matches (default: 6)%n") public int maximumGapSize; } From 1dadfb9a514d407e4af7db745a1989ef218b5584 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 13:08:04 +0100 Subject: [PATCH 2/6] Spotless --- cli/src/main/java/de/jplag/cli/CliOptions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index d812bed67..690573f45 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -122,7 +122,8 @@ public static class Merging { @Option(names = {"--neighbor-length"}, defaultValue = "2", description = "Defines how short a match can be, to be considered (default: 2)%n") public int minimumNeighborLength; - @Option(names = {"--gap-size"}, defaultValue = "6", description = "Defines how many token there can be between two neighboring matches (default: 6)%n") + @Option(names = { + "--gap-size"}, defaultValue = "6", description = "Defines how many token there can be between two neighboring matches (default: 6)%n") public int maximumGapSize; } From 579ccbecc71a4f48db4a5688ba7c7afec01ef150 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 15:32:13 +0100 Subject: [PATCH 3/6] Pushed default values to constants --- cli/src/main/java/de/jplag/cli/CliOptions.java | 13 +++++++------ .../main/java/de/jplag/merging/MergingOptions.java | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cli/src/main/java/de/jplag/cli/CliOptions.java b/cli/src/main/java/de/jplag/cli/CliOptions.java index 690573f45..c42cbe19b 100644 --- a/cli/src/main/java/de/jplag/cli/CliOptions.java +++ b/cli/src/main/java/de/jplag/cli/CliOptions.java @@ -7,6 +7,7 @@ import de.jplag.clustering.ClusteringOptions; import de.jplag.clustering.algorithm.InterClusterSimilarity; import de.jplag.java.JavaLanguage; +import de.jplag.merging.MergingOptions; import de.jplag.options.JPlagOptions; import de.jplag.options.SimilarityMetric; @@ -116,15 +117,15 @@ public static class ClusteringEnabled { } public static class Merging { - @Option(names = {"--match-merging"}, defaultValue = "false", description = "Enables match merging (default: false)%n") - public boolean enabled; + @Option(names = {"--match-merging"}, description = "Enables match merging (default: ${DEFAULT-VALUE})%n") + public boolean enabled = MergingOptions.DEFAULT_ENABLED; - @Option(names = {"--neighbor-length"}, defaultValue = "2", description = "Defines how short a match can be, to be considered (default: 2)%n") - public int minimumNeighborLength; + @Option(names = {"--neighbor-length"}, description = "Defines how short a match can be, to be considered (default: ${DEFAULT-VALUE})%n") + public int minimumNeighborLength = MergingOptions.DEFAULT_NEIGHBOR_LENGTH; @Option(names = { - "--gap-size"}, defaultValue = "6", description = "Defines how many token there can be between two neighboring matches (default: 6)%n") - public int maximumGapSize; + "--gap-size"}, description = "Defines how many token there can be between two neighboring matches (default: ${DEFAULT-VALUE})%n") + public int maximumGapSize = MergingOptions.DEFAULT_GAP_SIZE; } diff --git a/core/src/main/java/de/jplag/merging/MergingOptions.java b/core/src/main/java/de/jplag/merging/MergingOptions.java index 4c2b49e08..7d77f7f31 100644 --- a/core/src/main/java/de/jplag/merging/MergingOptions.java +++ b/core/src/main/java/de/jplag/merging/MergingOptions.java @@ -10,12 +10,16 @@ public record MergingOptions(@JsonProperty("enabled") boolean enabled, @JsonProperty("min_neighbour_length") int minimumNeighborLength, @JsonProperty("max_gap_size") int maximumGapSize) { + public static final boolean DEFAULT_ENABLED = false; + public static final int DEFAULT_NEIGHBOR_LENGTH = 2; + public static final int DEFAULT_GAP_SIZE = 6; + /** * The default values of MergingOptions are false for the enable-switch, which deactivate MatchMerging, while * minimumNeighborLength and maximumGapSize default to (2,6), which in testing yielded the best results. */ public MergingOptions() { - this(false, 2, 6); + this(DEFAULT_ENABLED, DEFAULT_NEIGHBOR_LENGTH, DEFAULT_GAP_SIZE); } /** From 68c22cdf285a2767652981aa80b250863ee35d62 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 15:45:06 +0100 Subject: [PATCH 4/6] Merging options default test --- .../java/de/jplag/cli/MergingOptionsTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cli/src/test/java/de/jplag/cli/MergingOptionsTest.java diff --git a/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java new file mode 100644 index 000000000..c5c2f2aa4 --- /dev/null +++ b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java @@ -0,0 +1,19 @@ +package de.jplag.cli; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; + +import de.jplag.merging.MergingOptions; + +public class MergingOptionsTest extends CommandLineInterfaceTest { + @Test + void testMergingDefault() throws CliException { + buildOptionsFromCLI(defaultArguments()); + assertNotNull(options.mergingOptions()); + assertEquals(options.mergingOptions().enabled(), MergingOptions.DEFAULT_ENABLED); + assertEquals(options.mergingOptions().minimumNeighborLength(), MergingOptions.DEFAULT_NEIGHBOR_LENGTH); + assertEquals(options.mergingOptions().maximumGapSize(), MergingOptions.DEFAULT_GAP_SIZE); + } +} From f0ff4dde37f5ecad45f163ad205cfd24c28512f5 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 16:27:09 +0100 Subject: [PATCH 5/6] JavaDoc --- cli/src/test/java/de/jplag/cli/MergingOptionsTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java index c5c2f2aa4..36de27363 100644 --- a/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java +++ b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java @@ -3,12 +3,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import de.jplag.merging.MergingOptions; +/** + * Test cases for the options of the match merging mechanism. + */ public class MergingOptionsTest extends CommandLineInterfaceTest { + @Test + @DisplayName("Test if default values are used when creating merging options from CLI") void testMergingDefault() throws CliException { buildOptionsFromCLI(defaultArguments()); assertNotNull(options.mergingOptions()); From 38e4c2095e7fd6594e8a6972af127209c8cbd388 Mon Sep 17 00:00:00 2001 From: uuqjz Date: Thu, 15 Feb 2024 16:38:58 +0100 Subject: [PATCH 6/6] Sonar Issues --- cli/src/test/java/de/jplag/cli/MergingOptionsTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java index 36de27363..bf2b642c7 100644 --- a/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java +++ b/cli/src/test/java/de/jplag/cli/MergingOptionsTest.java @@ -11,15 +11,15 @@ /** * Test cases for the options of the match merging mechanism. */ -public class MergingOptionsTest extends CommandLineInterfaceTest { +class MergingOptionsTest extends CommandLineInterfaceTest { @Test @DisplayName("Test if default values are used when creating merging options from CLI") void testMergingDefault() throws CliException { buildOptionsFromCLI(defaultArguments()); assertNotNull(options.mergingOptions()); - assertEquals(options.mergingOptions().enabled(), MergingOptions.DEFAULT_ENABLED); - assertEquals(options.mergingOptions().minimumNeighborLength(), MergingOptions.DEFAULT_NEIGHBOR_LENGTH); - assertEquals(options.mergingOptions().maximumGapSize(), MergingOptions.DEFAULT_GAP_SIZE); + assertEquals(MergingOptions.DEFAULT_ENABLED, options.mergingOptions().enabled()); + assertEquals(MergingOptions.DEFAULT_NEIGHBOR_LENGTH, options.mergingOptions().minimumNeighborLength()); + assertEquals(MergingOptions.DEFAULT_GAP_SIZE, options.mergingOptions().maximumGapSize()); } }