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;
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) {
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
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;
@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());
}
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) {
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;
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
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;
}
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) {
}
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;
}
}
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;
}
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
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;
}
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
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;
}
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;
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;
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) {
}
}
- 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();
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;
@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 {
}
@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
.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> {
@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));
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()) {
@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();
}
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());
}
}
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;
@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 {
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
@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));
@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));
@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();
}
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
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) {
private void verifyLeafContext(CounterInitializationContext context) {
assertThat(context.getLeaf().getChildren()).isEmpty();
- assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
+ assertThat(context.getPeriod()).isEqualTo(periodsHolder.getPeriod());
}
}
--- /dev/null
+/*
+ * 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);
+ }
+}
+++ /dev/null
-/*
- * 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));
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
+++ /dev/null
-/*
- * 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));
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
+++ /dev/null
-/*
- * 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));
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
+++ /dev/null
-/*
- * 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));
- }
-
-}
+++ /dev/null
-/*
- * 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);
- }
-
-}