MetricsMap implements Serializable { @Override public boolean equals(@Nullable Object object) { if (object instanceof MetricsMap) { MetricsMap<?, ?> metricsMap = (MetricsMap<?, ?>) object; return Objects.equals(metrics, metricsMap.metrics); } return false; } MetricsMap(Factory<K, T> factory); T get(K key); @Nullable T tryGet(K key); Iterable<Map.Entry<K, T>> entries(); Iterable<T> values(); @Override boolean equals(@Nullable Object object); @Override int hashCode();  }
@Test public void testEquals() { MetricsMap<String, AtomicLong> metricsMap = new MetricsMap<>(unusedKey -> new AtomicLong()); MetricsMap<String, AtomicLong> equal = new MetricsMap<>(unusedKey -> new AtomicLong()); Assert.assertEquals(metricsMap, equal); Assert.assertEquals(metricsMap.hashCode(), equal.hashCode()); }