]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9531 Fix computation of variation when value is 0
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 27 Jul 2017 09:22:51 +0000 (11:22 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Jul 2017 09:27:51 +0000 (11:27 +0200)
Also remove default value behavior as it's not used anymore by GOV

server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java

index bc3024d7126cf6cc64183e1ebfb4ac44b0dd0998..82e0afce6a39c6deeae7c0b3a2c48bd0e254d6d1 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.computation.task.projectanalysis.formula;
 
 import com.google.common.base.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
 import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
@@ -35,21 +33,14 @@ import static org.sonar.server.computation.task.projectanalysis.measure.Measure.
  */
 public class VariationSumFormula implements Formula<VariationSumFormula.VariationSumCounter> {
   private final String metricKey;
-  @CheckForNull
-  private final Double defaultInputValue;
 
   public VariationSumFormula(String metricKey) {
-    this(metricKey, null);
-  }
-
-  public VariationSumFormula(String metricKey, @Nullable Double defaultInputValue) {
     this.metricKey = requireNonNull(metricKey, "Metric key cannot be null");
-    this.defaultInputValue = defaultInputValue;
   }
 
   @Override
   public VariationSumCounter createNewCounter() {
-    return new VariationSumCounter(metricKey, defaultInputValue);
+    return new VariationSumCounter(metricKey);
   }
 
   @Override
@@ -66,14 +57,11 @@ public class VariationSumFormula implements Formula<VariationSumFormula.Variatio
   }
 
   public static final class VariationSumCounter implements Counter<VariationSumCounter> {
-    @CheckForNull
-    private final Double defaultInputValue;
     private final DoubleValue doubleValue = new DoubleValue();
     private final String metricKey;
 
-    private VariationSumCounter(String metricKey, @Nullable Double defaultInputValue) {
+    private VariationSumCounter(String metricKey) {
       this.metricKey = metricKey;
-      this.defaultInputValue = defaultInputValue;
     }
 
     @Override
@@ -85,22 +73,11 @@ public class VariationSumFormula implements Formula<VariationSumFormula.Variatio
     public void initialize(CounterInitializationContext context) {
       Optional<Measure> measure = context.getMeasure(metricKey);
       if (!measure.isPresent() || !measure.get().hasVariation()) {
-        initializeWithDefaultInputValue();
         return;
       }
       double variation = measure.get().getVariation();
-      if (variation > 0) {
-        doubleValue.increment(variation);
-      } else if (defaultInputValue != null) {
-        doubleValue.increment(defaultInputValue);
-      }
+      doubleValue.increment(variation);
     }
 
-    private void initializeWithDefaultInputValue() {
-      if (defaultInputValue == null) {
-        return;
-      }
-      doubleValue.increment(defaultInputValue);
-    }
   }
 }