]> source.dussan.org Git - sonarqube.git/blob
d948b03824b9136d356dbca846dc6c018b314d18
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2016 SonarSource SA
4  * mailto:contact AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 package org.sonar.server.computation.task.projectanalysis.formula.coverage;
21
22 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
23 import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
24 import org.sonar.server.computation.task.projectanalysis.period.Period;
25
26 import static java.util.Objects.requireNonNull;
27 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
28 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
29 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
30
31 public final class SingleWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
32   private final SingleWithUncoveredMetricKeys metricKeys;
33
34   public SingleWithUncoveredVariationCounter(SingleWithUncoveredMetricKeys metricKeys) {
35     this.metricKeys = requireNonNull(metricKeys);
36   }
37
38   @Override
39   protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
40     MeasureVariations newConditions = getMeasureVariations(counterContext, metricKeys.getCovered());
41     MeasureVariations uncoveredConditions = getMeasureVariations(counterContext, metricKeys.getUncovered());
42     for (Period period : supportedPeriods(counterContext)) {
43       long elements = getLongVariation(newConditions, period);
44       this.elements.increment(period, elements);
45       coveredElements.increment(period, elements - getLongVariation(uncoveredConditions, period));
46     }
47   }
48 }