public static <K,U,V> Map<K, Integer> countBy(Map<U,V> self, @ClosureParams(MapEntryOrKeyValue.class) Closure<K> closure) {
        Map<K, Integer> answer = new LinkedHashMap<K, Integer>();
        for (Object entry : self.entrySet()) {
            countAnswer(answer, callClosureForMapEntry(closure, (Map.Entry) entry));
        }
        return answer;
    }
public static < K , U , V > Map < K , Integer > countBy ( Map < U , V > self , @ ClosureParams ( MapEntryOrKeyValue . class ) Closure < K > closure ) { Map < K , Integer > answer = new LinkedHashMap < K , Integer > ( ) ; for ( Object entry : self . entrySet ( ) ) { countAnswer ( answer , callClosureForMapEntry ( closure , ( Map . Entry ) entry ) ) ; } return answer ; }
Groups the members of a map into groups determined by the
supplied mapping closure and counts the frequency of the created groups.
The closure will be passed a Map.Entry or
key and value (depending on the number of parameters the closure accepts)
and should return the key that each item should be grouped under.  The
resulting map will have an entry for each 'group' key returned by the
closure, with values being the frequency counts for that 'group'.
<p>
<pre class="groovyTestCase">def result = [a:1,b:2,c:3,d:4,e:5].countBy { it.value % 2 }
assert result == [0:2, 1:3]</pre>

@param self    a map to group and count
@param closure a closure mapping entries to frequency count keys
@return a new Map grouped by keys with frequency counts
@since 1.8.0