private static void throwExceptionForInvalidRanges(List<RowRange> invalidRanges,
    boolean details) {
    StringBuilder sb = new StringBuilder();
    sb.append(invalidRanges.size()).append(" invaild ranges.\n");
    if (details) {
      for (RowRange range : invalidRanges) {
        sb.append("Invalid range: start row => " + Bytes.toString(range.startRow) + ", stop row => "
          + Bytes.toString(range.stopRow)).append('\n');
      }
    }
    throw new IllegalArgumentException(sb.toString());
  }
sort the ranges and if the ranges with overlap, then merge them.
@param ranges the list of ranges to sort and merge.
@return the ranges after sort and merge.
hbase-client/src/main/java/org/apache/hadoop/hbase/filter/MultiRowRangeFilter.java