@Override public int compare(ClonePart o1, ClonePart o2) { int c = RESOURCE_ID_COMPARATOR.compare(o1, o2); if (c == 0) { return o1.getUnitStart() - o2.getUnitStart(); } return c; } };
/** * Compares two parts on inclusion. * part1 includes part2 if {@code (part1.resourceId == part2.resourceId) && (part1.unitStart <= part2.unitStart) && (part2.unitEnd <= part1.unitEnd)}. * * @return 0 if part1 includes part2, * 1 if resourceId of part1 is greater than resourceId of part2 or if unitStart of part1 is greater than unitStart of part2, * -1 in all other cases */ @Override public int compare(ClonePart part1, ClonePart part2) { int c = RESOURCE_ID_COMPARATOR.compare(part1, part2); if (c == 0) { if (part1.getUnitStart() <= part2.getUnitStart()) { if (part2.getUnitStart() + l2 <= part1.getUnitStart() + l1) { // part1 contains part2 return 0; } else { // SortedListsUtils#contains should continue search return -1; } } else { // unitStart of part1 is less than unitStart of part2 - SortedListsUtils#contains should stop search return 1; } } else { return c; } }
private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) { List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength); ClonePart origin = null; List<ClonePart> parts = new ArrayList<>(); for (int i = 0; i < pairs.size(); i++) { Block[] pair = pairs.get(i); Block firstBlock = pair[0]; Block lastBlock = pair[1]; ClonePart part = new ClonePart(firstBlock.getResourceId(), firstBlock.getIndexInFile(), firstBlock.getStartLine(), lastBlock.getEndLine()); if (originResourceId.equals(part.getResourceId())) { if (origin == null || part.getUnitStart() < origin.getUnitStart()) { origin = part; } } parts.add(part); } filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build()); }
} else if (part.getUnitStart() < origin.getUnitStart()) { origin = part;
@Override public int compare(ClonePart o1, ClonePart o2) { int c = RESOURCE_ID_COMPARATOR.compare(o1, o2); if (c == 0) { return o1.getUnitStart() - o2.getUnitStart(); } return c; } };
/** * Compares two parts on inclusion. * part1 includes part2 if {@code (part1.resourceId == part2.resourceId) && (part1.unitStart <= part2.unitStart) && (part2.unitEnd <= part1.unitEnd)}. * * @return 0 if part1 includes part2, * 1 if resourceId of part1 is greater than resourceId of part2 or if unitStart of part1 is greater than unitStart of part2, * -1 in all other cases */ @Override public int compare(ClonePart part1, ClonePart part2) { int c = RESOURCE_ID_COMPARATOR.compare(part1, part2); if (c == 0) { if (part1.getUnitStart() <= part2.getUnitStart()) { if (part2.getUnitStart() + l2 <= part1.getUnitStart() + l1) { // part1 contains part2 return 0; } else { // SortedListsUtils#contains should continue search return -1; } } else { // unitStart of part1 is less than unitStart of part2 - SortedListsUtils#contains should stop search return 1; } } else { return c; } }
private void reportClones(BlocksGroup beginGroup, BlocksGroup endGroup, int cloneLength) { List<Block[]> pairs = beginGroup.pairs(endGroup, cloneLength); ClonePart origin = null; List<ClonePart> parts = Lists.newArrayList(); for (int i = 0; i < pairs.size(); i++) { Block[] pair = pairs.get(i); Block firstBlock = pair[0]; Block lastBlock = pair[1]; ClonePart part = new ClonePart(firstBlock.getResourceId(), firstBlock.getIndexInFile(), firstBlock.getStartLine(), lastBlock.getEndLine()); if (originResourceId.equals(part.getResourceId())) { if (origin == null) { origin = part; } else if (part.getUnitStart() < origin.getUnitStart()) { origin = part; } } parts.add(part); } filter.add(CloneGroup.builder().setLength(cloneLength).setOrigin(origin).setParts(parts).build()); }
} else if (part.getUnitStart() < origin.getUnitStart()) { origin = part;