diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-08 11:20:48 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-02-09 12:15:11 +0100 |
commit | ac37b5725ac884aad4f7e35d73a2fce4ac61aa89 (patch) | |
tree | 6d63b20a3ea49d621efef030c5c4c2ca82fffe6a | |
parent | 9ca03e29686237eab5d3231be88fd79f5ff686fc (diff) | |
download | sonarqube-ac37b5725ac884aad4f7e35d73a2fce4ac61aa89.tar.gz sonarqube-ac37b5725ac884aad4f7e35d73a2fce4ac61aa89.zip |
SONAR-8743 Remove useless methods from PeriodHolder
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; @@ -41,13 +40,6 @@ public interface CounterInitializationContext { Optional<Measure> 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<Period> getPeriods(); - - /** * Return Period defined for the current project. It can be used to retrieve variation Measure. */ Period getPeriod(); 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; @@ -39,13 +38,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<Period> getPeriods(); - - /** * The period for which variation of the measure can be created. */ Period getPeriod(); 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 @@ -206,11 +206,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For } @Override - public List<Period> getPeriods() { - return periodsHolder.getPeriods(); - } - - @Override public Period getPeriod() { return periodsHolder.getPeriod(); } @@ -262,11 +257,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For } @Override - public List<Period> 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<Period> 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<Period> 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<Period> 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<Period> { - 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; @@ -47,11 +46,6 @@ public class DumbCreateMeasureContext implements CreateMeasureContext { } @Override - public List<Period> 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<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)); 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; @@ -136,11 +135,6 @@ public class CoverageUtilsTest { } @Override - public List<Period> 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,16 +45,6 @@ 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); @@ -64,21 +52,6 @@ public class PeriodsHolderRule implements TestRule, PeriodsHolder { } @Override - public List<Period> 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(); } |