/** Clones {@code this}, optionally also cloning the {@link SegmentInfo}. */ SegmentCommitInfo clone(boolean cloneSegmentInfo) { SegmentInfo otherInfo; if (cloneSegmentInfo) { otherInfo = info.clone(); } else { otherInfo = info; } SegmentCommitInfo other = new SegmentCommitInfo(otherInfo, delCount, delGen, fieldInfosGen, docValuesGen); // Not clear that we need to carry over nextWriteDelGen // (i.e. do we ever clone after a failed write and // before the next successful write?), but just do it to // be safe: other.nextWriteDelGen = nextWriteDelGen; other.nextWriteFieldInfosGen = nextWriteFieldInfosGen; other.nextWriteDocValuesGen = nextWriteDocValuesGen; // deep clone for (Entry<Long, Set<String>> e : genUpdatesFiles.entrySet()) { other.genUpdatesFiles.put(e.getKey(), new HashSet<>(e.getValue())); } // deep clone for (Entry<Integer, Set<String>> e : dvUpdatesFiles.entrySet()) { other.dvUpdatesFiles.put(e.getKey(), new HashSet<>(e.getValue())); } other.fieldInfosFiles.addAll(fieldInfosFiles); return other; }