@Test public void testMergeOverlapping5() { List<Range> rl = newRangeList(newRange("a", "e")); List<Range> expected = newRangeList(newRange("a", "e")); check(Range.mergeOverlapping(rl), expected); }
public static List<Range> mergeOverlapping(Collection<Range> ranges) { if (ranges.isEmpty()) return Collections.emptyList(); if (ranges.size() == 1) return Collections.singletonList(ranges.iterator().next()); List<Range> ral = new ArrayList<>(ranges); Collections.sort(ral); ArrayList<Range> ret = new ArrayList<>(ranges.size()); Range currentRange = ral.get(0); boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive; for (int i = 1; i < ral.size(); i++) { if (currentRange.infiniteStopKey) { break; } Range range = ral.get(i); boolean startKeysEqual; if (range.infiniteStartKey) { assert currentRange.infiniteStartKey; startKeysEqual = true; } else if (currentRange.infiniteStartKey) { startKeysEqual = false; } else { startKeysEqual = currentRange.start.equals(range.start); } if (startKeysEqual || currentRange.contains(range.start) || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) { int cmp; if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) { currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive); } } else { ret.add(currentRange); currentRange = range; currentStartKeyInclusive = range.startKeyInclusive; } } ret.add(currentRange); return ret; }
Range implements WritableComparable<Range> { public static List<Range> mergeOverlapping(Collection<Range> ranges) { if (ranges.isEmpty()) return Collections.emptyList(); if (ranges.size() == 1) return Collections.singletonList(ranges.iterator().next()); List<Range> ral = new ArrayList<>(ranges); Collections.sort(ral); ArrayList<Range> ret = new ArrayList<>(ranges.size()); Range currentRange = ral.get(0); boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive; for (int i = 1; i < ral.size(); i++) { if (currentRange.infiniteStopKey) { break; } Range range = ral.get(i); boolean startKeysEqual; if (range.infiniteStartKey) { assert currentRange.infiniteStartKey; startKeysEqual = true; } else if (currentRange.infiniteStartKey) { startKeysEqual = false; } else { startKeysEqual = currentRange.start.equals(range.start); } if (startKeysEqual || currentRange.contains(range.start) || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) { int cmp; if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) { currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive); } } else { ret.add(currentRange); currentRange = range; currentStartKeyInclusive = range.startKeyInclusive; } } ret.add(currentRange); return ret; } }
Range implements WritableComparable<Range> { public static List<Range> mergeOverlapping(Collection<Range> ranges) { if (ranges.isEmpty()) return Collections.emptyList(); if (ranges.size() == 1) return Collections.singletonList(ranges.iterator().next()); List<Range> ral = new ArrayList<>(ranges); Collections.sort(ral); ArrayList<Range> ret = new ArrayList<>(ranges.size()); Range currentRange = ral.get(0); boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive; for (int i = 1; i < ral.size(); i++) { if (currentRange.infiniteStopKey) { break; } Range range = ral.get(i); boolean startKeysEqual; if (range.infiniteStartKey) { assert currentRange.infiniteStartKey; startKeysEqual = true; } else if (currentRange.infiniteStartKey) { startKeysEqual = false; } else { startKeysEqual = currentRange.start.equals(range.start); } if (startKeysEqual || currentRange.contains(range.start) || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) { int cmp; if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) { currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive); } } else { ret.add(currentRange); currentRange = range; currentStartKeyInclusive = range.startKeyInclusive; } } ret.add(currentRange); return ret; } Range();  Range(Key startKey, Key endKey);  Range(CharSequence row);  Range(Text row);  Range(Text startRow, Text endRow);  Range(CharSequence startRow, CharSequence endRow);  Range(Text startRow, boolean startRowInclusive, Text endRow, boolean endRowInclusive);  Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow,
      boolean endRowInclusive);  Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive);  Range(Range range);  Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive,
      boolean infiniteStartKey, boolean infiniteStopKey); protected  Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop,
      boolean stopKeyInclusive, boolean infiniteStopKey);  Range(TRange trange); }
Range implements WritableComparable<Range> { public static List<Range> mergeOverlapping(Collection<Range> ranges) { if (ranges.isEmpty()) return Collections.emptyList(); if (ranges.size() == 1) return Collections.singletonList(ranges.iterator().next()); List<Range> ral = new ArrayList<>(ranges); Collections.sort(ral); ArrayList<Range> ret = new ArrayList<>(ranges.size()); Range currentRange = ral.get(0); boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive; for (int i = 1; i < ral.size(); i++) { if (currentRange.infiniteStopKey) { break; } Range range = ral.get(i); boolean startKeysEqual; if (range.infiniteStartKey) { assert currentRange.infiniteStartKey; startKeysEqual = true; } else if (currentRange.infiniteStartKey) { startKeysEqual = false; } else { startKeysEqual = currentRange.start.equals(range.start); } if (startKeysEqual || currentRange.contains(range.start) || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) { int cmp; if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) { currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive); } } else { ret.add(currentRange); currentRange = range; currentStartKeyInclusive = range.startKeyInclusive; } } ret.add(currentRange); return ret; } Range();  Range(Key startKey, Key endKey);  Range(CharSequence row);  Range(Text row);  Range(Text startRow, Text endRow);  Range(CharSequence startRow, CharSequence endRow);  Range(Text startRow, boolean startRowInclusive, Text endRow, boolean endRowInclusive);  Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow,
      boolean endRowInclusive);  Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive);  Range(Range range);  Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive,
      boolean infiniteStartKey, boolean infiniteStopKey); protected  Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop,
      boolean stopKeyInclusive, boolean infiniteStopKey);  Range(TRange trange); Key getStartKey(); boolean beforeStartKey(Key key); Key getEndKey(); boolean afterEndKey(Key key); @Override int hashCode(); @Override boolean equals(Object o); boolean equals(Range otherRange); @Override int compareTo(Range o); boolean contains(Key key); static List<Range> mergeOverlapping(Collection<Range> ranges); Range clip(Range range); Range clip(Range range, boolean returnNullIfDisjoint); Range bound(Column min, Column max); @Override String toString(); @Override void readFields(DataInput in); @Override void write(DataOutput out); boolean isStartKeyInclusive(); boolean isEndKeyInclusive(); TRange toThrift(); boolean isInfiniteStartKey(); boolean isInfiniteStopKey(); static Range exact(Text row); static Range exact(Text row, Text cf); static Range exact(Text row, Text cf, Text cq); static Range exact(Text row, Text cf, Text cq, Text cv); static Range exact(Text row, Text cf, Text cq, Text cv, long ts); static Text followingPrefix(Text prefix); static Range prefix(Text rowPrefix); static Range prefix(Text row, Text cfPrefix); static Range prefix(Text row, Text cf, Text cqPrefix); static Range prefix(Text row, Text cf, Text cq, Text cvPrefix); static Range exact(CharSequence row); static Range exact(CharSequence row, CharSequence cf); static Range exact(CharSequence row, CharSequence cf, CharSequence cq); static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv); static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv,
      long ts); static Range prefix(CharSequence rowPrefix); static Range prefix(CharSequence row, CharSequence cfPrefix); static Range prefix(CharSequence row, CharSequence cf, CharSequence cqPrefix); static Range prefix(CharSequence row, CharSequence cf, CharSequence cq,
      CharSequence cvPrefix); }
Range implements WritableComparable<Range> { public static List<Range> mergeOverlapping(Collection<Range> ranges) { if (ranges.isEmpty()) return Collections.emptyList(); if (ranges.size() == 1) return Collections.singletonList(ranges.iterator().next()); List<Range> ral = new ArrayList<>(ranges); Collections.sort(ral); ArrayList<Range> ret = new ArrayList<>(ranges.size()); Range currentRange = ral.get(0); boolean currentStartKeyInclusive = ral.get(0).startKeyInclusive; for (int i = 1; i < ral.size(); i++) { if (currentRange.infiniteStopKey) { break; } Range range = ral.get(i); boolean startKeysEqual; if (range.infiniteStartKey) { assert currentRange.infiniteStartKey; startKeysEqual = true; } else if (currentRange.infiniteStartKey) { startKeysEqual = false; } else { startKeysEqual = currentRange.start.equals(range.start); } if (startKeysEqual || currentRange.contains(range.start) || (!currentRange.stopKeyInclusive && range.startKeyInclusive && range.start.equals(currentRange.stop))) { int cmp; if (range.infiniteStopKey || (cmp = range.stop.compareTo(currentRange.stop)) > 0 || (cmp == 0 && range.stopKeyInclusive)) { currentRange = new Range(currentRange.getStartKey(), currentStartKeyInclusive, range.getEndKey(), range.stopKeyInclusive); } } else { ret.add(currentRange); currentRange = range; currentStartKeyInclusive = range.startKeyInclusive; } } ret.add(currentRange); return ret; } Range();  Range(Key startKey, Key endKey);  Range(CharSequence row);  Range(Text row);  Range(Text startRow, Text endRow);  Range(CharSequence startRow, CharSequence endRow);  Range(Text startRow, boolean startRowInclusive, Text endRow, boolean endRowInclusive);  Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow,
      boolean endRowInclusive);  Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive);  Range(Range range);  Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive,
      boolean infiniteStartKey, boolean infiniteStopKey); protected  Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop,
      boolean stopKeyInclusive, boolean infiniteStopKey);  Range(TRange trange); Key getStartKey(); boolean beforeStartKey(Key key); Key getEndKey(); boolean afterEndKey(Key key); @Override int hashCode(); @Override boolean equals(Object o); boolean equals(Range otherRange); @Override int compareTo(Range o); boolean contains(Key key); static List<Range> mergeOverlapping(Collection<Range> ranges); Range clip(Range range); Range clip(Range range, boolean returnNullIfDisjoint); Range bound(Column min, Column max); @Override String toString(); @Override void readFields(DataInput in); @Override void write(DataOutput out); boolean isStartKeyInclusive(); boolean isEndKeyInclusive(); TRange toThrift(); boolean isInfiniteStartKey(); boolean isInfiniteStopKey(); static Range exact(Text row); static Range exact(Text row, Text cf); static Range exact(Text row, Text cf, Text cq); static Range exact(Text row, Text cf, Text cq, Text cv); static Range exact(Text row, Text cf, Text cq, Text cv, long ts); static Text followingPrefix(Text prefix); static Range prefix(Text rowPrefix); static Range prefix(Text row, Text cfPrefix); static Range prefix(Text row, Text cf, Text cqPrefix); static Range prefix(Text row, Text cf, Text cq, Text cvPrefix); static Range exact(CharSequence row); static Range exact(CharSequence row, CharSequence cf); static Range exact(CharSequence row, CharSequence cf, CharSequence cq); static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv); static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv,
      long ts); static Range prefix(CharSequence rowPrefix); static Range prefix(CharSequence row, CharSequence cfPrefix); static Range prefix(CharSequence row, CharSequence cf, CharSequence cqPrefix); static Range prefix(CharSequence row, CharSequence cf, CharSequence cq,
      CharSequence cvPrefix);  }