package com.yammer.metrics.util;

import com.yammer.metrics.core.Metric;
import com.yammer.metrics.core.MetricName;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Utils {
    private Utils() { /* unused */ }

    public static Map<String, Map<MetricName, Metric>> sortMetrics(Map<MetricName, Metric> metrics) {
        return sortAndFilterMetrics(metrics, MetricPredicate.ALL);
    }

    public static Map<MetricName, Metric> filterMetrics(Map<MetricName, Metric> metrics, MetricPredicate predicate) {
        final Map<MetricName, Metric> result = new HashMap<MetricName, Metric>();
        for (Entry<MetricName, Metric> entry : metrics.entrySet()) {
            if (predicate.matches(entry.getKey(), entry.getValue())) {
                result.put(entry.getKey(), entry.getValue());
            }
        }
        return result;
    }

    public static Map<String, Map<MetricName, Metric>> sortAndFilterMetrics(Map<MetricName, Metric> metrics, MetricPredicate predicate) {
        final Map<String, Map<MetricName, Metric>> sortedMetrics = new TreeMap<String, Map<MetricName, Metric>>();
        for (Entry<MetricName, Metric> entry : metrics.entrySet()) {
            final String qualifiedTypeName = entry.getKey().getGroup() + "." + entry.getKey()
                                                                                    .getType();
            if (predicate.matches(entry.getKey(), entry.getValue())) {
                final String scopedName;
                if (entry.getKey().hasScope()) {
                    scopedName = qualifiedTypeName + "." + entry.getKey().getScope();
                } else {
                    scopedName = qualifiedTypeName;
                }
                Map<MetricName, Metric> subMetrics = sortedMetrics.get(scopedName);
                if (subMetrics == null) {
                    subMetrics = new TreeMap<MetricName, Metric>();
                    sortedMetrics.put(scopedName, subMetrics);
                }
                subMetrics.put(entry.getKey(), entry.getValue());
            }
        }
        return sortedMetrics;
    }
}

@@ -114,34 +114,8 @@
 e;%0A%0A
-import java.util.HashMap;%0A
 impo
@@ -426,464 +426,8 @@
  %7D%0A%0A
-    public static Map%3CMetricName, Metric%3E filterMetrics(Map%3CMetricName, Metric%3E metrics, MetricPredicate predicate) %7B%0A        final Map%3CMetricName, Metric%3E result = new HashMap%3CMetricName, Metric%3E();%0A        for (Entry%3CMetricName, Metric%3E entry : metrics.entrySet()) %7B%0A            if (predicate.matches(entry.getKey(), entry.getValue())) %7B%0A                result.put(entry.getKey(), entry.getValue());%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A
     

Remove Utils.filterMetrics.