@Test public void testBuildRanges() { int[] test1 = { 1, 2, 3, 5, 7, 8, 10, 4 }; TreeSet<Integer> treeSet = Sets.newTreeSet(); for (int t : test1) { treeSet.add(t); } List<Range<Integer>> ranges = RangeUtil.buildRanges(new TreeSet<Integer>(treeSet)); Assert.assertEquals(3, ranges.size()); }
public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; }
RangeUtil { public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; } }
RangeUtil { public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; } private  RangeUtil(); }
RangeUtil { public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; } private  RangeUtil(); static NavigableMap<C, V> filter(NavigableMap<C, V> values, Range<C> filterRange); static boolean lowerBoundInclusive(Range<C> range); static boolean upperBoundInclusive(Range<C> range); static Range<C> merge(Range<C> a, Range<C> b); static List<Range<C>> remove(Range<C> self, Range<C> other); static String formatTsRange(Range<Long> tsRange); static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values); }
RangeUtil { public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; } private  RangeUtil(); static NavigableMap<C, V> filter(NavigableMap<C, V> values, Range<C> filterRange); static boolean lowerBoundInclusive(Range<C> range); static boolean upperBoundInclusive(Range<C> range); static Range<C> merge(Range<C> a, Range<C> b); static List<Range<C>> remove(Range<C> self, Range<C> other); static String formatTsRange(Range<Long> tsRange); static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values);  }