@Test public void testSize() { list.addRange(Integer.MIN_VALUE, Integer.MIN_VALUE+1); list.addRange(-1234,-1231); list.addRange(-13, -9); list.addRange(-8, -6); list.addRange(-1, 1); list.addRange(3, 4); list.addRange(6, 8); list.addRange(12, 15); list.addRange(16, 19); list.addRange(Integer.MAX_VALUE-1, Integer.MAX_VALUE); assertEquals(32, list.getNumValues()); }
@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);  }