public static < E > Counter < E > average ( Counter < E > c1 , Counter < E > c2 ) { Counter < E > average = c1 . getFactory ( ) . create ( ) ; Set < E > allKeys = new HashSet < E > ( c1 . keySet ( ) ) ; allKeys . addAll ( c2 . keySet ( ) ) ; for ( E key : allKeys ) { average . setCount ( key , ( c1 . getCount ( key ) + c2 . getCount ( key ) ) * 0.5 ) ; } return average ; }
Returns a new Counter with counts averaged from the two given Counters . The average Counter will contain the union of keys in both source Counters and each count will be the average of the two source counts for that key where as usual a missing count in one Counter is treated as count 0 .