void compareWithPastMeasures(DecoratorContext context, int index, List<Object[]> pastMeasures) { Map<MeasureKey, Object[]> pastMeasuresByKey = Maps.newHashMap(); for (Object[] pastMeasure : pastMeasures) { pastMeasuresByKey.put(new MeasureKey(pastMeasure), pastMeasure); } // for each measure, search equivalent past measure for (Measure measure : context.getMeasures(MeasuresFilters.all())) { // compare with past measure Integer metricId = (measure.getMetric().getId() != null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId()); Integer characteristicId = (measure.getCharacteristic() != null ? measure.getCharacteristic().getId() : null); Integer ruleId = (measure instanceof RuleMeasure ? ((RuleMeasure) measure).getRule().getId() : null); Object[] pastMeasure = pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, ruleId)); if (updateVariation(measure, pastMeasure, index)) { context.saveMeasure(measure); } } }
/** the measure is updated if it's already registered. */ @Override public Measure addMeasure(Resource resource, Measure measure) { Bucket bucket = checkIndexed(resource); if (bucket != null && !bucket.isExcluded()) { Metric metric = metricFinder.findByKey(measure.getMetricKey()); if (metric == null) { throw new SonarException("Unknown metric: " + measure.getMetricKey()); } measure.setMetric(metric); bucket.addMeasure(measure); if (measure.getPersistenceMode().useDatabase()) { persistence.saveMeasure(resource, measure); } } return measure; }