}
private <T> T returnExistingWithCast(MetricMutable metric,
Class<T> metricClass, String name) {
if (!metricClass.isAssignableFrom(metric.getClass())) {
throw new MetricsException(
"Metric already exists in registry for metric name: " + name
+ " and not of type " + metricClass);
}
return (T) metric;