|
8 | 8 | @Slf4j |
9 | 9 | public class ChangePronenessRanker { |
10 | 10 |
|
11 | | - private final Map<Integer, Integer> changeCountsByTimeStamps = new HashMap<>(); |
| 11 | + private final TreeMap<Integer, Integer> changeCountsByTimeStamps = new TreeMap<>(); |
12 | 12 | private final Map<String, ScmLogInfo> cachedScmLogInfos = new HashMap<>(); |
13 | 13 |
|
14 | 14 | public ChangePronenessRanker(GitLogReader repositoryLogReader) { |
15 | 15 | try { |
16 | 16 | log.info("Capturing change count based on commit timestamps"); |
17 | | - changeCountsByTimeStamps.putAll( |
18 | | - computeChangeCountsByTimeStamps(repositoryLogReader.captureChangeCountByCommitTimestamp())); |
| 17 | + changeCountsByTimeStamps.putAll(repositoryLogReader.captureChangeCountByCommitTimestamp()); |
19 | 18 | } catch (IOException | GitAPIException e) { |
20 | 19 | log.error("Error reading from repository: {}", e.getMessage()); |
21 | 20 | } |
22 | 21 | } |
23 | 22 |
|
24 | | - private Map<Integer, Integer> computeChangeCountsByTimeStamps(TreeMap<Integer, Integer> commitsWithChangeCounts) { |
25 | | - HashMap<Integer, Integer> changeCountsByTimeStamps = new HashMap<>(); |
26 | | - int runningTotal = 0; |
27 | | - for (Map.Entry<Integer, Integer> commitChangeCountEntry : |
28 | | - commitsWithChangeCounts.descendingMap().entrySet()) { |
29 | | - runningTotal += commitChangeCountEntry.getValue(); |
30 | | - changeCountsByTimeStamps.put(commitChangeCountEntry.getKey(), runningTotal); |
31 | | - } |
32 | | - |
33 | | - return changeCountsByTimeStamps; |
34 | | - } |
35 | | - |
36 | 23 | public void rankChangeProneness(List<ScmLogInfo> scmLogInfos) { |
37 | 24 | for (ScmLogInfo scmLogInfo : scmLogInfos) { |
38 | 25 | if (!cachedScmLogInfos.containsKey(scmLogInfo.getPath())) { |
39 | | - if (scmLogInfo.getEarliestCommit() == 0) { |
40 | | - log.warn("No commits found for {}", scmLogInfo.getPath()); |
41 | | - continue; |
42 | | - } |
43 | | - |
44 | | - int commitsInRepositorySinceCreation = changeCountsByTimeStamps.get(scmLogInfo.getEarliestCommit()); |
| 26 | + int commitsInRepositorySinceCreation = |
| 27 | + changeCountsByTimeStamps.tailMap(scmLogInfo.getEarliestCommit()).values().stream() |
| 28 | + .mapToInt(i -> i) |
| 29 | + .sum(); |
45 | 30 |
|
46 | 31 | scmLogInfo.setChangeProneness((float) scmLogInfo.getCommitCount() / commitsInRepositorySinceCreation); |
47 | 32 | cachedScmLogInfos.put(scmLogInfo.getPath(), scmLogInfo); |
|
0 commit comments