public TextSet build() { return new TextSet(symbols, lengthOfOrigin); }
private static TextSet createTextSet(Collection<Block> fileBlocks, Map<String, List<Block>> fromIndex) { TextSet.Builder textSetBuilder = TextSet.builder(); // TODO Godin: maybe we can reduce size of tree and so memory consumption by removing non-repeatable blocks List<Block> sortedFileBlocks = new ArrayList<>(fileBlocks); Collections.sort(sortedFileBlocks, BLOCK_COMPARATOR); textSetBuilder.add(sortedFileBlocks); for (List<Block> list : fromIndex.values()) { Collections.sort(list, BLOCK_COMPARATOR); int i = 0; while (i < list.size()) { int j = i + 1; while ((j < list.size()) && (list.get(j).getIndexInFile() == list.get(j - 1).getIndexInFile() + 1)) { j++; } textSetBuilder.add(list.subList(i, j)); i = j; } } return textSetBuilder.build(); }
public DuplicationsCollector(TextSet text) { this.text = text; this.originResourceId = text.getBlock(0).getResourceId(); }
/** * TODO Godin: in fact computations here are the same as in {@link #report(Node)}, * so maybe would be better to remove this duplication, * however it should be noted that this check can't be done in {@link Collector#endOfGroup()}, * because it might lead to creation of unnecessary new objects */ private boolean containsOrigin(Node node) { for (int i = node.startSize; i < node.endSize; i++) { int start = tree.text.length() - list.get(i); int end = start + node.depth; if (text.isInsideOrigin(end)) { return true; } } return false; }
/** * TODO Godin: in fact computations here are the same as in {@link #report(Node)}, * so maybe would be better to remove this duplication, * however it should be noted that this check can't be done in {@link Collector#endOfGroup()}, * because it might lead to creation of unnecessary new objects */ private boolean containsOrigin(Node node) { for (int i = node.startSize; i < node.endSize; i++) { int start = tree.text.length() - list.get(i); int end = start + node.depth; if (text.isInsideOrigin(end)) { return true; } } return false; }
public TextSet build() { return new TextSet(symbols, lengthOfOrigin); }
private static TextSet createTextSet(Collection<Block> fileBlocks, Map<String, List<Block>> fromIndex) { TextSet.Builder textSetBuilder = TextSet.builder(); // TODO Godin: maybe we can reduce size of tree and so memory consumption by removing non-repeatable blocks List<Block> sortedFileBlocks = Lists.newArrayList(fileBlocks); Collections.sort(sortedFileBlocks, BLOCK_COMPARATOR); textSetBuilder.add(sortedFileBlocks); for (List<Block> list : fromIndex.values()) { Collections.sort(list, BLOCK_COMPARATOR); int i = 0; while (i < list.size()) { int j = i + 1; while ((j < list.size()) && (list.get(j).getIndexInFile() == list.get(j - 1).getIndexInFile() + 1)) { j++; } textSetBuilder.add(list.subList(i, j)); i = j; } } return textSetBuilder.build(); }
public DuplicationsCollector(TextSet text) { this.text = text; this.originResourceId = text.getBlock(0).getResourceId(); }