public T get(K key) {
    T metric = metrics.get(key);
    if (metric == null) {
      metric = factory.createInstance(key);
      metric = MoreObjects.firstNonNull(metrics.putIfAbsent(key, metric), metric);
    }
    return metric;
  }
@Test
  public void testReuseInstances() {
    AtomicLong foo1 = metricsMap.get("foo");
    AtomicLong foo2 = metricsMap.get("foo");

    assertThat(foo1, sameInstance(foo2));
  }