Hendrik Jungnitsch
2022-09-29 afabd75c4009cbc0f784bbf1f7a74b1ec083a7f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package de.gedoplan.seminar.sbt.di.exercise.aop;
 
import org.springframework.stereotype.Component;
 
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.Collectors;
 
@Component
public class MethodCounter {
 
    private ConcurrentMap<String, LongAdder> methodCounts = new ConcurrentHashMap<>();
 
 
    protected void increase(String methodName) {
        methodCounts.computeIfAbsent(methodName,s -> new LongAdder())
                .increment();
    }
 
    public Map<String,Long> getMethodCounts() {
        return methodCounts.entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey,e -> e.getValue().longValue()));
 
    }
}