/** * @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; }
void setLeakValue(ComponentDto component, String metricKey, Rating variation) { setLeakValue(component, metricKey, (double) variation.getIndex()); }
private void addMaintainabilityRatingMeasure(Component component, double density) { Rating rating = ratingSettings.getDebtRatingGrid().getRatingForDensity(density); measureRepository.add(component, maintainabilityRatingMetric, newMeasureBuilder().create(rating.getIndex(), rating.name())); }
@Override public DebtRatingGrid getDebtRatingGrid() { return new DebtRatingGrid(new double[] {0.05, 0.1, 0.2, 0.5}); }
private static double effortToReachMaintainabilityRatingA(IssueMetricFormula.Context context) { double developmentCost = context.getValue(CoreMetrics.DEVELOPMENT_COST).orElse(0.0); double effort = context.getValue(CoreMetrics.TECHNICAL_DEBT).orElse(0.0); double upperGradeCost = context.getDebtRatingGrid().getGradeLowerBound(Rating.B) * developmentCost; return upperGradeCost < effort ? (effort - upperGradeCost) : 0.0; }
private static Rating toRating(String value) { return Rating.valueOf(parseInt(value)); }
@Test public void density_matching_exact_grid_values() { assertThat(ratingGrid.getRatingForDensity(0.1)).isEqualTo(A); assertThat(ratingGrid.getRatingForDensity(0.2)).isEqualTo(B); assertThat(ratingGrid.getRatingForDensity(0.5)).isEqualTo(C); assertThat(ratingGrid.getRatingForDensity(1)).isEqualTo(D); }
public DebtRatingGrid(double[] gridValues) { this.gridValues = Arrays.copyOf(gridValues, gridValues.length); this.ratingBounds = buildRatingBounds(gridValues); }
private static EnumMap<Rating, Bounds> buildRatingBounds(double[] gridValues) { checkState(gridValues.length == 4, "Rating grid should contains 4 values"); EnumMap<Rating, Bounds> ratingBounds = new EnumMap<>(Rating.class); ratingBounds.put(A, new Bounds(0d, gridValues[0])); ratingBounds.put(B, new Bounds(gridValues[0], gridValues[1])); ratingBounds.put(C, new Bounds(gridValues[1], gridValues[2])); ratingBounds.put(D, new Bounds(gridValues[2], gridValues[3])); ratingBounds.put(E, new Bounds(gridValues[3], Double.MAX_VALUE)); return ratingBounds; }
public RatingSettings(Configuration config) { ratingGrid = new DebtRatingGrid(config); defaultDevCost = initDefaultDevelopmentCost(config); languageSpecificConfigurationByLanguageKey = initLanguageSpecificConfigurationByLanguageKey(config); }
private void assertNewMaintainability(int componentRef, Rating expectedVariation) { assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasVariation(expectedVariation.getIndex()); }
@Test public void fail_on_invalid_density() { throwable.expect(IllegalArgumentException.class); throwable.expectMessage("Invalid value '-1.0'"); ratingGrid.getRatingForDensity(-1); }
@Before public void setUp() { double[] gridValues = new double[] {0.1, 0.2, 0.5, 1}; ratingGrid = new DebtRatingGrid(gridValues); }
private void verifyAddedRawMeasureOnLeakPeriod(int componentRef, String metricKey, Rating rating) { MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)) .hasVariation(rating.getIndex()); }
@Test public void fail_to_concert_invalid_value() { throwable.expect(IllegalArgumentException.class); Rating.valueOf(10); }
@Test public void fail_on_invalid_grid() { throwable.expect(IllegalStateException.class); throwable.expectMessage("Rating grid should contains 4 values"); ratingGrid = new DebtRatingGrid(new double[] {0.1, 0.2, 0.5}); } }