AlignedString implements Iterable<AlignedString.DataSegment> { public Interval resolve(final Interval i) { if (_underlying == null) { return i; } final DataSegment startSeg = getSegmentAt(i.getStart(), true); final DataSegment endSeg = getSegmentAt( (i.getStart() != i.getEnd()) ? i.getEnd() - 1 : i.getEnd(), true); DataSegment cursor = startSeg; int start; while (true) { if (cursor == null) { start = _underlying._first.getStart(); break; } else if (cursor instanceof ObliqueSegment) { final ObliqueSegment oseg = (ObliqueSegment) cursor; if (cursor == startSeg) { final int pos = i.getStart() - oseg.getStart(); start = oseg._start.getPosition() + pos; break; } else { start = oseg._end.getPosition(); break; } } else { cursor = cursor.getPrevious(); } } cursor = endSeg; int end; while (true) { if (cursor == null) { if ((startSeg instanceof ObliqueSegment) && (startSeg.length() >= i.getLength())) { final ObliqueSegment oseg = (ObliqueSegment) startSeg; final int pos = i.getEnd() - oseg.getStart(); end = oseg._start.getPosition() + pos; } else { end = _underlying._last.getEnd(); } break; } else if (cursor instanceof ObliqueSegment) { final ObliqueSegment oseg = (ObliqueSegment) cursor; if (cursor == endSeg) { final int pos = i.getEnd() - oseg.getStart(); end = oseg._start.getPosition() + pos; break; } else { end = oseg._start.getPosition(); break; } } else { cursor = cursor.getNext(); } } if (end < start) { throw new IllegalStateException("BUG: End [" + end + "] of resolved interval before start [" + start + "]!"); } return new ImmutableInterval(start, end); } 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 testResolve() { top.delete(4, 7); final ImmutableInterval ri = new ImmutableInterval(3, 4); final Interval i = top.resolve(ri); assertEquals(1, i.getLength()); }