ListMultimap<RuleKey, Issue> issuesPerRuleKeys = ArrayListMultimap.create();
Set<RuleKey> ruleKeys = Sets.newHashSet();
Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric));
for (Measure child : children) {
RuleMeasure childRuleMeasure = (RuleMeasure) child;
RuleKey ruleKey = childRuleMeasure.ruleKey();
if (ruleKey != null) {
childMeasuresPerRuleKeys.put(ruleKey, childRuleMeasure);
ruleKeys.add(ruleKey);
}
}
for (Issue issue : issues) {
if (RulePriority.valueOf(issue.severity()).equals(severity)) {
ruleKeys.add(issue.ruleKey());
issuesPerRuleKeys.put(issue.ruleKey(), issue);
}
}
for (RuleKey ruleKey : ruleKeys) {
RuleMeasure measure = RuleMeasure.createForRule(metric, ruleKey, null);
measure.setSeverity(severity);
for (Period period : timeMachineConfiguration.periods()) {
int variationIndex = period.getIndex();
double sum = MeasureUtils.sumOnVariation(true, variationIndex, childMeasuresPerRuleKeys.get(ruleKey)) + countIssues(issuesPerRuleKeys.get(ruleKey), period);
measure.setVariation(variationIndex, sum);
}
context.saveMeasure(measure);
}
}
}