/**
* Constructs CloneGroup and saves it.
*/
@Override
public void endOfGroup() {
ClonePart origin = null;
CloneGroup.Builder builder = CloneGroup.builder().setLength(length);
List<ClonePart> parts = Lists.newArrayListWithCapacity(count);
for (int[] b : blockNumbers) {
Block firstBlock = text.getBlock(b[0]);
Block lastBlock = text.getBlock(b[1]);
ClonePart part = new ClonePart(
firstBlock.getResourceId(),
firstBlock.getIndexInFile(),
firstBlock.getStartLine(),
lastBlock.getEndLine());
// TODO Godin: maybe use FastStringComparator here ?
if (originResourceId.equals(part.getResourceId())) {
// part from origin
if (origin == null) {
origin = part;
// To calculate length important to use the origin, because otherwise block may come from DB without required data
builder.setLengthInUnits(lastBlock.getEndUnit() - firstBlock.getStartUnit() + 1);
} else if (part.getUnitStart() < origin.getUnitStart()) {
origin = part;
}
}
parts.add(part);