@Test public void testContains() { list.addRange(4, 7); list.addRange(10,11); assertTrue(!list.contains(2)); assertTrue(!list.contains(3)); assertTrue(list.contains(4)); assertTrue(list.contains(5)); assertTrue(list.contains(6)); assertTrue(list.contains(7)); assertTrue(!list.contains(8)); assertTrue(!list.contains(9)); assertTrue(list.contains(10)); assertTrue(list.contains(11)); assertTrue(!list.contains(12)); assertTrue(!list.contains(13)); }
@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);  }