SemanticMetricRegistry implements SemanticMetricSet { @SuppressWarnings("unchecked") protected <T extends Metric> SortedMap<MetricId, T> getMetrics( final Class<T> klass, final SemanticMetricFilter filter ) { final TreeMap<MetricId, T> metrics = new TreeMap<MetricId, T>(); for (final Map.Entry<MetricId, Metric> entry : this.metrics.entrySet()) { if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(), entry.getValue())) { metrics.put(entry.getKey(), (T) entry.getValue()); } } return Collections.unmodifiableSortedMap(metrics); } SemanticMetricRegistry(final ConcurrentMap<MetricId, Metric> metrics);  SemanticMetricRegistry();  SemanticMetricRegistry(final Supplier<Reservoir> defaultReservoirSupplier);  SemanticMetricRegistry(
        final ConcurrentMap<MetricId, Metric> metrics,
        final Supplier<Reservoir> defaultReservoirSupplier
    ); T register(@NonNull final MetricId name, @NonNull final T metric); void registerAll(final SemanticMetricSet metrics); Counter counter(final MetricId name); Histogram histogram(final MetricId name); Distribution distribution(final MetricId name); Histogram histogram(final MetricId name, Supplier<Reservoir> reservoirSupplier); Meter meter(final MetricId name); Timer timer(final MetricId name); Timer timer(final MetricId name, Supplier<Reservoir> reservoirSupplier); DerivingMeter derivingMeter(final MetricId name); boolean remove(final MetricId name); void removeMatching(final SemanticMetricFilter filter); void addListener(final SemanticMetricRegistryListener listener); void removeListener(final SemanticMetricRegistryListener listener); SortedSet<MetricId> getNames(); @SuppressWarnings("rawtypes") SortedMap<MetricId, Gauge> getGauges(); @SuppressWarnings("rawtypes") SortedMap<MetricId, Gauge> getGauges(final SemanticMetricFilter filter); SortedMap<MetricId, Counter> getCounters(); SortedMap<MetricId, Counter> getCounters(final SemanticMetricFilter filter); SortedMap<MetricId, Histogram> getHistograms(); SortedMap<MetricId, Histogram> getHistograms(final SemanticMetricFilter filter); SortedMap<MetricId, Meter> getMeters(); SortedMap<MetricId, Meter> getMeters(final SemanticMetricFilter filter); SortedMap<MetricId, Timer> getTimers(); SortedMap<MetricId, Timer> getTimers(final SemanticMetricFilter filter); SortedMap<MetricId, DerivingMeter> getDerivingMeters(final SemanticMetricFilter filter); SortedMap<MetricId, Distribution> getDistributions(final SemanticMetricFilter filter); @SuppressWarnings("unchecked") T getOrAdd(
        final MetricId name, final SemanticMetricBuilder<T> builder
    ); @Override Map<MetricId, Metric> getMetrics();  }
@Test public void shouldGetMetrics() { Set<Map.Entry<MetricId, Metric>> entries = ImmutableMap.of(id, metric, id2, metric2).entrySet(); final SemanticMetricFilter filter = mock(SemanticMetricFilter.class); doReturn(entries).when(metrics).entrySet(); doReturn(true).when(filter).matches(id2, metric2); final Map<MetricId, Metric> expected = ImmutableMap.of(id2, metric2); assertEquals(expected, registry.getMetrics(Metric.class, filter)); verify(metrics).entrySet(); verify(filter).matches(id2, metric2); }