public static < E > Counter < E > absoluteDifference ( Counter < E > c1 , Counter < E > c2 ) { Counter < E > result = c1 . getFactory ( ) . create ( ) ; for ( E key : Sets . union ( c1 . keySet ( ) , c2 . keySet ( ) ) ) { double newCount = Math . abs ( c1 . getCount ( key ) - c2 . getCount ( key ) ) ; if ( newCount > 0 ) { result . setCount ( key , newCount ) ; } } return result ; }
Returns |c1 - c2| .