forked from SeaseLtd/rated-ranking-evaluator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SeaseLtd#109: Changes to allow default max grade, default missing gra…
…de to be set via Maven pom.xml: - Add singleton factory for instantiating MetricClassManager instances; - Allow access to default grade values via factory class. - Modify Maven plugins to use factory.
- Loading branch information
Matt Pearce
committed
Mar 16, 2020
1 parent
ef1bc11
commit 0784fdc
Showing
13 changed files
with
178 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
rre-core/src/main/java/io/sease/rre/core/domain/metrics/MetricClassManagerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.sease.rre.core.domain.metrics; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Singleton utility class for instantiating the metric class manager, | ||
* and managing metric configuration details. | ||
* | ||
* @author Matt Pearce ([email protected]) | ||
*/ | ||
public class MetricClassManagerFactory { | ||
|
||
private static MetricClassManagerFactory instance; | ||
|
||
private BigDecimal defaultMaximumGrade = BigDecimal.valueOf(3); | ||
private BigDecimal defaultMissingGrade = BigDecimal.valueOf(2); | ||
|
||
private MetricClassManagerFactory() { | ||
// Private constructor | ||
} | ||
|
||
public static MetricClassManagerFactory getInstance() { | ||
if (instance == null) { | ||
instance = new MetricClassManagerFactory(); | ||
} | ||
return instance; | ||
} | ||
|
||
public MetricClassManager buildMetricClassManager(List<String> metrics, Map<String, Map> parameterizedMetrics) { | ||
final MetricClassManager metricClassManager; | ||
if (parameterizedMetrics == null || parameterizedMetrics.isEmpty()) { | ||
metricClassManager = new SimpleMetricClassManager(metrics); | ||
} else { | ||
metricClassManager = new ParameterizedMetricClassManager(metrics, parameterizedMetrics); | ||
} | ||
return metricClassManager; | ||
} | ||
|
||
public BigDecimal getDefaultMaximumGrade() { | ||
return defaultMaximumGrade; | ||
} | ||
|
||
public MetricClassManagerFactory setDefaultMaximumGrade(BigDecimal defaultMaximumGrade) { | ||
this.defaultMaximumGrade = defaultMaximumGrade; | ||
return this; | ||
} | ||
|
||
public BigDecimal getDefaultMissingGrade() { | ||
return defaultMissingGrade; | ||
} | ||
|
||
public MetricClassManagerFactory setDefaultMissingGrade(BigDecimal defaultMissingGrade) { | ||
this.defaultMissingGrade = defaultMissingGrade; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
rre-core/src/test/java/io/sease/rre/core/domain/metrics/MetricClassManagerFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.sease.rre.core.domain.metrics; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Unit tests for the MetricClassManagerFactory class. | ||
* | ||
* @author Matt Pearce ([email protected]) | ||
*/ | ||
public class MetricClassManagerFactoryTest { | ||
|
||
private final MetricClassManagerFactory factory = MetricClassManagerFactory.getInstance(); | ||
|
||
private static final List<String> METRICS = Arrays.asList( | ||
"io.sease.rre.core.domain.metrics.impl.PrecisionAtOne", | ||
"io.sease.rre.core.domain.metrics.impl.PrecisionAtK" | ||
); | ||
|
||
|
||
@Test | ||
public void returnsSimpleMetricManager_whenParameterizedMetricsAreNull() { | ||
assertThat(factory.buildMetricClassManager(METRICS, null)).isInstanceOf(SimpleMetricClassManager.class); | ||
} | ||
|
||
@Test | ||
public void returnsSimpleMetricManager_whenParameterizedMetricsIsEmpty() { | ||
assertThat(factory.buildMetricClassManager(METRICS, new HashMap<>())).isInstanceOf(SimpleMetricClassManager.class); | ||
} | ||
|
||
@Test | ||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public void returnsParameterizedMetricManager_whenParameterizedMetricsSet() { | ||
final Map precisionAtFiveConfig = new HashMap(); | ||
precisionAtFiveConfig.put("class", "io.sease.rre.core.domain.metrics.impl.PrecisionAtK"); | ||
precisionAtFiveConfig.put("v", 5); | ||
final Map<String, Map> parameterizedConfig = new HashMap<>(); | ||
parameterizedConfig.put("pAt5", precisionAtFiveConfig); | ||
|
||
MetricClassManager test = factory.buildMetricClassManager(METRICS, parameterizedConfig); | ||
|
||
assertThat(test).isInstanceOf(ParameterizedMetricClassManager.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.