MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / count

Method count

reflection/PetCounter3.java:20–26  ·  view source on GitHub ↗
(Pet pet)

Source from the content-addressed store, hash-verified

18 Collectors.toMap(Pair::key, Pair::value)));
19 }
20 public void count(Pet pet) {
21 // Class.isInstance() eliminates instanceofs:
22 entrySet().stream()
23 .filter(pair -> pair.getKey().isInstance(pet))
24 .forEach(pair ->
25 put(pair.getKey(), pair.getValue() + 1));
26 }
27 @Override public String toString() {
28 String result = entrySet().stream()
29 .map(pair -> String.format("%s=%s",

Callers

nothing calls this directly

Calls 5

streamMethod · 0.45
entrySetMethod · 0.45
getKeyMethod · 0.45
putMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected