### Question:
Metrics { public Metrics() { metrics = new ConcurrentHashMap<>(); } Metrics(); void addMetric(Metric metric); void addMetric(String name, Number value); void addMetric(String name, Number value, String unit); boolean hasMetric(String name); List<Metric> getMetric(String name); Set<String> getMetricNames(); Metric latestMetric(String name); Metric percentile(String metricName, int percentile); double mean(String metricName);  }### Answer:
@Test public void testMetrics() { Metrics metrics = new Metrics(); metrics.addMetric(new Metric("m1", 1L)); metrics.addMetric("m1", 3L, "count"); metrics.addMetric("m1", 2L); Metric p50 = metrics.percentile("m1", 50); Assert.assertEquals(p50.getValue().longValue(), 2L); metrics.addMetric(new Metric("m2", 1f)); metrics.addMetric("m2", 3f, "count"); metrics.addMetric("m2", 2f); p50 = metrics.percentile("m2", 50); Assert.assertEquals(p50.getValue().floatValue(), 2f); metrics.addMetric(new Metric("m3", 1d)); metrics.addMetric("m3", 3d, "count"); metrics.addMetric("m3", 2d); p50 = metrics.percentile("m3", 50); Assert.assertEquals(p50.getValue().doubleValue(), 2d); List<Metric> list = metrics.getMetric("m1"); Assert.assertEquals(list.size(), 3); list = metrics.getMetric("m4"); Assert.assertEquals(list.size(), 0); Set<String> metricNames = metrics.getMetricNames(); Assert.assertEquals(metricNames.size(), 3); Assert.assertEquals(metricNames.contains("m1"), true); Assert.assertEquals(metricNames.contains("m2"), true); Assert.assertEquals(metricNames.contains("m3"), true); Assert.assertEquals(metricNames.contains("m4"), false); }