Histographs { public static <K extends Comparable<K>> Histograph<K> union( Histograph<K> h0, Histograph<K> h1 ) { Histograph<K> result = new Histograph<>( h0 ); for (Map.Entry<K, AtomicInteger> entry : h1.delegate.entrySet()) { result.incr( entry.getKey(), entry.getValue().get() ); } return result; }  static Histograph<K> intersection( Histograph<K> h0, Histograph<K> h1 ); static Histograph<K> union( Histograph<K> h0, Histograph<K> h1 ); static long sum( Histograph<K> histograph );  }
@Test public void testUnion() throws Exception { Histograph<String> h0 = new Histograph<>(); Histograph<String> h1 = new Histograph<>(); h0.incr( "a" ); h0.incr( "b" ); h1.incr( "b" ); h1.incr( "c" ); Histograph<String> union = Histographs.union( h0, h1 ); System.out.printf( "%s\n", union ); assertEquals( "{b=2, a=1, c=1}", union.toString() ); }