public static RowRanges create(long rowCount, PrimitiveIterator.OfInt pageIndexes, OffsetIndex offsetIndex) {
    RowRanges ranges = new RowRanges();
    while (pageIndexes.hasNext()) {
      int pageIndex = pageIndexes.nextInt();
      ranges.add(new Range(
          offsetIndex.getFirstRowIndex(pageIndex), offsetIndex.getLastRowIndex(pageIndex, rowCount)));
    }
    return ranges;
  }
@Test
  public void testCreate() {
    RowRanges ranges = buildRanges(
        1, 2,
        3, 4,
        6, 7,
        7, 10,
        15, 17);
    assertAllRowsEqual(ranges.iterator(), 1, 2, 3, 4, 6, 7, 8, 9, 10, 15, 16, 17);
    assertEquals(12, ranges.rowCount());
    assertTrue(ranges.isOverlapping(4, 5));
    assertFalse(ranges.isOverlapping(5, 5));
    assertTrue(ranges.isOverlapping(10, 14));
    assertFalse(ranges.isOverlapping(11, 14));
    assertFalse(ranges.isOverlapping(18, Long.MAX_VALUE));

    ranges = RowRanges.createSingle(5);
    assertAllRowsEqual(ranges.iterator(), 0, 1, 2, 3, 4);
    assertEquals(5, ranges.rowCount());
    assertTrue(ranges.isOverlapping(0, 100));
    assertFalse(ranges.isOverlapping(5, Long.MAX_VALUE));

    ranges = RowRanges.EMPTY;
    assertAllRowsEqual(ranges.iterator());
    assertEquals(0, ranges.rowCount());
    assertFalse(ranges.isOverlapping(0, Long.MAX_VALUE));
  }