From ac37b5725ac884aad4f7e35d73a2fce4ac61aa89 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 8 Feb 2017 11:20:48 +0100 Subject: SONAR-8743 Remove useless methods from PeriodHolder --- .../formula/CounterInitializationContext.java | 8 --- .../formula/CreateMeasureContext.java | 8 --- .../formula/FormulaExecutorComponentVisitor.java | 10 --- .../task/projectanalysis/period/PeriodsHolder.java | 35 --------- .../projectanalysis/period/PeriodsHolderImpl.java | 82 +++------------------- .../formula/DumbCreateMeasureContext.java | 6 -- .../ReportFormulaExecutorComponentVisitorTest.java | 2 +- .../formula/coverage/CoverageUtilsTest.java | 6 -- .../projectanalysis/period/PeriodsHolderRule.java | 27 ------- 9 files changed, 9 insertions(+), 175 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CounterInitializationContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CounterInitializationContext.java index 813f874de65..2bace929dbc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CounterInitializationContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CounterInitializationContext.java @@ -20,7 +20,6 @@ package org.sonar.server.computation.task.projectanalysis.formula; import com.google.common.base.Optional; -import java.util.List; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.period.Period; @@ -40,13 +39,6 @@ public interface CounterInitializationContext { */ Optional getMeasure(String metricKey); - /** - * Lists of Periods defined for the current project. They can be used to retrieve variations Measure. - * @deprecated replaced by {@link #getPeriod()} - */ - @Deprecated - List getPeriods(); - /** * Return Period defined for the current project. It can be used to retrieve variation Measure. */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CreateMeasureContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CreateMeasureContext.java index 816bd124b48..12f125f0ef9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CreateMeasureContext.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CreateMeasureContext.java @@ -19,7 +19,6 @@ */ package org.sonar.server.computation.task.projectanalysis.formula; -import java.util.List; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.metric.Metric; import org.sonar.server.computation.task.projectanalysis.period.Period; @@ -38,13 +37,6 @@ public interface CreateMeasureContext { */ Metric getMetric(); - /** - * The periods for which variations of the measure can be created. - * @deprecated as only one period is now available. Use {@link #getPeriod()} instead - */ - @Deprecated - List getPeriods(); - /** * The period for which variation of the measure can be created. */ diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java index 3732ddf126f..20aff1b0f49 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java @@ -205,11 +205,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter getPeriods() { - return periodsHolder.getPeriods(); - } - @Override public Period getPeriod() { return periodsHolder.getPeriod(); @@ -261,11 +256,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter getPeriods() { - return periodsHolder.getPeriods(); - } - @Override public Period getPeriod() { return periodsHolder.getPeriod(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolder.java index 42e31799cab..4099f282588 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolder.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolder.java @@ -19,8 +19,6 @@ */ package org.sonar.server.computation.task.projectanalysis.period; -import java.util.List; - /** * Repository of period used to compute differential measures. * Here are the steps to retrieve the period : @@ -30,39 +28,6 @@ import java.util.List; */ public interface PeriodsHolder { - @Deprecated - int MAX_NUMBER_OF_PERIODS = 5; - - /** - * Return the list of differential periods, ordered by increasing index. - * - * @throws IllegalStateException if the periods haven't been initialized - * @deprecated replaced by {@link #getPeriod()} - */ - @Deprecated - List getPeriods(); - - /** - * Finds out whether the holder contains a Period for the specified index. - * - * @throws IllegalStateException if the periods haven't been initialized - * @throws IndexOutOfBoundsException if i is either < 1 or > 5 - * @deprecated replaced by {@link #hasPeriod()} - */ - @Deprecated - boolean hasPeriod(int i); - - /** - * Retrieves the Period for the specified index from the Holder. - * - * @throws IllegalStateException if the periods haven't been initialized - * @throws IllegalStateException if there is no period for the specified index (see {@link #hasPeriod(int)}) - * @throws IndexOutOfBoundsException if i is either < 1 or > 5 - * @deprecated replaced by {@link #getPeriod()} - */ - @Deprecated - Period getPeriod(int i); - /** * Finds out whether the holder contains a Period * diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderImpl.java index 587a73e310a..f47cd6fa240 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderImpl.java @@ -19,50 +19,16 @@ */ package org.sonar.server.computation.task.projectanalysis.period; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.core.util.stream.Collectors; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.FluentIterable.from; -import static java.util.Objects.requireNonNull; -import static org.sonar.server.computation.task.projectanalysis.period.Period.isValidPeriodIndex; public class PeriodsHolderImpl implements PeriodsHolder { @CheckForNull - private Period[] periods = null; - - /** - * Initializes the periods in the holder. - * - * @throws NullPointerException if the specified Iterable is {@code null} - * @throws NullPointerException if the specified Iterable contains a {@code null} - * @throws IllegalArgumentException if the specified Iterable has more than 5 elements - * @throws IllegalStateException if the holder has already been initialized - * @throws IllegalStateException if two Periods have the same index - * @deprecated as only one period is now available. Use {@link #setPeriod(Period)} instead - */ - @Deprecated - public void setPeriods(Iterable periods) { - requireNonNull(periods, "Periods cannot be null"); - checkArgument(Iterables.size(periods) <= MAX_NUMBER_OF_PERIODS, String.format("There can not be more than %d periods", MAX_NUMBER_OF_PERIODS)); - checkState(this.periods == null, "Periods have already been initialized"); - - Period[] newPeriods = new Period[MAX_NUMBER_OF_PERIODS]; - for (Period period : from(periods).filter(CheckNotNull.INSTANCE)) { - int arrayIndex = period.getIndex() - 1; - checkArgument(newPeriods[arrayIndex] == null, "More than one period has the index " + period.getIndex()); - newPeriods[arrayIndex] = period; - } - this.periods = newPeriods; - } + private Period period = null; + private boolean initialized = false; /** * Initializes the periods in the holder. @@ -70,57 +36,25 @@ public class PeriodsHolderImpl implements PeriodsHolder { * @throws IllegalStateException if the holder has already been initialized */ public void setPeriod(@Nullable Period period) { - checkState(this.periods == null, "Period have already been initialized"); - Period[] newPeriods = new Period[1]; - newPeriods[0] = period; - this.periods = newPeriods; - } - - @Override - public List getPeriods() { - checkHolderIsInitialized(); - return Arrays.stream(periods).filter(Objects::nonNull).collect(Collectors.toList()); - } - - @Override - public boolean hasPeriod(int i) { - checkHolderIsInitialized(); - if (!isValidPeriodIndex(i)) { - throw new IndexOutOfBoundsException(String.format("Invalid Period index (%s), must be 0 < x < 6", i)); - } - return periods[i - 1] != null; - } - - @Override - public Period getPeriod(int i) { - checkState(hasPeriod(i), "Holder has no Period for index %s", i); - return this.periods[i - 1]; + checkState(!initialized, "Period have already been initialized"); + this.period = period; + this.initialized = true; } @Override public boolean hasPeriod() { checkHolderIsInitialized(); - return periods[0] != null; + return period != null; } @Override public Period getPeriod() { checkHolderIsInitialized(); - return this.periods[0]; + return period; } private void checkHolderIsInitialized() { - checkState(this.periods != null, "Period have not been initialized yet"); - } - - private enum CheckNotNull implements Predicate { - INSTANCE; - - @Override - public boolean apply(@Nullable Period input) { - requireNonNull(input, "No null Period can be added to the holder"); - return true; - } + checkState(initialized, "Period have not been initialized yet"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/DumbCreateMeasureContext.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/DumbCreateMeasureContext.java index 87e21537f6f..3010a58a626 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/DumbCreateMeasureContext.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/DumbCreateMeasureContext.java @@ -19,7 +19,6 @@ */ package org.sonar.server.computation.task.projectanalysis.formula; -import java.util.List; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.metric.Metric; import org.sonar.server.computation.task.projectanalysis.period.Period; @@ -46,11 +45,6 @@ public class DumbCreateMeasureContext implements CreateMeasureContext { return metric; } - @Override - public List getPeriods() { - return periodsHolder.getPeriods(); - } - @Override public Period getPeriod() { return periodsHolder.getPeriod(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java index 3437d47c9bd..694d0ba7688 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java @@ -240,7 +240,7 @@ public class ReportFormulaExecutorComponentVisitorTest { @Override public Optional 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)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java index d8cdd2dc1cf..9ea8dafae59 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java @@ -21,7 +21,6 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage; import com.google.common.base.Optional; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.junit.Rule; import org.junit.Test; @@ -135,11 +134,6 @@ public class CoverageUtilsTest { return Optional.fromNullable(measures.get(metricKey)); } - @Override - public List getPeriods() { - throw new UnsupportedOperationException("getPeriods is not supported"); - } - @Override public Period getPeriod() { throw new UnsupportedOperationException("getPeriod is not supported"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java index a9b427905d8..4c13550bfea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java @@ -19,8 +19,6 @@ */ package org.sonar.server.computation.task.projectanalysis.period; -import java.util.Arrays; -import java.util.List; import javax.annotation.Nullable; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -47,37 +45,12 @@ public class PeriodsHolderRule implements TestRule, PeriodsHolder { this.delegate = new PeriodsHolderImpl(); } - /** - * @deprecated as only one period is now available. Use {@link #setPeriod(Period)} instead - */ - @Deprecated - public PeriodsHolderRule setPeriods(Period... periods) { - delegate = new PeriodsHolderImpl(); - delegate.setPeriods(Arrays.asList(periods)); - return this; - } - public PeriodsHolderRule setPeriod(@Nullable Period period) { delegate = new PeriodsHolderImpl(); delegate.setPeriod(period); return this; } - @Override - public List getPeriods() { - return delegate.getPeriods(); - } - - @Override - public boolean hasPeriod(int i) { - return delegate.hasPeriod(i); - } - - @Override - public Period getPeriod(int i) { - return delegate.getPeriod(i); - } - @Override public boolean hasPeriod() { return delegate.hasPeriod(); -- cgit v1.2.3