for (Metric metric : metrics.getMetrics()) {
String metricKey = metric.getKey();
if (CoreMetrics.getMetrics().contains(metric)) {
throw new IllegalStateException("The following metric is already defined in sonar: " + metricKey);
}
Metrics anotherRepository = metricsByRepository.get(metricKey);
if (anotherRepository != null) {
throw new IllegalStateException("The metric '" + metricKey + "' is already defined in the extension: " + anotherRepository);
}
metricsByRepository.put(metricKey, metrics);
}