MetricRegistry implements MetricSet { public static String name(String name, String... names) { final StringBuilder builder = new StringBuilder(); append(builder, name); if (names != null) { for (String s : names) { append(builder, s); } } return builder.toString(); } MetricRegistry(); static String name(String name, String... names); static String name(Class<?> klass, String... names); @SuppressWarnings("unchecked") T register(String name, T metric); void registerAll(MetricSet metrics); Counter counter(String name); Counter counter(String name, final MetricSupplier<Counter> supplier); Histogram histogram(String name); Histogram histogram(String name, final MetricSupplier<Histogram> supplier); Meter meter(String name); Meter meter(String name, final MetricSupplier<Meter> supplier); Timer timer(String name); Timer timer(String name, final MetricSupplier<Timer> supplier); @SuppressWarnings("rawtypes") Gauge gauge(String name, final MetricSupplier<Gauge> supplier); boolean remove(String name); void removeMatching(MetricFilter filter); void addListener(MetricRegistryListener listener); void removeListener(MetricRegistryListener listener); SortedSet<String> getNames(); @SuppressWarnings("rawtypes") SortedMap<String, Gauge> getGauges(); @SuppressWarnings("rawtypes") SortedMap<String, Gauge> getGauges(MetricFilter filter); SortedMap<String, Counter> getCounters(); SortedMap<String, Counter> getCounters(MetricFilter filter); SortedMap<String, Histogram> getHistograms(); SortedMap<String, Histogram> getHistograms(MetricFilter filter); SortedMap<String, Meter> getMeters(); SortedMap<String, Meter> getMeters(MetricFilter filter); SortedMap<String, Timer> getTimers(); SortedMap<String, Timer> getTimers(MetricFilter filter); void registerAll(String prefix, MetricSet metrics); @Override Map<String, Metric> getMetrics();  }
@Test public void concatenatesStringsToFormADottedName() { assertThat(name("one", "two", "three")) .isEqualTo("one.two.three"); }
@Test @SuppressWarnings("NullArgumentToVariableArgMethod") public void elidesNullValuesFromNamesWhenOnlyOneNullPassedIn() { assertThat(name("one", (String) null)) .isEqualTo("one"); }
@Test public void elidesNullValuesFromNamesWhenManyNullsPassedIn() { assertThat(name("one", null, null)) .isEqualTo("one"); }
@Test public void elidesNullValuesFromNamesWhenNullAndNotNullPassedIn() { assertThat(name("one", null, "three")) .isEqualTo("one.three"); }
@Test public void elidesEmptyStringsFromNames() { assertThat(name("one", "", "three")) .isEqualTo("one.three"); }
@Test public void concatenatesClassNamesWithStringsToFormADottedName() { assertThat(name(MetricRegistryTest.class, "one", "two")) .isEqualTo("com.codahale.metrics.MetricRegistryTest.one.two"); }
@Test public void concatenatesClassesWithoutCanonicalNamesWithStrings() { final Gauge<String> g = () -> null; assertThat(name(g.getClass(), "one", "two")) .matches("com\\.codahale\\.metrics\\.MetricRegistryTest.+?\\.one\\.two"); }