summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-18 08:53:57 +0200
committerDavid Gageot <david@gageot.net>2012-07-18 08:54:35 +0200
commitfdc4b664a5d841ec80e15c0867d697dc02f2f4cb (patch)
treeacb2667e5ca2a995ec5795a2496839789138cb5a /sonar-batch
parent7cd84ab05c0610c9faea163be591a64c61958cae (diff)
downloadsonarqube-fdc4b664a5d841ec80e15c0867d697dc02f2f4cb.tar.gz
sonarqube-fdc4b664a5d841ec80e15c0867d697dc02f2f4cb.zip
Simplify code
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java31
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java10
2 files changed, 1 insertions, 40 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 6d68a0b6478..ec036f13da4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -23,14 +23,12 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.SetMultimap;
-import org.apache.commons.lang.math.NumberUtils;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.LoggerFactory;
import org.sonar.api.database.model.MeasureMapper;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
import org.sonar.api.measures.RuleMeasure;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
@@ -104,34 +102,7 @@ public final class MeasurePersister {
@VisibleForTesting
static boolean shouldPersistMeasure(Resource resource, Measure measure) {
return measure.getPersistenceMode().useDatabase() &&
- !(ResourceUtils.isEntity(resource) && isBestValueMeasure(measure, measure.getMetric()));
- }
-
- @VisibleForTesting
- static boolean isBestValueMeasure(Measure measure, Metric metric) {
- return metric.isOptimizedBestValue() == Boolean.TRUE
- && metric.getBestValue() != null
- && (measure.getValue() == null || NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0)
- && allNull(measure.getId(), measure.getAlertStatus(), measure.getDescription(), measure.getTendency(), measure.getUrl())
- && !measure.hasData()
- && isZeroVariation(measure.getVariation1())
- && isZeroVariation(measure.getVariation2())
- && isZeroVariation(measure.getVariation3())
- && isZeroVariation(measure.getVariation4())
- && isZeroVariation(measure.getVariation5());
- }
-
- private static boolean isZeroVariation(Double variation) {
- return (variation == null) || NumberUtils.compare(variation.doubleValue(), 0.0) == 0;
- }
-
- private static boolean allNull(Object... values) {
- for (Object value : values) {
- if (null != value) {
- return false;
- }
- }
- return true;
+ !(ResourceUtils.isEntity(resource) && measure.isBestValue());
}
private List<MeasureModel> getMeasuresToSave() {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
index 240248427a2..9aa404b3569 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java
@@ -232,16 +232,6 @@ public class MeasurePersisterTest extends AbstractDaoTestCase {
assertThat(MeasurePersister.shouldPersistMeasure(aFile, duplicatedLines)).isTrue();
}
- @Test
- public void null_value_and_null_variations_should_be_considered_as_best_value() {
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation1(0.0), CoreMetrics.NEW_VIOLATIONS)).isTrue();
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation1(1.0), CoreMetrics.NEW_VIOLATIONS)).isFalse();
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation2(1.0), CoreMetrics.NEW_VIOLATIONS)).isFalse();
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation3(1.0), CoreMetrics.NEW_VIOLATIONS)).isFalse();
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation4(1.0), CoreMetrics.NEW_VIOLATIONS)).isFalse();
- assertThat(MeasurePersister.isBestValueMeasure(new Measure(CoreMetrics.NEW_VIOLATIONS_KEY).setVariation5(1.0), CoreMetrics.NEW_VIOLATIONS)).isFalse();
- }
-
private static Snapshot snapshot(int id) {
Snapshot snapshot = mock(Snapshot.class);
when(snapshot.getId()).thenReturn(id);