### Question:
AdjacentSortedRangeList extends SortedRangeList { public AdjacentSortedRangeList intersect(AdjacentSortedRangeList other) { AdjacentSortedRangeList srl = new AdjacentSortedRangeList(this); srl.remove(other); AdjacentSortedRangeList srl2 = new AdjacentSortedRangeList(this); srl2.remove(srl); int num = other.getNumRanges(); for(int otherIndex=0; otherIndex < num-1; otherIndex++) { Range r = other.getRange(otherIndex); Range rNext = other.getRange(otherIndex+1); if (r.max+1 == rNext.min) { int myIndex = srl2.getRangeIndex(r.max); if (myIndex < 0) { continue; } Range myRange = srl2.getRange(myIndex); int min = myRange.min; int max = myRange.max; if (max >= rNext.min) { srl2.removeRange(min, max); srl2.addRange(min, r.max); srl2.addRange(rNext.min, max); } } } return srl2; } AdjacentSortedRangeList();  AdjacentSortedRangeList(AdjacentSortedRangeList list); @Override void addRange(int min, int max); AdjacentSortedRangeList intersect(AdjacentSortedRangeList other);  }### Answer:
@Test public void testIntersect() { list.addRange(10,19); list.addRange(40,49); list.addRange(60,69); AdjacentSortedRangeList other = new AdjacentSortedRangeList(); other.addRange(5,15); other.addRange(38, 52); other.addRange(62,65); AdjacentSortedRangeList intersection = list.intersect(other); Iterator<Range> it = intersection.getRanges(); assertEquals(new Range(10,15), it.next()); assertEquals(new Range(40, 49), it.next()); assertEquals(new Range(62, 65), it.next()); }