Histographs { public static <K extends Comparable<K>> Histograph<K> intersection( Histograph<K> h0, Histograph<K> h1 ) { Histograph<K> result = new Histograph<>(); for ( K key : h0.keySet() ) { if ( h1.delegate.containsKey( key ) ) { result.incr( key, h0.get( key ) ); result.incr( key, h1.get( key ) ); } } 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 testIntersection() 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> intersection = Histographs.intersection( h0, h1 ); System.out.printf( "%s\n", intersection ); assertEquals( "{b=2}", intersection.toString() ); }