### Question:
MergedCandidateSentence { public static Optional<MergedCandidateSentence> merge(List<CandidateSentence> candidateSentences) { if (candidateSentences.size() == 0) { return Optional.empty(); } int lineNum = candidateSentences.get(0).getLineNum(); StringBuilder contents = new StringBuilder(); Map<LineOffset, String> links = new HashMap<>(); List<LineOffset> offsetMap = new ArrayList<>(); for (CandidateSentence sentence : candidateSentences) { contents.append(sentence.getContent()); offsetMap.addAll(sentence.getOffsetMap()); if (sentence.getLink() != null && sentence.getOffsetMap().size() > 0) { links.put(sentence.getOffsetMap().get(0), sentence.getLink()); } } if (offsetMap.size() != contents.length()) { LOG.warn("Size of offset map (\"{}\") is not the same as sentence length \"{}\": ", offsetMap.size(), contents.length(), contents); } return Optional.of(new MergedCandidateSentence(lineNum, contents.toString(), links, offsetMap)); } MergedCandidateSentence(int lineNum, String contents,
            Map<LineOffset, String> links, List<LineOffset> offsetMap); static Optional<MergedCandidateSentence> merge(List<CandidateSentence> candidateSentences); List<String> getRangedLinks(int startPosition, int endPosition); String getContents(); Map<LineOffset, String> getLinks(); List<LineOffset> getOffsetMap(); int getLineNum(); @Override String toString();  }### Answer:
@Test void testMerge() { List<CandidateSentence> candidateSentences = initializeCandidateSentences( new CandidateSentence(1, "first ", "", 0), new CandidateSentence(1, "second ", "", 6), new CandidateSentence(1, "third", "", 13)); MergedCandidateSentence mergedSentence = MergedCandidateSentence.merge(candidateSentences).get(); assertTrue(mergedSentence != null); assertEquals("first second third", mergedSentence.getContents()); List<LineOffset> expectedOffsets = initializeMappingTable( new LineOffset(1, 0), new LineOffset(1, 1), new LineOffset(1, 2), new LineOffset(1, 3), new LineOffset(1, 4), new LineOffset(1, 5), new LineOffset(1, 6), new LineOffset(1, 7), new LineOffset(1, 8), new LineOffset(1, 9), new LineOffset(1, 10), new LineOffset(1, 11), new LineOffset(1, 12), new LineOffset(1, 13), new LineOffset(1, 14), new LineOffset(1, 15), new LineOffset(1, 16), new LineOffset(1, 17)); assertEquals(expectedOffsets.size(), mergedSentence.getOffsetMap().size()); for (int i = 0; i < expectedOffsets.size() ; i++) { assertEquals(expectedOffsets.get(i), mergedSentence.getOffsetMap().get(i)); } }