@Test public void testIntersects() { list.addRange(10,19); list.addRange(40,49); list.addRange(60,69); assertTrue(!list.intersects(0,5)); assertTrue(!list.intersects(0,9)); assertTrue(!list.intersects(20,39)); assertTrue(!list.intersects(50,55)); assertTrue(!list.intersects(50,59)); assertTrue(!list.intersects(70,80)); assertTrue(!list.intersects(100,200)); assertTrue(list.intersects(0,10)); assertTrue(list.intersects(0,11)); assertTrue(list.intersects(0,19)); assertTrue(list.intersects(0,20)); assertTrue(list.intersects(0,21)); assertTrue(list.intersects(0,45)); assertTrue(list.intersects(0, 100)); assertTrue(list.intersects(9,10)); assertTrue(list.intersects(9,11)); assertTrue(list.intersects(9,19)); assertTrue(list.intersects(9,20)); assertTrue(list.intersects(9,21)); assertTrue(list.intersects(9,40)); assertTrue(list.intersects(9,100)); assertTrue(list.intersects(10,10)); assertTrue(list.intersects(10,11)); assertTrue(list.intersects(10,19)); assertTrue(list.intersects(10,20)); assertTrue(list.intersects(10,21)); assertTrue(list.intersects(10,40)); assertTrue(list.intersects(10,100)); assertTrue(list.intersects(11,11)); assertTrue(list.intersects(11,19)); assertTrue(list.intersects(11,20)); assertTrue(list.intersects(11,21)); assertTrue(list.intersects(11,40)); assertTrue(list.intersects(11,100)); assertTrue(list.intersects(15,16)); assertTrue(list.intersects(15,19)); assertTrue(list.intersects(15,20)); assertTrue(list.intersects(15,21)); assertTrue(list.intersects(15,40)); assertTrue(list.intersects(15,100)); }
@Override public void addRange(int min, int max) { Range key = new Range(min, min); SortedSet<Range> headSet = set.headSet(key); if (!headSet.isEmpty()) { Range last = headSet.last(); if (min <= last.max){ last.max = Math.max(last.max, max); coalesce(last, set.tailSet(key).iterator()); return; } } SortedSet<Range> ss = set.tailSet(key); if (ss.isEmpty()) { set.add(new Range(min, max)); return; } Iterator<Range> it = ss.iterator(); Range first = it.next(); if (max < first.min) { set.add(new Range(min, max)); return; } first.min = Math.min(first.min, min); first.max = Math.max(first.max, max); coalesce(first, it); }
AdjacentSortedRangeList extends SortedRangeList { @Override public void addRange(int min, int max) { Range key = new Range(min, min); SortedSet<Range> headSet = set.headSet(key); if (!headSet.isEmpty()) { Range last = headSet.last(); if (min <= last.max){ last.max = Math.max(last.max, max); coalesce(last, set.tailSet(key).iterator()); return; } } SortedSet<Range> ss = set.tailSet(key); if (ss.isEmpty()) { set.add(new Range(min, max)); return; } Iterator<Range> it = ss.iterator(); Range first = it.next(); if (max < first.min) { set.add(new Range(min, max)); return; } first.min = Math.min(first.min, min); first.max = Math.max(first.max, max); coalesce(first, it); } }
AdjacentSortedRangeList extends SortedRangeList { @Override public void addRange(int min, int max) { Range key = new Range(min, min); SortedSet<Range> headSet = set.headSet(key); if (!headSet.isEmpty()) { Range last = headSet.last(); if (min <= last.max){ last.max = Math.max(last.max, max); coalesce(last, set.tailSet(key).iterator()); return; } } SortedSet<Range> ss = set.tailSet(key); if (ss.isEmpty()) { set.add(new Range(min, max)); return; } Iterator<Range> it = ss.iterator(); Range first = it.next(); if (max < first.min) { set.add(new Range(min, max)); return; } first.min = Math.min(first.min, min); first.max = Math.max(first.max, max); coalesce(first, it); } AdjacentSortedRangeList();  AdjacentSortedRangeList(AdjacentSortedRangeList list); }
AdjacentSortedRangeList extends SortedRangeList { @Override public void addRange(int min, int max) { Range key = new Range(min, min); SortedSet<Range> headSet = set.headSet(key); if (!headSet.isEmpty()) { Range last = headSet.last(); if (min <= last.max){ last.max = Math.max(last.max, max); coalesce(last, set.tailSet(key).iterator()); return; } } SortedSet<Range> ss = set.tailSet(key); if (ss.isEmpty()) { set.add(new Range(min, max)); return; } Iterator<Range> it = ss.iterator(); Range first = it.next(); if (max < first.min) { set.add(new Range(min, max)); return; } first.min = Math.min(first.min, min); first.max = Math.max(first.max, max); coalesce(first, it); } AdjacentSortedRangeList();  AdjacentSortedRangeList(AdjacentSortedRangeList list); @Override void addRange(int min, int max); AdjacentSortedRangeList intersect(AdjacentSortedRangeList other); }
AdjacentSortedRangeList extends SortedRangeList { @Override public void addRange(int min, int max) { Range key = new Range(min, min); SortedSet<Range> headSet = set.headSet(key); if (!headSet.isEmpty()) { Range last = headSet.last(); if (min <= last.max){ last.max = Math.max(last.max, max); coalesce(last, set.tailSet(key).iterator()); return; } } SortedSet<Range> ss = set.tailSet(key); if (ss.isEmpty()) { set.add(new Range(min, max)); return; } Iterator<Range> it = ss.iterator(); Range first = it.next(); if (max < first.min) { set.add(new Range(min, max)); return; } first.min = Math.min(first.min, min); first.max = Math.max(first.max, max); coalesce(first, it); } AdjacentSortedRangeList();  AdjacentSortedRangeList(AdjacentSortedRangeList list); @Override void addRange(int min, int max); AdjacentSortedRangeList intersect(AdjacentSortedRangeList other);  }