.thenComparing(DuplicateToFileKey.INSTANCE).thenComparing(DuplicateToTextBlock.INSTANCE);
private final TextBlock original;
- private final SortedSet<Duplicate> duplicates;
+ private final Duplicate[] duplicates;
/**
* @throws NullPointerException if {@code original} is {@code null} or {@code duplicates} is {@code null} or {@code duplicates} contains {@code null}
public Duplication(TextBlock original, List<Duplicate> duplicates) {
this.original = requireNonNull(original, "original TextBlock can not be null");
validateDuplicates(original, duplicates);
- this.duplicates = new TreeSet<>(DUPLICATE_COMPARATOR);
- this.duplicates.addAll(duplicates);
+ this.duplicates = duplicates.stream().sorted(DUPLICATE_COMPARATOR).distinct().toArray(Duplicate[]::new);
}
private static void validateDuplicates(TextBlock original, List<Duplicate> duplicates) {
* </ul
* <p>The returned set can not be empty and no inner duplicate can contain the original {@link TextBlock}.</p>
*/
- public SortedSet<Duplicate> getDuplicates() {
+ public Duplicate[] getDuplicates() {
return this.duplicates;
}
package org.sonar.ce.task.projectanalysis.duplication;
import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
for (Duplication duplication : duplications) {
blocks++;
addLines(duplication.getOriginal(), duplicatedLineNumbers);
- InnerDuplicate[] innerDuplicates = duplication.getDuplicates().stream()
+ InnerDuplicate[] innerDuplicates = Arrays.stream(duplication.getDuplicates())
.filter(x -> x instanceof InnerDuplicate)
.map(d -> (InnerDuplicate) d)
.toArray(InnerDuplicate[]::new);
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
issue.setSelectedAt(System.currentTimeMillis());
result.add(issue);
});
- return ImmutableList.copyOf(result);
+ return Collections.unmodifiableList(result);
}
private static void setChanges(Map<String, List<IssueChangeDto>> changeDtoByIssueKey, DefaultIssue i) {
boolean hasChangesetForLine(int lineNumber);
/**
- * Return all ChangeSets, in order, for all lines that have changesets.
+ * Return all ChangeSets, index by line number. Some values might be null.
*/
Changeset[] getAllChangesets();
@Override
public boolean hasChangesetForLine(int lineNumber) {
- return lineNumber - 1 < lineChangesets.length && lineChangesets[lineNumber - 1] != null;
+ return lineNumber > 0 && lineNumber - 1 < lineChangesets.length && lineChangesets[lineNumber - 1] != null;
}
@Override
package org.sonar.ce.task.projectanalysis.source.linereader;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import org.sonar.ce.task.projectanalysis.duplication.TextBlock;
import org.sonar.db.protobuf.DbFileSources;
-import static com.google.common.collect.FluentIterable.from;
import static com.google.common.collect.Iterables.size;
public class DuplicationLineReader implements LineReader {
List<TextBlock> duplicatedBlock = new ArrayList<>(size(duplications));
for (Duplication duplication : duplications) {
duplicatedBlock.add(duplication.getOriginal());
- for (InnerDuplicate duplicate : from(duplication.getDuplicates()).filter(InnerDuplicate.class)) {
- duplicatedBlock.add(duplicate.getTextBlock());
- }
+ Arrays.stream(duplication.getDuplicates())
+ .filter(d -> d instanceof InnerDuplicate)
+ .forEach(duplicate -> duplicatedBlock.add(duplicate.getTextBlock()));
}
return duplicatedBlock;
}
private void processSymbols(DbFileSources.Line.Builder lineBuilder) {
int line = lineBuilder.getLine();
- List<ScannerReport.Symbol> lineSymbols = new ArrayList<>(this.symbolsPerLine.get(line));
// Sort symbols to have deterministic results and avoid false variation that would lead to an unnecessary update of the source files
// data
- lineSymbols.sort(SymbolsComparator.INSTANCE);
-
StringBuilder symbolString = new StringBuilder();
- for (ScannerReport.Symbol lineSymbol : lineSymbols) {
+ symbolsPerLine.get(line).stream().sorted(SymbolsComparator.INSTANCE).forEach(lineSymbol -> {
int symbolId = idsBySymbol.get(lineSymbol);
appendSymbol(symbolString, lineSymbol.getDeclaration(), line, symbolId, lineBuilder.getSource());
for (ScannerReport.TextRange range : lineSymbol.getReferenceList()) {
appendSymbol(symbolString, range, line, symbolId, lineBuilder.getSource());
}
- }
+ });
if (symbolString.length() > 0) {
lineBuilder.setSymbols(symbolString.toString());
}
package org.sonar.ce.task.projectanalysis.step;
import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
Iterable<Duplication> duplications = duplicationRepository.getDuplications(component);
for (Duplication duplication : duplications) {
duplicationCounters.addBlock(duplication.getOriginal());
- duplication.getDuplicates().stream()
+ Arrays.stream(duplication.getDuplicates())
.filter(InnerDuplicate.class::isInstance)
.map(duplicate -> (InnerDuplicate) duplicate)
.forEach(duplicate -> duplicationCounters.addBlock(duplicate.getTextBlock()));