AlignedString implements Iterable<AlignedString.DataSegment> { public void insert(final int pos, final String s) { if (s.length() == 0) { return; } final AbstractDataSegment prefix; final AbstractDataSegment suffix; if (pos == 0) { prefix = _first; suffix = _first._next; } else { prefix = getSegmentAt(pos); suffix = prefix.split(pos); } final BaseSegment seg = new BaseSegment(prefix, suffix, s); prefix._next = seg; suffix._prev = seg; fireChange(); } private  AlignedString();  AlignedString(final String base);  AlignedString(final AlignedString underlying); void fireChange(); Interval resolve(final Interval i); ImmutableInterval inverseResolve(final ImmutableInterval i); AbstractDataSegment getSegmentAt(final int position); AbstractDataSegment getFirst(); AbstractDataSegment getLast(); @Override Iterator<DataSegment> iterator(); int length(); String get(); void updateCaches(); String get(final int start, final int end); void insert(final int pos, final String s); void delete(final int start, final int end); void replace(final int start, final int end, final String d); Anchor getAnchor(final int pos); Collection<Anchor> getAnchors(); Collection<DataSegment> getSegments(); String dataSegmentsToString(); @Override String toString();  }
@Test public void testInsert() { final String insertString = "such "; final int insertPos = 2; bottom.insert(insertPos, insertString); final StringBuilder sb = new StringBuilder(baseString); sb.insert(insertPos, insertString); assertEquals(sb.toString(), bottom.get()); assertEquals(sb.toString(), top.get()); }