Browse Source

SONAR-8743 Remove useless methods from PeriodHolder

tags/6.3-RC1
Julien Lancelot 7 years ago
parent
commit
ac37b5725a

+ 0
- 8
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CounterInitializationContext.java View File

@@ -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<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.
*/

+ 0
- 8
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/CreateMeasureContext.java View File

@@ -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<Period> getPeriods();

/**
* The period for which variation of the measure can be created.
*/

+ 0
- 10
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/FormulaExecutorComponentVisitor.java View File

@@ -205,11 +205,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For
return measureRepository.getRawMeasure(file, metricRepository.getByKey(metricKey));
}

@Override
public List<Period> getPeriods() {
return periodsHolder.getPeriods();
}

@Override
public Period getPeriod() {
return periodsHolder.getPeriod();
@@ -261,11 +256,6 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For
return metric;
}

@Override
public List<Period> getPeriods() {
return periodsHolder.getPeriods();
}

@Override
public Period getPeriod() {
return periodsHolder.getPeriod();

+ 0
- 35
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolder.java View File

@@ -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 &lt; 1 or &gt; 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 &lt; 1 or &gt; 5
* @deprecated replaced by {@link #getPeriod()}
*/
@Deprecated
Period getPeriod(int i);

/**
* Finds out whether the holder contains a Period
*

+ 8
- 74
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderImpl.java View File

@@ -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");
}

}

+ 0
- 6
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/DumbCreateMeasureContext.java View File

@@ -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<Period> getPeriods() {
return periodsHolder.getPeriods();
}

@Override
public Period getPeriod() {
return periodsHolder.getPeriod();

+ 1
- 1
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/ReportFormulaExecutorComponentVisitorTest.java View File

@@ -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));


+ 0
- 6
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java View File

@@ -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<Period> getPeriods() {
throw new UnsupportedOperationException("getPeriods is not supported");
}

@Override
public Period getPeriod() {
throw new UnsupportedOperationException("getPeriod is not supported");

+ 0
- 27
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java View File

@@ -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<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();

Loading…
Cancel
Save