]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8743 Remove MeasureVariations from XXXVariationValue classes
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 8 Feb 2017 07:47:32 +0000 (08:47 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 9 Feb 2017 11:15:11 +0000 (12:15 +0100)
31 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/MaintainabilityMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/ReliabilityAndSecurityRatingMeasuresVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ViewsFormulaExecutorComponentVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java [deleted file]

index 77d1730e26b1e9e6b9223d6991c73d94f60ebe36..b4186bf6f6cb4450e9341d0487f6ac1ab4ae9e27 100644 (file)
@@ -23,7 +23,7 @@ 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.DoubleVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 
 import static java.util.Objects.requireNonNull;
@@ -68,7 +68,7 @@ public class VariationSumFormula implements Formula<VariationSumFormula.Variatio
   public static final class VariationSumCounter implements Counter<VariationSumCounter> {
     @CheckForNull
     private final Double defaultInputValue;
-    private final DoubleVariationValue doubleValue = new DoubleVariationValue();
+    private final DoubleValue doubleValue = new DoubleValue();
     private final String metricKey;
 
     private VariationSumCounter(String metricKey, @Nullable Double defaultInputValue) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValue.java
new file mode 100644 (file)
index 0000000..adae6c5
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import javax.annotation.Nullable;
+
+/**
+ * Convenience class wrapping a double to compute the value and know it is has ever been set.
+ */
+public class DoubleValue {
+  private boolean set = false;
+  private double value = 0L;
+
+  /**
+   * @return the current {@link DoubleValue} so that chained calls on a specific {@link DoubleValue} instance can be done
+   */
+  public DoubleValue increment(double increment) {
+    this.value += increment;
+    this.set = true;
+    return this;
+  }
+
+  /**
+   * @return the current {@link DoubleValue} so that chained calls on a specific {@link DoubleValue} instance can be done
+   */
+  public DoubleValue increment(@Nullable DoubleValue value) {
+    if (value != null && value.isSet()) {
+      increment(value.value);
+    }
+    return this;
+  }
+
+  public boolean isSet() {
+    return set;
+  }
+
+  public double getValue() {
+    return value;
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValue.java
deleted file mode 100644 (file)
index ad8f07d..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import javax.annotation.Nullable;
-import org.sonar.server.computation.task.projectanalysis.formula.Counter;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS;
-
-/**
- * Convenience class wrapping a double to compute the value of a MeasureVariation as an double and know it is has ever
- * been set.
- * <p>
- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily
- * creating using method {@link #newArray()}.
- * </p>
- */
-public class DoubleVariationValue {
-  private boolean set = false;
-  private double value = 0L;
-
-  /**
-   * @return the current DoubleVariationValue so that chained calls on a specific DoubleVariationValue instance can be done
-   */
-  public DoubleVariationValue increment(double increment) {
-    this.value += increment;
-    this.set = true;
-    return this;
-  }
-
-  /**
-   * @return the current DoubleVariationValue so that chained calls on a specific DoubleVariationValue instance can be done
-   */
-  public DoubleVariationValue increment(@Nullable DoubleVariationValue value) {
-    if (value != null && value.isSet()) {
-      increment(value.value);
-    }
-    return this;
-  }
-
-  public boolean isSet() {
-    return set;
-  }
-
-  public double getValue() {
-    return value;
-  }
-
-  /**
-   * Creates a new Array of {@link DoubleVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS},
-   * initialized with newly creates {@link DoubleVariationValue} instances.
-   */
-  public static Array newArray() {
-    return new Array();
-  }
-
-  public static class Array {
-    private final DoubleVariationValue[] values;
-
-    public Array() {
-      this.values = new DoubleVariationValue[MAX_NUMBER_OF_PERIODS];
-      for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) {
-        this.values[i] = new DoubleVariationValue();
-      }
-    }
-
-    public DoubleVariationValue get(Period period) {
-      return values[period.getIndex() - 1];
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array increment(Period period, double value) {
-      this.values[period.getIndex() - 1].increment(value);
-      return this;
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array incrementAll(Array source) {
-      for (int i = 0; i < this.values.length; i++) {
-        if (source.values[i].isSet()) {
-          this.values[i].increment(source.values[i]);
-        }
-      }
-      return this;
-    }
-
-    /**
-     * Creates a new MeasureVariations from the current array.
-     */
-    public Optional<MeasureVariations> toMeasureVariations() {
-      if (!isAnySet()) {
-        return Optional.absent();
-      }
-      Double[] variations = new Double[values.length];
-      for (int i = 0; i < values.length; i++) {
-        if (values[i].isSet()) {
-          variations[i] = values[i].getValue();
-        }
-      }
-      return Optional.of(new MeasureVariations(variations));
-    }
-
-    private boolean isAnySet() {
-      for (DoubleVariationValue variationValue : values) {
-        if (variationValue.isSet()) {
-          return true;
-        }
-      }
-      return false;
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValue.java
new file mode 100644 (file)
index 0000000..8ba101c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import javax.annotation.Nullable;
+
+/**
+ * Convenience class wrapping an int to compute the value and know it is has ever been set.
+ */
+public class IntValue {
+  private boolean set = false;
+  private int value = 0;
+
+  /**
+   * @return the current {@link IntValue} so that chained calls on a specific {@link IntValue} instance can be done
+   */
+  public IntValue increment(int increment) {
+    this.value += increment;
+    this.set = true;
+    return this;
+  }
+
+  /**
+   * @return the current {@link IntValue} so that chained calls on a specific {@link IntValue} instance can be done
+   */
+  public IntValue increment(@Nullable IntValue value) {
+    if (value != null && value.isSet()) {
+      increment(value.value);
+    }
+    return this;
+  }
+
+  public boolean isSet() {
+    return set;
+  }
+
+  public int getValue() {
+    return value;
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValue.java
deleted file mode 100644 (file)
index 4c1f92c..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import javax.annotation.Nullable;
-import org.sonar.server.computation.task.projectanalysis.formula.Counter;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS;
-
-/**
- * Convenience class wrapping a int to compute the value of a MeasureVariation as an int and know it is has ever been
- * set.
- * <p>
- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily
- * creating using method {@link #newArray()}.
- * </p>
- */
-public class IntVariationValue {
-  private boolean set = false;
-  private int value = 0;
-
-  /**
-   * @return the current IntVariationValue so that chained calls on a specific IntVariationValue instance can be done
-   */
-  public IntVariationValue increment(int increment) {
-    this.value += increment;
-    this.set = true;
-    return this;
-  }
-
-  /**
-   * @return the current IntVariationValue so that chained calls on a specific IntVariationValue instance can be done
-   */
-  public IntVariationValue increment(@Nullable IntVariationValue value) {
-    if (value != null && value.isSet()) {
-      increment(value.value);
-    }
-    return this;
-  }
-
-  public boolean isSet() {
-    return set;
-  }
-
-  public int getValue() {
-    return value;
-  }
-
-  /**
-   * Creates a new Array of {@link IntVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS},
-   * initialized with newly creates {@link IntVariationValue} instances.
-   */
-  public static Array newArray() {
-    return new Array();
-  }
-
-  public static class Array {
-    private final IntVariationValue[] values;
-
-    public Array() {
-      this.values = new IntVariationValue[MAX_NUMBER_OF_PERIODS];
-      for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) {
-        this.values[i] = new IntVariationValue();
-      }
-    }
-
-    public IntVariationValue get(Period period) {
-      return values[period.getIndex() - 1];
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array increment(Period period, int value) {
-      this.values[period.getIndex() - 1].increment(value);
-      return this;
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array incrementAll(Array source) {
-      for (int i = 0; i < this.values.length; i++) {
-        if (source.values[i].isSet()) {
-          this.values[i].increment(source.values[i]);
-        }
-      }
-      return this;
-    }
-
-    /**
-     * Creates a new MeasureVariations from the current array.
-     */
-    public Optional<MeasureVariations> toMeasureVariations() {
-      if (!isAnySet()) {
-        return Optional.absent();
-      }
-      Double[] variations = new Double[values.length];
-      for (int i = 0; i < values.length; i++) {
-        if (values[i].isSet()) {
-          variations[i] = (double) values[i].getValue();
-        }
-      }
-      return Optional.of(new MeasureVariations(variations));
-    }
-
-    private boolean isAnySet() {
-      for (IntVariationValue variationValue : values) {
-        if (variationValue.isSet()) {
-          return true;
-        }
-      }
-      return false;
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValue.java
new file mode 100644 (file)
index 0000000..8cdd0d2
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import javax.annotation.Nullable;
+
+/**
+ * Convenience class wrapping a long to compute the value and know it is has ever been set.
+ */
+public class LongValue {
+  private boolean set = false;
+  private long value = 0L;
+
+  /**
+   * @return the current {@link LongValue} so that chained calls on a specific {@link LongValue} instance can be done
+   */
+  public LongValue increment(long increment) {
+    this.value += increment;
+    this.set = true;
+    return this;
+  }
+
+  /**
+   * @return the current {@link LongValue} so that chained calls on a specific {@link LongValue} instance can be done
+   */
+  public LongValue increment(@Nullable LongValue value) {
+    if (value != null && value.isSet()) {
+      increment(value.value);
+    }
+    return this;
+  }
+
+  public boolean isSet() {
+    return set;
+  }
+
+  public long getValue() {
+    return value;
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValue.java
deleted file mode 100644 (file)
index a53f1e3..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import javax.annotation.Nullable;
-import org.sonar.server.computation.task.projectanalysis.formula.Counter;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS;
-
-/**
- * Convenience class wrapping a long to compute the value of a MeasureVariation as an long and know it is has ever been
- * set.
- * <p>
- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily
- * creating using method {@link #newArray()}.
- * </p>
- */
-public class LongVariationValue {
-  private boolean set = false;
-  private long value = 0L;
-
-  /**
-   * @return the current LongVariationValue so that chained calls on a specific LongVariationValue instance can be done
-   */
-  public LongVariationValue increment(long increment) {
-    this.value += increment;
-    this.set = true;
-    return this;
-  }
-
-  /**
-   * @return the current LongVariationValue so that chained calls on a specific LongVariationValue instance can be done
-   */
-  public LongVariationValue increment(@Nullable LongVariationValue value) {
-    if (value != null && value.isSet()) {
-      increment(value.value);
-    }
-    return this;
-  }
-
-  public boolean isSet() {
-    return set;
-  }
-
-  public long getValue() {
-    return value;
-  }
-
-  /**
-   * Creates a new Array of {@link LongVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS},
-   * initialized with newly creates {@link LongVariationValue} instances.
-   */
-  public static Array newArray() {
-    return new Array();
-  }
-
-  public static class Array {
-    private final LongVariationValue[] values;
-
-    public Array() {
-      this.values = new LongVariationValue[MAX_NUMBER_OF_PERIODS];
-      for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) {
-        this.values[i] = new LongVariationValue();
-      }
-    }
-
-    public LongVariationValue get(Period period) {
-      return values[period.getIndex() - 1];
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array increment(Period period, long value) {
-      this.values[period.getIndex() - 1].increment(value);
-      return this;
-    }
-
-    /**
-     * @return the current Array, so that chained calls on a specific Array instance can be done
-     */
-    public Array incrementAll(Array source) {
-      for (int i = 0; i < this.values.length; i++) {
-        if (source.values[i].isSet()) {
-          this.values[i].increment(source.values[i]);
-        }
-      }
-      return this;
-    }
-
-    /**
-     * Creates a new MeasureVariations from the current array.
-     */
-    public Optional<MeasureVariations> toMeasureVariations() {
-      if (!isAnySet()) {
-        return Optional.absent();
-      }
-      Double[] variations = new Double[values.length];
-      for (int i = 0; i < values.length; i++) {
-        if (values[i].isSet()) {
-          variations[i] = (double) values[i].getValue();
-        }
-      }
-      return Optional.of(new MeasureVariations(variations));
-    }
-
-    private boolean isAnySet() {
-      for (LongVariationValue variationValue : values) {
-        if (variationValue.isSet()) {
-          return true;
-        }
-      }
-      return false;
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValue.java
new file mode 100644 (file)
index 0000000..bcafa64
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import javax.annotation.Nullable;
+import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
+
+/**
+ * Convenience class wrapping a rating to compute the value and know it is has ever been set.
+ */
+public class RatingValue {
+  private boolean set = false;
+  private Rating value = Rating.A;
+
+  /**
+   * @return the current {@link RatingValue}  so that chained calls on a specific {@link RatingValue} instance can be done
+   */
+  public RatingValue increment(Rating rating) {
+    if (value.compareTo(rating) > 0) {
+      value = rating;
+    }
+    this.set = true;
+    return this;
+  }
+
+  /**
+   * @return the current {@link RatingValue} so that chained calls on a specific {@link RatingValue} instance can be done
+   */
+  public RatingValue increment(@Nullable RatingValue value) {
+    if (value != null && value.isSet()) {
+      increment(value.value);
+    }
+    return this;
+  }
+
+  public boolean isSet() {
+    return set;
+  }
+
+  public Rating getValue() {
+    return value;
+  }
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValue.java
deleted file mode 100644 (file)
index 3535f8e..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import java.util.Arrays;
-import java.util.Optional;
-import javax.annotation.Nullable;
-import org.sonar.server.computation.task.projectanalysis.formula.Counter;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
-
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder.MAX_NUMBER_OF_PERIODS;
-
-/**
- * Convenience class wrapping a rating.
- * It also allows to compute the value of a MeasureVariation as a rating, and add a check to know if it is has ever been set.
- * <p>
- * Basically, this class will be used in a {@link Counter} implementation as an array property which can be easily
- * created using method {@link #newArray()}.
- * </p>
- */
-public class RatingVariationValue {
-  private boolean set = false;
-  private Rating value = Rating.A;
-
-  /**
-   * @return the current RatingVariationValue so that chained calls on a specific RatingVariationValue instance can be done
-   */
-  public RatingVariationValue increment(Rating rating) {
-    if (value.compareTo(rating) > 0) {
-      value = rating;
-    }
-    this.set = true;
-    return this;
-  }
-
-  /**
-   * @return the current RatingVariationValue so that chained calls on a specific RatingVariationValue instance can be done
-   */
-  public RatingVariationValue increment(@Nullable RatingVariationValue value) {
-    if (value != null && value.isSet()) {
-      increment(value.value);
-    }
-    return this;
-  }
-
-  public boolean isSet() {
-    return set;
-  }
-
-  public Rating getValue() {
-    return value;
-  }
-
-  /**
-   * Creates a new Array of {@link RatingVariationValue} of size {@link PeriodsHolder#MAX_NUMBER_OF_PERIODS},
-   * initialized with newly creates {@link RatingVariationValue} instances.
-   */
-  public static Array newArray() {
-    return new Array();
-  }
-
-  public static class Array {
-    private final RatingVariationValue[] values;
-
-    public Array() {
-      this.values = new RatingVariationValue[MAX_NUMBER_OF_PERIODS];
-      for (int i = 0; i < MAX_NUMBER_OF_PERIODS; i++) {
-        this.values[i] = new RatingVariationValue();
-      }
-    }
-
-    public RatingVariationValue get(Period period) {
-      return values[period.getIndex() - 1];
-    }
-
-    /**
-    * @return the current Array, so that chained calls on a specific Array instance can be done
-    */
-    public Array increment(Period period, Rating value) {
-      this.values[period.getIndex() - 1].increment(value);
-      return this;
-    }
-
-    /**
-    * @return the current Array, so that chained calls on a specific Array instance can be done
-    */
-    public Array incrementAll(Array source) {
-      for (int i = 0; i < this.values.length; i++) {
-        if (source.values[i].isSet()) {
-          this.values[i].increment(source.values[i]);
-        }
-      }
-      return this;
-    }
-
-    /**
-    * Creates a new MeasureVariations from the current array.
-    */
-    public Optional<MeasureVariations> toMeasureVariations() {
-      if (!isAnySet()) {
-        return Optional.empty();
-      }
-      Double[] variations = new Double[values.length];
-      for (int i = 0; i < values.length; i++) {
-        if (values[i].isSet()) {
-          variations[i] = (double) values[i].getValue().getIndex();
-        }
-      }
-      return Optional.of(new MeasureVariations(variations));
-    }
-
-    private boolean isAnySet() {
-      return Arrays.stream(values).anyMatch(RatingVariationValue::isSet);
-    }
-  }
-}
index b5b717c41ff697c0d421c4d05dce867b5c15b8d6..44f8c3dbc2789823e250eb0e25b3398183243df6 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage;
 import com.google.common.base.Optional;
 import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext;
 import org.sonar.server.computation.task.projectanalysis.formula.Formula;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.LongValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 
 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.calculateCoverage;
@@ -36,9 +36,9 @@ public abstract class CoverageVariationFormula<T extends ElementsAndCoveredEleme
 
   @Override
   public Optional<Measure> createMeasure(T counter, CreateMeasureContext context) {
-    LongVariationValue elements = counter.elements;
+    LongValue elements = counter.elements;
     if (elements.isSet() && elements.getValue() > 0d) {
-      LongVariationValue coveredElements = counter.coveredElements;
+      LongValue coveredElements = counter.coveredElements;
       double variation = calculateCoverage(coveredElements.getValue(), elements.getValue());
       return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue());
     }
index 5c41fa06079bec1ca712337f089cc61686d6205d..b833c1ed0efa6a0de840b4b3b26e6d9869ecbda9 100644 (file)
@@ -22,14 +22,14 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.formula.Counter;
 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.LongValue;
 
 /**
  * A counter used to create measure variations which are based on a count of elements and coveredElements.
  */
 public abstract class ElementsAndCoveredElementsVariationCounter implements Counter<ElementsAndCoveredElementsVariationCounter> {
-  protected final LongVariationValue elements = new LongVariationValue();
-  protected final LongVariationValue coveredElements = new LongVariationValue();
+  protected final LongValue elements = new LongValue();
+  protected final LongValue coveredElements = new LongValue();
 
   @Override
   public void aggregate(ElementsAndCoveredElementsVariationCounter counter) {
index 80a340eb1d327ce0eaafdfc981726176c1bf2215..b6046375fe2224b977b3268cd3bea17ae50ed559 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
@@ -155,8 +155,8 @@ public class MaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<Main
 
   public static final class Counter {
     private long devCosts = 0;
-    private RatingVariationValue reliabilityRating = new RatingVariationValue();
-    private RatingVariationValue securityRating = new RatingVariationValue();
+    private RatingValue reliabilityRating = new RatingValue();
+    private RatingValue securityRating = new RatingValue();
 
     private Counter() {
       // prevents instantiation
index ce08f62c41605b5bdf13b50013e7c5e1d9c83c0c..cb91579d406271cb17c88b874ba261afb6da46ba 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.LongValue;
 import org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
@@ -127,7 +127,7 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
   }
 
   private static double computeDensity(Counter counter) {
-    LongVariationValue newDebt = counter.getNewDebt();
+    LongValue newDebt = counter.getNewDebt();
     if (newDebt.isSet()) {
       long developmentCost = counter.getDevCost().getValue();
       if (developmentCost != 0L) {
@@ -217,27 +217,27 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter<N
   }
 
   public static final class Counter {
-    private final LongVariationValue newDebt = new LongVariationValue();
-    private final LongVariationValue devCost = new LongVariationValue();
+    private final LongValue newDebt = new LongValue();
+    private final LongValue devCost = new LongValue();
 
     public void add(Counter counter) {
       this.newDebt.increment(counter.newDebt);
       this.devCost.increment(counter.devCost);
     }
 
-    LongVariationValue incrementNewDebt(long value) {
+    LongValue incrementNewDebt(long value) {
       return newDebt.increment(value);
     }
 
-    LongVariationValue incrementDevCost(long value) {
+    LongValue incrementDevCost(long value) {
       return devCost.increment(value);
     }
 
-    LongVariationValue getNewDebt() {
+    LongValue getNewDebt() {
       return this.newDebt;
     }
 
-    LongVariationValue getDevCost() {
+    LongValue getDevCost() {
       return this.devCost;
     }
   }
index 64b09fce28d7e1cd54835229f4f04a8a2287a35e..c9aa477a7bab4a210d3dff68794000323017202c 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingValue;
 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
@@ -143,9 +143,9 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis
   }
 
   static final class Counter {
-    private Map<String, RatingVariationValue> newRatingValueByMetric = ImmutableMap.of(
-      NEW_RELIABILITY_RATING_KEY, new RatingVariationValue(),
-      NEW_SECURITY_RATING_KEY, new RatingVariationValue());
+    private Map<String, RatingValue> newRatingValueByMetric = ImmutableMap.of(
+      NEW_RELIABILITY_RATING_KEY, new RatingValue(),
+      NEW_SECURITY_RATING_KEY, new RatingValue());
 
     private Counter() {
       // prevents instantiation
index 6fd0994cb071b4ff9d0948c825bc74c54498fca0..f3adfbc6ea949039055e802c830b0ca69d8be655 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.ce.measure.Issue;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.RatingValue;
 import org.sonar.server.computation.task.projectanalysis.issue.ComponentIssuesRepository;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
@@ -135,9 +135,9 @@ public class ReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVisito
   }
 
   static final class Counter {
-    private Map<String, RatingVariationValue> ratingValueByMetric = ImmutableMap.of(
-      RELIABILITY_RATING_KEY, new RatingVariationValue(),
-      SECURITY_RATING_KEY, new RatingVariationValue());
+    private Map<String, RatingValue> ratingValueByMetric = ImmutableMap.of(
+      RELIABILITY_RATING_KEY, new RatingValue(),
+      SECURITY_RATING_KEY, new RatingValue());
 
     private Counter() {
       // prevents instantiation
index b2ca9560fc63c07e31361234e939fe51f7b270ff..94eb9493bbbca41a84e8800152e3d15eb4e05851 100644 (file)
@@ -40,7 +40,7 @@ import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureCo
 import org.sonar.server.computation.task.projectanalysis.formula.Formula;
 import org.sonar.server.computation.task.projectanalysis.formula.FormulaExecutorComponentVisitor;
 import org.sonar.server.computation.task.projectanalysis.formula.VariationSumFormula;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue;
 import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
 import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredVariationFormula;
 import org.sonar.server.computation.task.projectanalysis.formula.coverage.SingleWithUncoveredMetricKeys;
@@ -227,10 +227,10 @@ public class NewCoverageMeasuresStep implements ComputationStep {
   }
 
   public static final class NewCoverageCounter implements org.sonar.server.computation.task.projectanalysis.formula.Counter<NewCoverageCounter> {
-    private final IntVariationValue newLines = new IntVariationValue();
-    private final IntVariationValue newCoveredLines = new IntVariationValue();
-    private final IntVariationValue newConditions = new IntVariationValue();
-    private final IntVariationValue newCoveredConditions = new IntVariationValue();
+    private final IntValue newLines = new IntValue();
+    private final IntValue newCoveredLines = new IntValue();
+    private final IntValue newConditions = new IntValue();
+    private final IntValue newCoveredConditions = new IntValue();
     private final ScmInfoRepository scmInfoRepository;
     private final NewCoverageInputMetricKeys metricKeys;
 
index 5728fd552c3a369d113d1e9bb09ffc10dc92fb3a..d54ae239dfa393aed634b91cb3b2673d7a7a8eaa 100644 (file)
@@ -39,7 +39,7 @@ import org.sonar.server.computation.task.projectanalysis.formula.CounterInitiali
 import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext;
 import org.sonar.server.computation.task.projectanalysis.formula.Formula;
 import org.sonar.server.computation.task.projectanalysis.formula.FormulaExecutorComponentVisitor;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
@@ -92,9 +92,9 @@ public class NewSizeMeasuresStep implements ComputationStep {
   private static class NewSizeCounter implements Counter<NewSizeCounter> {
     private final DuplicationRepository duplicationRepository;
     private final ScmInfoRepository scmInfoRepository;
-    private final IntVariationValue newLines = new IntVariationValue();
-    private final IntVariationValue newDuplicatedLines = new IntVariationValue();
-    private final IntVariationValue newDuplicatedBlocks = new IntVariationValue();
+    private final IntValue newLines = new IntValue();
+    private final IntValue newDuplicatedLines = new IntValue();
+    private final IntValue newDuplicatedBlocks = new IntValue();
 
     private NewSizeCounter(DuplicationRepository duplicationRepository,
       ScmInfoRepository scmInfoRepository) {
@@ -224,15 +224,15 @@ public class NewSizeMeasuresStep implements ComputationStep {
       }
     }
 
-    private static Optional<Measure> createMeasure(IntVariationValue intValue) {
+    private static Optional<Measure> createMeasure(IntValue intValue) {
       return intValue.isSet()
         ? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue())
         : Optional.absent();
     }
 
     private static Optional<Measure> createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter) {
-      IntVariationValue newLines = counter.newLines;
-      IntVariationValue newDuplicatedLines = counter.newDuplicatedLines;
+      IntValue newLines = counter.newLines;
+      IntValue newDuplicatedLines = counter.newDuplicatedLines;
       if (newLines.isSet() && newDuplicatedLines.isSet()) {
         int newLinesVariations = newLines.getValue();
         int newDuplicatedLinesVariations = newDuplicatedLines.getValue();
index 8cccff51454457cf529aa8d420a07017ae3d3998..3437d47c9bd20b2563e52f13e716f2948b5621f6 100644 (file)
@@ -28,10 +28,9 @@ import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler;
 import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
@@ -90,8 +89,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
   @Rule
   public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
   @Rule
-  public PeriodsHolderRule periodsHolder = new PeriodsHolderRule()
-    .setPeriods(new Period(2, "some mode", null, 95l, "756l"), new Period(5, "some other mode", null, 756L, "956L"));
+  public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod(new Period("some mode", null, 95l, "756l"));
 
   @Test
   public void verify_aggregation_on_value() throws Exception {
@@ -152,24 +150,24 @@ public class ReportFormulaExecutorComponentVisitorTest {
   }
 
   @Test
-  public void verify_aggregation_on_variations() throws Exception {
+  public void verify_aggregation_on_variation() throws Exception {
     treeRootHolder.setRoot(BALANCED_COMPONENT_TREE);
 
-    measureRepository.addRawMeasure(FILE_1_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(10, 20));
-    measureRepository.addRawMeasure(FILE_2_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(8, 16));
-    measureRepository.addRawMeasure(FILE_3_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(2, 4));
+    measureRepository.addRawMeasure(FILE_1_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(10));
+    measureRepository.addRawMeasure(FILE_2_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(8));
+    measureRepository.addRawMeasure(FILE_3_REF, NEW_LINES_TO_COVER_KEY, createMeasureWithVariation(2));
 
     new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula()))
       .visit(BALANCED_COMPONENT_TREE);
 
-    assertAddedRawMeasure(ROOT_REF, 20, 40);
-    assertAddedRawMeasure(MODULE_1_REF, 18, 36);
-    assertAddedRawMeasure(DIRECTORY_1_REF, 18, 36);
-    assertAddedRawMeasure(FILE_1_REF, 10, 20);
-    assertAddedRawMeasure(FILE_2_REF, 8, 16);
-    assertAddedRawMeasure(MODULE_2_REF, 2, 4);
-    assertAddedRawMeasure(DIRECTORY_2_REF, 2, 4);
-    assertAddedRawMeasure(FILE_3_REF, 2, 4);
+    assertAddedRawMeasureVariation(ROOT_REF, 20);
+    assertAddedRawMeasureVariation(MODULE_1_REF, 18);
+    assertAddedRawMeasureVariation(DIRECTORY_1_REF, 18);
+    assertAddedRawMeasureVariation(FILE_1_REF, 10);
+    assertAddedRawMeasureVariation(FILE_2_REF, 8);
+    assertAddedRawMeasureVariation(MODULE_2_REF, 2);
+    assertAddedRawMeasureVariation(DIRECTORY_2_REF, 2);
+    assertAddedRawMeasureVariation(FILE_3_REF, 2);
   }
 
   @Test
@@ -219,17 +217,17 @@ public class ReportFormulaExecutorComponentVisitorTest {
       .buildFor(ImmutableList.of(formula));
   }
 
-  private static Measure createMeasureWithVariation(double variation2Value, double variation5Value) {
-    return newMeasureBuilder().setVariations(new MeasureVariations(null, variation2Value, null, null, variation5Value)).createNoValue();
+  private static Measure createMeasureWithVariation(double variation) {
+    return newMeasureBuilder().setVariation(variation).createNoValue();
   }
 
   private void assertAddedRawMeasure(int componentRef, int expectedValue) {
     assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef))).containsOnly(entryOf(NCLOC_KEY, newMeasureBuilder().create(expectedValue)));
   }
 
-  private void assertAddedRawMeasure(int componentRef, int variation2Value, int variation5Value) {
+  private void assertAddedRawMeasureVariation(int componentRef, int variation) {
     assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
-      .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation2Value, variation5Value)));
+      .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation)));
   }
 
   private class FakeFormula implements Formula<FakeCounter> {
@@ -265,7 +263,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
     @Override
     public Optional<Measure> createMeasure(FakeCounter counter, CreateMeasureContext context) {
       // verify the context which is passed to the method
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
       assertThat(context.getComponent()).isNotNull();
       assertThat(context.getMetric())
         .isIn(metricRepository.getByKey(NEW_LINES_TO_COVER_KEY), metricRepository.getByKey(NEW_COVERAGE_KEY));
@@ -301,7 +299,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
     public void initialize(CounterInitializationContext context) {
       // verify the context which is passed to the method
       assertThat(context.getLeaf().getChildren()).isEmpty();
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
 
       Optional<Measure> measureOptional = context.getMeasure(LINES_KEY);
       if (measureOptional.isPresent()) {
@@ -320,15 +318,15 @@ public class ReportFormulaExecutorComponentVisitorTest {
     @Override
     public Optional<Measure> createMeasure(FakeVariationCounter counter, CreateMeasureContext context) {
       // verify the context which is passed to the method
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
       assertThat(context.getComponent()).isNotNull();
       assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NEW_COVERAGE_KEY));
 
-      Optional<MeasureVariations> measureVariations = counter.values.toMeasureVariations();
-      if (measureVariations.isPresent()) {
+      IntValue measureVariations = counter.values;
+      if (measureVariations.isSet()) {
         return Optional.of(
           newMeasureBuilder()
-            .setVariations(measureVariations.get())
+            .setVariation(measureVariations.getValue())
             .createNoValue());
       }
       return Optional.absent();
@@ -341,28 +339,24 @@ public class ReportFormulaExecutorComponentVisitorTest {
   }
 
   private class FakeVariationCounter implements Counter<FakeVariationCounter> {
-    private final IntVariationValue.Array values = IntVariationValue.newArray();
+    private final IntValue values = new IntValue();
 
     @Override
     public void aggregate(FakeVariationCounter counter) {
-      values.incrementAll(counter.values);
+      values.increment(counter.values);
     }
 
     @Override
     public void initialize(CounterInitializationContext context) {
       // verify the context which is passed to the method
       assertThat(context.getLeaf().getChildren()).isEmpty();
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
 
       Optional<Measure> measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY);
-      if (!measureOptional.isPresent()) {
+      if (!measureOptional.isPresent() || !context.hasPeriod()) {
         return;
       }
-      for (Period period : context.getPeriods()) {
-        this.values.increment(
-          period,
-          (int) measureOptional.get().getVariations().getVariation(period.getIndex()));
-      }
+      this.values.increment((int) measureOptional.get().getVariation());
     }
   }
 
index 0bb77e1239af3eadbfbd9c525ee50d3a3cff4f50..3adeb437b3d240e4620b9a4fee9c7910d7a43d7c 100644 (file)
@@ -28,11 +28,10 @@ import org.sonar.api.measures.CoreMetrics;
 import org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler;
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
 import org.sonar.server.computation.task.projectanalysis.component.ViewsComponent;
-import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue;
+import org.sonar.server.computation.task.projectanalysis.formula.counter.IntValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
@@ -90,8 +89,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
   @Rule
   public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
   @Rule
-  public PeriodsHolderRule periodsHolder = new PeriodsHolderRule()
-    .setPeriods(new Period(2, "some mode", null, 95l, "u1"), new Period(5, "some other mode", null, 756L, "u2"));
+  public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod(new Period("some mode", null, 95l, "u1"));
 
   @Test
   public void verify_aggregation_on_value() throws Exception {
@@ -137,33 +135,32 @@ public class ViewsFormulaExecutorComponentVisitorTest {
   public void verify_aggregation_on_variations() throws Exception {
     treeRootHolder.setRoot(BALANCED_COMPONENT_TREE);
 
-    addRawMeasureWithVariation(PROJECT_VIEW_1_REF, NEW_LINES_TO_COVER_KEY, 10, 20);
-    addRawMeasureWithVariation(PROJECT_VIEW_2_REF, NEW_LINES_TO_COVER_KEY, 8, 16);
-    addRawMeasureWithVariation(PROJECT_VIEW_3_REF, NEW_LINES_TO_COVER_KEY, 2, 4);
-    addRawMeasureWithVariation(PROJECT_VIEW_4_REF, NEW_LINES_TO_COVER_KEY, 3, 7);
+    addRawMeasureWithVariation(PROJECT_VIEW_1_REF, NEW_LINES_TO_COVER_KEY, 10);
+    addRawMeasureWithVariation(PROJECT_VIEW_2_REF, NEW_LINES_TO_COVER_KEY, 8);
+    addRawMeasureWithVariation(PROJECT_VIEW_3_REF, NEW_LINES_TO_COVER_KEY, 2);
+    addRawMeasureWithVariation(PROJECT_VIEW_4_REF, NEW_LINES_TO_COVER_KEY, 3);
 
     new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeVariationFormula()))
       .visit(BALANCED_COMPONENT_TREE);
 
     verifyProjectViewsHasNoAddedRawMeasures();
-    verifySingleMetricWithVariations(SUB_SUBVIEW_REF, 18, 36);
-    verifySingleMetricWithVariations(SUBVIEW_1_REF, 18, 36);
-    verifySingleMetricWithVariations(SUBVIEW_2_REF, 2, 4);
-    verifySingleMetricWithVariations(ROOT_REF, 23, 47);
+    verifySingleMetricWithVariation(SUB_SUBVIEW_REF, 18);
+    verifySingleMetricWithVariation(SUBVIEW_1_REF, 18);
+    verifySingleMetricWithVariation(SUBVIEW_2_REF, 2);
+    verifySingleMetricWithVariation(ROOT_REF, 23);
   }
 
-  private AbstractIterableAssert<?, ? extends Iterable<? extends MeasureRepoEntry>, MeasureRepoEntry> verifySingleMetricWithVariations(int componentRef, int variation2Value,
-    int variation5Value) {
+  private AbstractIterableAssert<?, ? extends Iterable<? extends MeasureRepoEntry>, MeasureRepoEntry> verifySingleMetricWithVariation(int componentRef, int variation) {
     return assertThat(toEntries(measureRepository.getAddedRawMeasures(componentRef)))
-      .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation2Value, variation5Value)));
+      .containsOnly(entryOf(NEW_COVERAGE_KEY, createMeasureWithVariation(variation)));
   }
 
-  private MeasureRepositoryRule addRawMeasureWithVariation(int componentRef, String metricKey, int variation2Value, int variation5Value) {
-    return measureRepository.addRawMeasure(componentRef, metricKey, createMeasureWithVariation(variation2Value, variation5Value));
+  private MeasureRepositoryRule addRawMeasureWithVariation(int componentRef, String metricKey, int variation) {
+    return measureRepository.addRawMeasure(componentRef, metricKey, createMeasureWithVariation(variation));
   }
 
-  private static Measure createMeasureWithVariation(double variation2Value, double variation5Value) {
-    return newMeasureBuilder().setVariations(new MeasureVariations(null, variation2Value, null, null, variation5Value)).createNoValue();
+  private static Measure createMeasureWithVariation(double variation) {
+    return newMeasureBuilder().setVariation(variation).createNoValue();
   }
 
   @Test
@@ -218,7 +215,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
     @Override
     public Optional<Measure> createMeasure(FakeCounter counter, CreateMeasureContext context) {
       // verify the context which is passed to the method
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
       assertThat(context.getComponent()).isNotNull();
       assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NCLOC_KEY));
 
@@ -241,7 +238,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
     @Override
     public Optional<Measure> createMeasure(FakeCounter counter, CreateMeasureContext context) {
       // verify the context which is passed to the method
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
       assertThat(context.getComponent()).isNotNull();
       assertThat(context.getMetric())
         .isIn(metricRepository.getByKey(NEW_LINES_TO_COVER_KEY), metricRepository.getByKey(NEW_COVERAGE_KEY));
@@ -294,15 +291,15 @@ public class ViewsFormulaExecutorComponentVisitorTest {
     @Override
     public Optional<Measure> createMeasure(FakeVariationCounter counter, CreateMeasureContext context) {
       // verify the context which is passed to the method
-      assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+      assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
       assertThat(context.getComponent()).isNotNull();
       assertThat(context.getMetric()).isSameAs(metricRepository.getByKey(NEW_COVERAGE_KEY));
 
-      Optional<MeasureVariations> measureVariations = counter.values.toMeasureVariations();
-      if (measureVariations.isPresent()) {
+      IntValue measureVariations = counter.values;
+      if (measureVariations.isSet()) {
         return Optional.of(
           newMeasureBuilder()
-            .setVariations(measureVariations.get())
+            .setVariation(measureVariations.getValue())
             .createNoValue());
       }
       return Optional.absent();
@@ -315,11 +312,11 @@ public class ViewsFormulaExecutorComponentVisitorTest {
   }
 
   private class FakeVariationCounter implements Counter<FakeVariationCounter> {
-    private final IntVariationValue.Array values = IntVariationValue.newArray();
+    private final IntValue values = new IntValue();
 
     @Override
     public void aggregate(FakeVariationCounter counter) {
-      values.incrementAll(counter.values);
+      values.increment(counter.values);
     }
 
     @Override
@@ -327,15 +324,12 @@ public class ViewsFormulaExecutorComponentVisitorTest {
       verifyLeafContext(context);
 
       Optional<Measure> measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY);
-      if (!measureOptional.isPresent()) {
+      if (!measureOptional.isPresent() || !context.hasPeriod()) {
         return;
       }
-      for (Period period : context.getPeriods()) {
-        this.values.increment(
-          period,
-          (int) measureOptional.get().getVariations().getVariation(period.getIndex()));
-      }
+      this.values.increment((int) measureOptional.get().getVariation());
     }
+
   }
 
   private FormulaExecutorComponentVisitor formulaExecutorComponentVisitor(Formula formula) {
@@ -369,7 +363,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
 
   private void verifyLeafContext(CounterInitializationContext context) {
     assertThat(context.getLeaf().getChildren()).isEmpty();
-    assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+    assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
   }
 
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleValueTest.java
new file mode 100644 (file)
index 0000000..3149c4b
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DoubleValueTest {
+  @Test
+  public void newly_created_DoubleVariationValue_is_unset_and_has_value_0() {
+    verifyUnsetVariationValue(new DoubleValue());
+  }
+
+  @Test
+  public void increment_double_sets_DoubleVariationValue_and_increments_value() {
+    verifySetVariationValue(new DoubleValue().increment(10.6), 10.6);
+  }
+
+  @Test
+  public void increment_DoubleVariationValue_has_no_effect_if_arg_is_null() {
+    verifyUnsetVariationValue(new DoubleValue().increment(null));
+  }
+
+  @Test
+  public void increment_DoubleVariationValue_has_no_effect_if_arg_is_unset() {
+    verifyUnsetVariationValue(new DoubleValue().increment(new DoubleValue()));
+  }
+
+  @Test
+  public void increment_DoubleVariationValue_increments_by_the_value_of_the_arg() {
+    DoubleValue source = new DoubleValue().increment(10);
+    DoubleValue target = new DoubleValue().increment(source);
+
+    verifySetVariationValue(target, 10);
+  }
+
+  @Test
+  public void multiple_calls_to_increment_DoubleVariationValue_increments_by_the_value_of_the_arg() {
+    DoubleValue target = new DoubleValue()
+      .increment(new DoubleValue().increment(35))
+      .increment(new DoubleValue().increment(10));
+
+    verifySetVariationValue(target, 45);
+  }
+
+  @Test
+  public void multiples_calls_to_increment_double_increment_the_value() {
+    DoubleValue variationValue = new DoubleValue()
+      .increment(10.6)
+      .increment(95.4);
+
+    verifySetVariationValue(variationValue, 106);
+  }
+
+  private static void verifyUnsetVariationValue(DoubleValue variationValue) {
+    assertThat(variationValue.isSet()).isFalse();
+    assertThat(variationValue.getValue()).isEqualTo(0);
+  }
+
+  private static void verifySetVariationValue(DoubleValue variationValue, double expected) {
+    assertThat(variationValue.isSet()).isTrue();
+    assertThat(variationValue.getValue()).isEqualTo(expected);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueArrayTest.java
deleted file mode 100644 (file)
index 1949be1..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
-
-public class DoubleVariationValueArrayTest {
-  private static final List<Period> PERIODS;
-
-  static {
-    ImmutableList.Builder<Period> builder = ImmutableList.builder();
-    for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) {
-      builder.add(createPeriod(i));
-    }
-    PERIODS = builder.build();
-  }
-
-  @Test
-  public void newArray_always_returns_a_new_instance() {
-    assertThat(DoubleVariationValue.newArray()).isNotSameAs(DoubleVariationValue.newArray());
-  }
-
-  @Test
-  public void get_returns_unset_DoubleVariationValue_for_each_Period_index() {
-    DoubleVariationValue.Array array = DoubleVariationValue.newArray();
-    for (Period period : PERIODS) {
-      DoubleVariationValue value = array.get(period);
-      verifyUnsetVariationValue(value);
-    }
-  }
-
-  @Test
-  public void get_returns_set_DoubleVariationValue_for_each_Period_index_if_increment_has_been_called() {
-    DoubleVariationValue.Array array = DoubleVariationValue.newArray();
-    for (Period period : PERIODS) {
-      array.increment(period, 66.66);
-      DoubleVariationValue value = array.get(period);
-      verifySetDoubleVariation(value, 66.66);
-    }
-  }
-
-  @Test
-  public void incrementAll_increments_internals_from_all_set_DoubleVariationValue_from_source() {
-    DoubleVariationValue.Array source = DoubleVariationValue.newArray()
-      .increment(createPeriod(2), 20.6)
-      .increment(createPeriod(5), 5.5);
-
-    DoubleVariationValue.Array target = DoubleVariationValue.newArray()
-      .increment(createPeriod(1), 1.7)
-      .increment(createPeriod(5), 30.5);
-    target.incrementAll(source);
-
-    verifySetDoubleVariation(target.get(createPeriod(1)), 1.7);
-    verifySetDoubleVariation(target.get(createPeriod(2)), 20.6);
-    verifyUnsetVariationValue(target.get(createPeriod(3)));
-    verifyUnsetVariationValue(target.get(createPeriod(4)));
-    verifySetDoubleVariation(target.get(createPeriod(5)), 36);
-  }
-
-  @Test
-  public void toMeasureVariations_returns_absent_if_no_DoubleVariationValue_has_been_set() {
-    assertThat(DoubleVariationValue.newArray().toMeasureVariations()).isAbsent();
-  }
-
-  @Test
-  public void toMeasureVariations_returns_value_of_set_DoubleVariationValue_as_double() {
-    Optional<MeasureVariations> variationsOptional = DoubleVariationValue.newArray()
-      .increment(createPeriod(2), 2.6)
-      .increment(createPeriod(5), 15.9)
-      .toMeasureVariations();
-
-    assertThat(variationsOptional).isPresent();
-    MeasureVariations variations = variationsOptional.get();
-    assertThat(variations.hasVariation1()).isFalse();
-    assertThat(variations.getVariation2()).isEqualTo(2.6d);
-    assertThat(variations.hasVariation3()).isFalse();
-    assertThat(variations.hasVariation4()).isFalse();
-    assertThat(variations.getVariation5()).isEqualTo(15.9d);
-  }
-
-  private static void verifyUnsetVariationValue(DoubleVariationValue value) {
-    assertThat(value.isSet()).isFalse();
-    assertThat(value.getValue()).isEqualTo(0);
-  }
-
-  private static void verifySetDoubleVariation(DoubleVariationValue value, double expectedValue) {
-    assertThat(value.isSet()).isTrue();
-    assertThat(value.getValue()).isEqualTo(expectedValue);
-  }
-
-  private static Period createPeriod(int i) {
-    return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i));
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/DoubleVariationValueTest.java
deleted file mode 100644 (file)
index 8964971..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class DoubleVariationValueTest {
-  @Test
-  public void newly_created_DoubleVariationValue_is_unset_and_has_value_0() {
-    verifyUnsetVariationValue(new DoubleVariationValue());
-  }
-
-  @Test
-  public void increment_double_sets_DoubleVariationValue_and_increments_value() {
-    verifySetVariationValue(new DoubleVariationValue().increment(10.6), 10.6);
-  }
-
-  @Test
-  public void increment_DoubleVariationValue_has_no_effect_if_arg_is_null() {
-    verifyUnsetVariationValue(new DoubleVariationValue().increment(null));
-  }
-
-  @Test
-  public void increment_DoubleVariationValue_has_no_effect_if_arg_is_unset() {
-    verifyUnsetVariationValue(new DoubleVariationValue().increment(new DoubleVariationValue()));
-  }
-
-  @Test
-  public void increment_DoubleVariationValue_increments_by_the_value_of_the_arg() {
-    DoubleVariationValue source = new DoubleVariationValue().increment(10);
-    DoubleVariationValue target = new DoubleVariationValue().increment(source);
-
-    verifySetVariationValue(target, 10);
-  }
-
-  @Test
-  public void multiple_calls_to_increment_DoubleVariationValue_increments_by_the_value_of_the_arg() {
-    DoubleVariationValue target = new DoubleVariationValue()
-      .increment(new DoubleVariationValue().increment(35))
-      .increment(new DoubleVariationValue().increment(10));
-
-    verifySetVariationValue(target, 45);
-  }
-
-  @Test
-  public void multiples_calls_to_increment_double_increment_the_value() {
-    DoubleVariationValue variationValue = new DoubleVariationValue()
-      .increment(10.6)
-      .increment(95.4);
-
-    verifySetVariationValue(variationValue, 106);
-  }
-
-  private static void verifyUnsetVariationValue(DoubleVariationValue variationValue) {
-    assertThat(variationValue.isSet()).isFalse();
-    assertThat(variationValue.getValue()).isEqualTo(0);
-  }
-
-  private static void verifySetVariationValue(DoubleVariationValue variationValue, double expected) {
-    assertThat(variationValue.isSet()).isTrue();
-    assertThat(variationValue.getValue()).isEqualTo(expected);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntValueTest.java
new file mode 100644 (file)
index 0000000..5718c4e
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class IntValueTest {
+  @Test
+  public void newly_created_IntVariationValue_is_unset_and_has_value_0() {
+    verifyUnsetVariationValue(new IntValue());
+  }
+
+  @Test
+  public void increment_int_sets_IntVariationValue_and_increments_value() {
+    verifySetVariationValue(new IntValue().increment(10), 10);
+  }
+
+  @Test
+  public void increment_IntVariationValue_has_no_effect_if_arg_is_null() {
+    verifyUnsetVariationValue(new IntValue().increment(null));
+  }
+
+  @Test
+  public void increment_IntVariationValue_has_no_effect_if_arg_is_unset() {
+    verifyUnsetVariationValue(new IntValue().increment(new IntValue()));
+  }
+
+  @Test
+  public void increment_IntVariationValue_increments_by_the_value_of_the_arg() {
+    IntValue source = new IntValue().increment(10);
+    IntValue target = new IntValue().increment(source);
+
+    verifySetVariationValue(target, 10);
+  }
+
+  @Test
+  public void multiple_calls_to_increment_IntVariationValue_increments_by_the_value_of_the_arg() {
+    IntValue target = new IntValue()
+      .increment(new IntValue().increment(35))
+      .increment(new IntValue().increment(10));
+
+    verifySetVariationValue(target, 45);
+  }
+
+  @Test
+  public void multiples_calls_to_increment_int_increment_the_value() {
+    IntValue variationValue = new IntValue()
+      .increment(10)
+      .increment(95);
+
+    verifySetVariationValue(variationValue, 105);
+  }
+
+  private static void verifyUnsetVariationValue(IntValue variationValue) {
+    assertThat(variationValue.isSet()).isFalse();
+    assertThat(variationValue.getValue()).isEqualTo(0);
+  }
+
+  private static void verifySetVariationValue(IntValue variationValue, int expected) {
+    assertThat(variationValue.isSet()).isTrue();
+    assertThat(variationValue.getValue()).isEqualTo(expected);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueArrayTest.java
deleted file mode 100644 (file)
index 25aa126..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
-
-public class IntVariationValueArrayTest {
-  private static final List<Period> PERIODS;
-
-  static {
-    ImmutableList.Builder<Period> builder = ImmutableList.builder();
-    for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) {
-      builder.add(createPeriod(i));
-    }
-    PERIODS = builder.build();
-  }
-
-  @Test
-  public void newArray_always_returns_a_new_instance() {
-    assertThat(IntVariationValue.newArray()).isNotSameAs(IntVariationValue.newArray());
-  }
-
-  @Test
-  public void get_returns_unset_IntVariationValue_for_each_Period_index() {
-    IntVariationValue.Array array = IntVariationValue.newArray();
-    for (Period period : PERIODS) {
-      IntVariationValue value = array.get(period);
-      verifyUnsetVariationValue(value);
-    }
-  }
-
-  @Test
-  public void get_returns_set_IntVariationValue_for_each_Period_index_if_increment_has_been_called() {
-    IntVariationValue.Array array = IntVariationValue.newArray();
-    for (Period period : PERIODS) {
-      array.increment(period, 66);
-      IntVariationValue value = array.get(period);
-      verifySetVariationValue(value, 66);
-    }
-  }
-
-  @Test
-  public void incrementAll_increments_internals_from_all_set_IntVariationValue_from_source() {
-    IntVariationValue.Array source = IntVariationValue.newArray()
-      .increment(createPeriod(2), 20)
-      .increment(createPeriod(5), 5);
-
-    IntVariationValue.Array target = IntVariationValue.newArray()
-      .increment(createPeriod(1), 1)
-      .increment(createPeriod(5), 30);
-    target.incrementAll(source);
-
-    verifySetVariationValue(target.get(createPeriod(1)), 1);
-    verifySetVariationValue(target.get(createPeriod(2)), 20);
-    verifyUnsetVariationValue(target.get(createPeriod(3)));
-    verifyUnsetVariationValue(target.get(createPeriod(4)));
-    verifySetVariationValue(target.get(createPeriod(5)), 35);
-  }
-
-  @Test
-  public void toMeasureVariations_returns_absent_if_no_IntVariationValue_has_been_set() {
-    assertThat(IntVariationValue.newArray().toMeasureVariations()).isAbsent();
-  }
-
-  @Test
-  public void toMeasureVariations_returns_value_of_set_IntVariationValue_as_double() {
-    Optional<MeasureVariations> variationsOptional = IntVariationValue.newArray()
-      .increment(createPeriod(2), 2)
-      .increment(createPeriod(5), 15)
-      .toMeasureVariations();
-
-    assertThat(variationsOptional).isPresent();
-    MeasureVariations variations = variationsOptional.get();
-    assertThat(variations.hasVariation1()).isFalse();
-    assertThat(variations.getVariation2()).isEqualTo(2d);
-    assertThat(variations.hasVariation3()).isFalse();
-    assertThat(variations.hasVariation4()).isFalse();
-    assertThat(variations.getVariation5()).isEqualTo(15d);
-  }
-
-  private static void verifyUnsetVariationValue(IntVariationValue value) {
-    assertThat(value.isSet()).isFalse();
-    assertThat(value.getValue()).isEqualTo(0);
-  }
-
-  private static void verifySetVariationValue(IntVariationValue value, int expectedValue) {
-    assertThat(value.isSet()).isTrue();
-    assertThat(value.getValue()).isEqualTo(expectedValue);
-  }
-
-  private static Period createPeriod(int i) {
-    return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i));
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/IntVariationValueTest.java
deleted file mode 100644 (file)
index 7cca94f..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IntVariationValueTest {
-  @Test
-  public void newly_created_IntVariationValue_is_unset_and_has_value_0() {
-    verifyUnsetVariationValue(new IntVariationValue());
-  }
-
-  @Test
-  public void increment_int_sets_IntVariationValue_and_increments_value() {
-    verifySetVariationValue(new IntVariationValue().increment(10), 10);
-  }
-
-  @Test
-  public void increment_IntVariationValue_has_no_effect_if_arg_is_null() {
-    verifyUnsetVariationValue(new IntVariationValue().increment(null));
-  }
-
-  @Test
-  public void increment_IntVariationValue_has_no_effect_if_arg_is_unset() {
-    verifyUnsetVariationValue(new IntVariationValue().increment(new IntVariationValue()));
-  }
-
-  @Test
-  public void increment_IntVariationValue_increments_by_the_value_of_the_arg() {
-    IntVariationValue source = new IntVariationValue().increment(10);
-    IntVariationValue target = new IntVariationValue().increment(source);
-
-    verifySetVariationValue(target, 10);
-  }
-
-  @Test
-  public void multiple_calls_to_increment_IntVariationValue_increments_by_the_value_of_the_arg() {
-    IntVariationValue target = new IntVariationValue()
-      .increment(new IntVariationValue().increment(35))
-      .increment(new IntVariationValue().increment(10));
-
-    verifySetVariationValue(target, 45);
-  }
-
-  @Test
-  public void multiples_calls_to_increment_int_increment_the_value() {
-    IntVariationValue variationValue = new IntVariationValue()
-      .increment(10)
-      .increment(95);
-
-    verifySetVariationValue(variationValue, 105);
-  }
-
-  private static void verifyUnsetVariationValue(IntVariationValue variationValue) {
-    assertThat(variationValue.isSet()).isFalse();
-    assertThat(variationValue.getValue()).isEqualTo(0);
-  }
-
-  private static void verifySetVariationValue(IntVariationValue variationValue, int expected) {
-    assertThat(variationValue.isSet()).isTrue();
-    assertThat(variationValue.getValue()).isEqualTo(expected);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongValueTest.java
new file mode 100644 (file)
index 0000000..4c506df
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LongValueTest {
+  @Test
+  public void newly_created_LongVariationValue_is_unset_and_has_value_0() {
+    verifyUnsetVariationValue(new LongValue());
+  }
+
+  @Test
+  public void increment_long_sets_LongVariationValue_and_increments_value() {
+    verifySetVariationValue(new LongValue().increment(10L), 10L);
+  }
+
+  @Test
+  public void increment_LongVariationValue_has_no_effect_if_arg_is_null() {
+    verifyUnsetVariationValue(new LongValue().increment(null));
+  }
+
+  @Test
+  public void increment_LongVariationValue_has_no_effect_if_arg_is_unset() {
+    verifyUnsetVariationValue(new LongValue().increment(new LongValue()));
+  }
+
+  @Test
+  public void increment_LongVariationValue_increments_by_the_value_of_the_arg() {
+    LongValue source = new LongValue().increment(10L);
+    LongValue target = new LongValue().increment(source);
+
+    verifySetVariationValue(target, 10L);
+  }
+
+  @Test
+  public void multiple_calls_to_increment_LongVariationValue_increments_by_the_value_of_the_arg() {
+    LongValue target = new LongValue()
+      .increment(new LongValue().increment(35L))
+      .increment(new LongValue().increment(10L));
+
+    verifySetVariationValue(target, 45L);
+  }
+
+  @Test
+  public void multiples_calls_to_increment_long_increment_the_value() {
+    LongValue variationValue = new LongValue()
+      .increment(10L)
+      .increment(95L);
+
+    verifySetVariationValue(variationValue, 105L);
+  }
+
+  private static void verifyUnsetVariationValue(LongValue variationValue) {
+    assertThat(variationValue.isSet()).isFalse();
+    assertThat(variationValue.getValue()).isEqualTo(0L);
+  }
+
+  private static void verifySetVariationValue(LongValue variationValue, long expected) {
+    assertThat(variationValue.isSet()).isTrue();
+    assertThat(variationValue.getValue()).isEqualTo(expected);
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueArrayTest.java
deleted file mode 100644 (file)
index ea31e62..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
-
-public class LongVariationValueArrayTest {
-  private static final List<Period> PERIODS;
-
-  static {
-    ImmutableList.Builder<Period> builder = ImmutableList.builder();
-    for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) {
-      builder.add(createPeriod(i));
-    }
-    PERIODS = builder.build();
-  }
-
-  @Test
-  public void newArray_always_returns_a_new_instance() {
-    assertThat(LongVariationValue.newArray()).isNotSameAs(LongVariationValue.newArray());
-  }
-
-  @Test
-  public void get_returns_unset_LongVariationValue_for_each_Period_index() {
-    LongVariationValue.Array array = LongVariationValue.newArray();
-    for (Period period : PERIODS) {
-      LongVariationValue value = array.get(period);
-      verifyUnsetLongVariation(value);
-    }
-  }
-
-  @Test
-  public void get_returns_set_LongVariationValue_for_each_Period_index_if_increment_has_been_called() {
-    LongVariationValue.Array array = LongVariationValue.newArray();
-    for (Period period : PERIODS) {
-      array.increment(period, 66L);
-      LongVariationValue value = array.get(period);
-      verifySetLongVariation(value, 66L);
-    }
-  }
-
-  @Test
-  public void incrementAll_increments_internals_from_all_set_LongVariationValue_from_source() {
-    LongVariationValue.Array source = LongVariationValue.newArray()
-      .increment(createPeriod(2), 20l)
-      .increment(createPeriod(5), 5l);
-
-    LongVariationValue.Array target = LongVariationValue.newArray()
-      .increment(createPeriod(1), 1L)
-      .increment(createPeriod(5), 30L);
-    target.incrementAll(source);
-
-    verifySetLongVariation(target.get(createPeriod(1)), 1L);
-    verifySetLongVariation(target.get(createPeriod(2)), 20L);
-    verifyUnsetLongVariation(target.get(createPeriod(3)));
-    verifyUnsetLongVariation(target.get(createPeriod(4)));
-    verifySetLongVariation(target.get(createPeriod(5)), 35L);
-  }
-
-  @Test
-  public void toMeasureVariations_returns_absent_if_no_LongVariationValue_has_been_set() {
-    assertThat(LongVariationValue.newArray().toMeasureVariations()).isAbsent();
-  }
-
-  @Test
-  public void toMeasureVariations_returns_value_of_set_LongVariationValue_as_double() {
-    Optional<MeasureVariations> variationsOptional = LongVariationValue.newArray()
-      .increment(createPeriod(2), 2L)
-      .increment(createPeriod(5), 15L)
-      .toMeasureVariations();
-
-    assertThat(variationsOptional).isPresent();
-    MeasureVariations variations = variationsOptional.get();
-    assertThat(variations.hasVariation1()).isFalse();
-    assertThat(variations.getVariation2()).isEqualTo(2d);
-    assertThat(variations.hasVariation3()).isFalse();
-    assertThat(variations.hasVariation4()).isFalse();
-    assertThat(variations.getVariation5()).isEqualTo(15d);
-  }
-
-  private static void verifyUnsetLongVariation(LongVariationValue value) {
-    assertThat(value.isSet()).isFalse();
-    assertThat(value.getValue()).isEqualTo(0L);
-  }
-
-  private static void verifySetLongVariation(LongVariationValue value, long expectedValue) {
-    assertThat(value.isSet()).isTrue();
-    assertThat(value.getValue()).isEqualTo(expectedValue);
-  }
-
-  private static Period createPeriod(int i) {
-    return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i));
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/LongVariationValueTest.java
deleted file mode 100644 (file)
index 0a64ffa..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class LongVariationValueTest {
-  @Test
-  public void newly_created_LongVariationValue_is_unset_and_has_value_0() {
-    verifyUnsetVariationValue(new LongVariationValue());
-  }
-
-  @Test
-  public void increment_long_sets_LongVariationValue_and_increments_value() {
-    verifySetVariationValue(new LongVariationValue().increment(10L), 10L);
-  }
-
-  @Test
-  public void increment_LongVariationValue_has_no_effect_if_arg_is_null() {
-    verifyUnsetVariationValue(new LongVariationValue().increment(null));
-  }
-
-  @Test
-  public void increment_LongVariationValue_has_no_effect_if_arg_is_unset() {
-    verifyUnsetVariationValue(new LongVariationValue().increment(new LongVariationValue()));
-  }
-
-  @Test
-  public void increment_LongVariationValue_increments_by_the_value_of_the_arg() {
-    LongVariationValue source = new LongVariationValue().increment(10L);
-    LongVariationValue target = new LongVariationValue().increment(source);
-
-    verifySetVariationValue(target, 10L);
-  }
-
-  @Test
-  public void multiple_calls_to_increment_LongVariationValue_increments_by_the_value_of_the_arg() {
-    LongVariationValue target = new LongVariationValue()
-      .increment(new LongVariationValue().increment(35L))
-      .increment(new LongVariationValue().increment(10L));
-
-    verifySetVariationValue(target, 45L);
-  }
-
-  @Test
-  public void multiples_calls_to_increment_long_increment_the_value() {
-    LongVariationValue variationValue = new LongVariationValue()
-      .increment(10L)
-      .increment(95L);
-
-    verifySetVariationValue(variationValue, 105L);
-  }
-
-  private static void verifyUnsetVariationValue(LongVariationValue variationValue) {
-    assertThat(variationValue.isSet()).isFalse();
-    assertThat(variationValue.getValue()).isEqualTo(0L);
-  }
-
-  private static void verifySetVariationValue(LongVariationValue variationValue, long expected) {
-    assertThat(variationValue.isSet()).isTrue();
-    assertThat(variationValue.getValue()).isEqualTo(expected);
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingValueTest.java
new file mode 100644 (file)
index 0000000..29f5427
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.computation.task.projectanalysis.formula.counter;
+
+import org.junit.Test;
+import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.A;
+import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.B;
+import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C;
+import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D;
+
+public class RatingValueTest {
+
+  @Test
+  public void newly_created_value_is_unset_and_has_value_0() {
+    verifyUnsetVariationValue(new RatingValue());
+  }
+
+  @Test
+  public void increment_sets_value_and_increments_value() {
+    verifySetVariationValue(new RatingValue().increment(B), B);
+  }
+
+  @Test
+  public void increment_has_no_effect_if_arg_is_null() {
+    verifyUnsetVariationValue(new RatingValue().increment((RatingValue) null));
+  }
+
+  @Test
+  public void increment_has_no_effect_if_arg_is_unset() {
+    verifyUnsetVariationValue(new RatingValue().increment(new RatingValue()));
+  }
+
+  @Test
+  public void increment_increments_by_the_value_of_the_arg() {
+    RatingValue source = new RatingValue().increment(B);
+    RatingValue target = new RatingValue().increment(source);
+
+    verifySetVariationValue(target, B);
+  }
+
+  @Test
+  public void multiple_calls_to_increment_increments_by_the_value_of_the_arg() {
+    RatingValue target = new RatingValue()
+      .increment(new RatingValue().increment(B))
+      .increment(new RatingValue().increment(D));
+
+    verifySetVariationValue(target, D);
+  }
+
+  @Test
+  public void multiples_calls_to_increment_increments_the_value() {
+    RatingValue variationValue = new RatingValue()
+      .increment(B)
+      .increment(C);
+
+    verifySetVariationValue(variationValue, C);
+  }
+
+  private static void verifyUnsetVariationValue(RatingValue variationValue) {
+    assertThat(variationValue.isSet()).isFalse();
+    assertThat(variationValue.getValue()).isEqualTo(A);
+  }
+
+  private static void verifySetVariationValue(RatingValue variationValue, Rating expected) {
+    assertThat(variationValue.isSet()).isTrue();
+    assertThat(variationValue.getValue()).isEqualTo(expected);
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueArrayTest.java
deleted file mode 100644 (file)
index 6d34d93..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import com.google.common.collect.ImmutableList;
-import java.util.List;
-import java.util.Optional;
-import org.assertj.guava.api.Assertions;
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.A;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.B;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.E;
-
-public class RatingVariationValueArrayTest {
-
-  private static final List<Period> PERIODS;
-
-  static {
-    ImmutableList.Builder<Period> builder = ImmutableList.builder();
-    for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) {
-      builder.add(createPeriod(i));
-    }
-    PERIODS = builder.build();
-  }
-
-  @Test
-  public void newArray_always_returns_a_new_instance() {
-    assertThat(RatingVariationValue.newArray()).isNotSameAs(RatingVariationValue.newArray());
-  }
-
-  @Test
-  public void get_returns_unset_value_for_each_period_index() {
-    RatingVariationValue.Array array = RatingVariationValue.newArray();
-    PERIODS.forEach(p -> verifyUnsetVariation(array.get(p)));
-  }
-
-  @Test
-  public void get_returns_set_value_for_each_period_index_if_increment_has_been_called() {
-    RatingVariationValue.Array array = RatingVariationValue.newArray();
-    PERIODS.forEach(period -> {
-      array.increment(period, C);
-      verifySetVariation(array.get(period), C);
-    });
-  }
-
-  @Test
-  public void incrementAll_increments_internals_from_all_set_value_from_source() {
-    RatingVariationValue.Array source = RatingVariationValue.newArray()
-      .increment(createPeriod(2), B)
-      .increment(createPeriod(5), C);
-
-    RatingVariationValue.Array target = RatingVariationValue.newArray()
-      .increment(createPeriod(1), D)
-      .increment(createPeriod(5), E);
-    target.incrementAll(source);
-
-    verifySetVariation(target.get(createPeriod(1)), D);
-    verifySetVariation(target.get(createPeriod(2)), B);
-    verifyUnsetVariation(target.get(createPeriod(3)));
-    verifyUnsetVariation(target.get(createPeriod(4)));
-    verifySetVariation(target.get(createPeriod(5)), E);
-  }
-
-  @Test
-  public void toMeasureVariations_returns_absent_if_no_value_has_been_set() {
-    Assertions.assertThat(LongVariationValue.newArray().toMeasureVariations()).isAbsent();
-  }
-
-  @Test
-  public void toMeasureVariations_returns_value_of_set_value_as_double() {
-    Optional<MeasureVariations> variationsOptional = RatingVariationValue.newArray()
-      .increment(createPeriod(2), B)
-      .increment(createPeriod(5), A)
-      .toMeasureVariations();
-
-    assertThat(variationsOptional).isPresent();
-    MeasureVariations variations = variationsOptional.get();
-    assertThat(variations.hasVariation1()).isFalse();
-    assertThat(variations.getVariation2()).isEqualTo(2d);
-    assertThat(variations.hasVariation3()).isFalse();
-    assertThat(variations.hasVariation4()).isFalse();
-    assertThat(variations.getVariation5()).isEqualTo(1d);
-  }
-
-  private static void verifyUnsetVariation(RatingVariationValue value) {
-    assertThat(value.isSet()).isFalse();
-    assertThat(value.getValue()).isEqualTo(A);
-  }
-
-  private static void verifySetVariation(RatingVariationValue value, Rating expectedValue) {
-    assertThat(value.isSet()).isTrue();
-    assertThat(value.getValue()).isEqualTo(expectedValue);
-  }
-
-  private static Period createPeriod(int i) {
-    return new Period(i, "mode " + i, null, 100L + i, String.valueOf(753L + i));
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/counter/RatingVariationValueTest.java
deleted file mode 100644 (file)
index d8af49e..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.computation.task.projectanalysis.formula.counter;
-
-import org.junit.Test;
-import org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.A;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.B;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.C;
-import static org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingGrid.Rating.D;
-
-public class RatingVariationValueTest {
-
-  @Test
-  public void newly_created_value_is_unset_and_has_value_0() {
-    verifyUnsetVariationValue(new RatingVariationValue());
-  }
-
-  @Test
-  public void increment_sets_value_and_increments_value() {
-    verifySetVariationValue(new RatingVariationValue().increment(B), B);
-  }
-
-  @Test
-  public void increment_has_no_effect_if_arg_is_null() {
-    verifyUnsetVariationValue(new RatingVariationValue().increment((RatingVariationValue) null));
-  }
-
-  @Test
-  public void increment_has_no_effect_if_arg_is_unset() {
-    verifyUnsetVariationValue(new RatingVariationValue().increment(new RatingVariationValue()));
-  }
-
-  @Test
-  public void increment_increments_by_the_value_of_the_arg() {
-    RatingVariationValue source = new RatingVariationValue().increment(B);
-    RatingVariationValue target = new RatingVariationValue().increment(source);
-
-    verifySetVariationValue(target, B);
-  }
-
-  @Test
-  public void multiple_calls_to_increment_increments_by_the_value_of_the_arg() {
-    RatingVariationValue target = new RatingVariationValue()
-      .increment(new RatingVariationValue().increment(B))
-      .increment(new RatingVariationValue().increment(D));
-
-    verifySetVariationValue(target, D);
-  }
-
-  @Test
-  public void multiples_calls_to_increment_increments_the_value() {
-    RatingVariationValue variationValue = new RatingVariationValue()
-      .increment(B)
-      .increment(C);
-
-    verifySetVariationValue(variationValue, C);
-  }
-
-  private static void verifyUnsetVariationValue(RatingVariationValue variationValue) {
-    assertThat(variationValue.isSet()).isFalse();
-    assertThat(variationValue.getValue()).isEqualTo(A);
-  }
-
-  private static void verifySetVariationValue(RatingVariationValue variationValue, Rating expected) {
-    assertThat(variationValue.isSet()).isTrue();
-    assertThat(variationValue.getValue()).isEqualTo(expected);
-  }
-
-}