void setValue(ComponentDto component, String metricKey, Rating value) { changeCell(component, metricKey, m -> { Double initialValue = m.getValue(); if (initialValue != null && Double.compare(initialValue, (double) value.getIndex()) == 0) { return false; } m.setData(value.name()); m.setValue((double) value.getIndex()); Double initialVariation = m.getVariation(); if (initialValue != null && initialVariation != null) { double leakInitialValue = initialValue - initialVariation; m.setVariation(value.getIndex() - leakInitialValue); } return true; }); }
/** * @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; }
private static Rating toRating(String value) { return Rating.valueOf(parseInt(value)); }
void setLeakValue(ComponentDto component, String metricKey, Rating variation) { setLeakValue(component, metricKey, (double) variation.getIndex()); }
private void computeAndSaveMeasures(Component component, Path<Counter> path) { if (!periodHolder.hasPeriod()) { return; } initRatingsToA(path); processIssues(component, path); path.current().newRatingValueByMetric.entrySet() .stream() .filter(entry -> entry.getValue().isSet()) .forEach( entry -> measureRepository.add( component, metricsByKey.get(entry.getKey()), newMeasureBuilder().setVariation(entry.getValue().getValue().getIndex()).createNoValue())); addToParent(path); }
@Test public void fail_to_concert_invalid_value() { throwable.expect(IllegalArgumentException.class); Rating.valueOf(10); }
@Test public void verify_value_comparison_for_rating_metric() { Predicate<Measure> underTest = BestValueOptimization.from(createMetric(Metric.MetricType.RATING, A.getIndex()), FILE_COMPONENT); assertThat(underTest.test(newMeasureBuilder().create(A.getIndex()))).isTrue(); assertThat(underTest.test(newMeasureBuilder().setVariation((double) A.getIndex()).createNoValue())).isTrue(); assertThat(underTest.test(newMeasureBuilder().create(B.getIndex()))).isFalse(); assertThat(underTest.test(newMeasureBuilder().setVariation((double) B.getIndex()).createNoValue())).isFalse(); }
private void assertNewMaintainability(int componentRef, Rating expectedVariation) { assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasVariation(expectedVariation.getIndex()); }
private void computeAndSaveMeasures(Component component, Path<Counter> path) { processIssues(component, path); path.current().ratingValueByMetric.forEach((key, value) -> { Rating rating = value.getValue(); measureRepository.add(component, metricsByKey.get(key), newMeasureBuilder().create(rating.getIndex(), rating.name())); }); if (!path.isRoot()) { path.parent().add(path.current()); } }
private void verifyAddedRawMeasureOnLeakPeriod(int componentRef, String metricKey, Rating rating) { MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)) .hasVariation(rating.getIndex()); }
private void assertThatRatingMeasureHasLeakValue(ComponentDto component, Rating expectedValue) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex()); }
private LiveMeasureDto assertThatRatingMeasureHasValue(ComponentDto component, Rating expectedRating) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getValue()).isEqualTo(expectedRating.getIndex()); assertThat(measure.getDataAsString()).isEqualTo(expectedRating.name()); return measure; }