duplications.add(createDuplication(componentsByKey, from, size, componentKey, session));
}
}
- Collections.sort(duplications, new DuplicationComparator(component));
+ Collections.sort(duplications, new DuplicationComparator(component.uuid(), component.projectUuid()));
blocks.add(new Block(duplications));
}
Collections.sort(blocks, new BlockComparator());
static class DuplicationComparator implements Comparator<Duplication>, Serializable {
private static final long serialVersionUID = 1;
- private final ComponentDto component;
+ private final String uuid;
+ private final String projectUuid;
- DuplicationComparator(ComponentDto component) {
- this.component = component;
+ DuplicationComparator(String uuid, String projectUuid) {
+ this.uuid = uuid;
+ this.projectUuid = projectUuid;
}
@Override
if (file1.equals(d2.file())) {
// if duplication on same file => order by starting line
return d1.from().compareTo(d2.from());
- } else if (file1.equals(component)) {
+ } else if (file1.uuid().equals(uuid)) {
// the current resource must be displayed first
return -1;
- } else if (file2.equals(component)) {
+ } else if (file2.uuid().equals(uuid)) {
// the current resource must be displayed first
return 1;
- } else if (StringUtils.equals(file1.projectUuid(), component.projectUuid()) && !StringUtils.equals(file2.projectUuid(), component.projectUuid())) {
+ } else if (StringUtils.equals(file1.projectUuid(), projectUuid) && !StringUtils.equals(file2.projectUuid(), projectUuid)) {
// if resource is in the same project, this it must be displayed first
return -1;
- } else if (StringUtils.equals(file2.projectUuid(), component.projectUuid()) && !StringUtils.equals(file1.projectUuid(), component.projectUuid())) {
+ } else if (StringUtils.equals(file2.projectUuid(), projectUuid) && !StringUtils.equals(file1.projectUuid(), projectUuid)) {
// if resource is in the same project, this it must be displayed first
return 1;
} else {
ComponentDto fileOnSameProject = ComponentTesting.newFileDto(project1).setId(12L);
ComponentDto fileOnDifferentProject = ComponentTesting.newFileDto(project2).setId(13L);
- DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile);
+ DuplicationsParser.DuplicationComparator comparator = new DuplicationsParser.DuplicationComparator(currentFile.uuid(), currentFile.projectUuid());
// On same file
assertThat(comparator.compare(new DuplicationsParser.Duplication(currentFile, 2, 2), new DuplicationsParser.Duplication(currentFile, 5, 2))).isEqualTo(-1);