}
private void mapNewissues(SourceHashHolder sourceHashHolder, Collection<DefaultIssue> newIssues, IssueTrackingResult result) {
HashedSequenceComparator<StringText> hashedComparator = new HashedSequenceComparator<StringText>(StringTextComparator.IGNORE_WHITESPACE);
IssueTrackingBlocksRecognizer rec = new IssueTrackingBlocksRecognizer(sourceHashHolder.getHashedReference(), sourceHashHolder.getHashedSource(), hashedComparator);
RollingHashSequence<HashedSequence<StringText>> a = RollingHashSequence.wrap(sourceHashHolder.getHashedReference(), hashedComparator, 5);
RollingHashSequence<HashedSequence<StringText>> b = RollingHashSequence.wrap(sourceHashHolder.getHashedSource(), hashedComparator, 5);
RollingHashSequenceComparator<HashedSequence<StringText>> cmp = new RollingHashSequenceComparator<HashedSequence<StringText>>(hashedComparator);
Multimap<Integer, DefaultIssue> newIssuesByLines = newIssuesByLines(newIssues, rec, result);
Multimap<Integer, IssueDto> lastIssuesByLines = lastIssuesByLines(result.unmatched(), rec);
Map<Integer, HashOccurrence> map = Maps.newHashMap();
for (Integer line : lastIssuesByLines.keySet()) {
int hash = cmp.hash(a, line - 1);
HashOccurrence hashOccurrence = map.get(hash);
if (hashOccurrence == null) {
// first occurrence in A
hashOccurrence = new HashOccurrence();
hashOccurrence.lineA = line;
hashOccurrence.countA = 1;
map.put(hash, hashOccurrence);
} else {
hashOccurrence.countA++;
}
}
for (Integer line : newIssuesByLines.keySet()) {
int hash = cmp.hash(b, line - 1);
HashOccurrence hashOccurrence = map.get(hash);
if (hashOccurrence != null) {
hashOccurrence.lineB = line;
hashOccurrence.countB++;
}
}
for (HashOccurrence hashOccurrence : map.values()) {
if (hashOccurrence.countA == 1 && hashOccurrence.countB == 1) {
// Guaranteed that lineA has been moved to lineB, so we can map all issues on lineA to all issues on lineB
map(newIssuesByLines.get(hashOccurrence.lineB), lastIssuesByLines.get(hashOccurrence.lineA), result);
lastIssuesByLines.removeAll(hashOccurrence.lineA);
newIssuesByLines.removeAll(hashOccurrence.lineB);
}
}
// Check if remaining number of lines exceeds threshold
if (lastIssuesByLines.keySet().size() * newIssuesByLines.keySet().size() < 250000) {
List<LinePair> possibleLinePairs = Lists.newArrayList();
for (Integer oldLine : lastIssuesByLines.keySet()) {
for (Integer newLine : newIssuesByLines.keySet()) {
int weight = rec.computeLengthOfMaximalBlock(oldLine - 1, newLine - 1);
possibleLinePairs.add(new LinePair(oldLine, newLine, weight));
}
}
Collections.sort(possibleLinePairs, LINE_PAIR_COMPARATOR);
for (LinePair linePair : possibleLinePairs) {