public NotDocIdIterator(BlockDocIdIterator childDocIdIterator, int numDocs) {
    _childDocIdIterator = childDocIdIterator;
    _nextDocId = 0;

    int currentDocIdFromChildIterator = childDocIdIterator.next();
    _nextNonMatchingDocId = currentDocIdFromChildIterator == Constants.EOF ? numDocs : currentDocIdFromChildIterator;
    _numDocs = numDocs;
  }
@Test
  public void testNotDocIdIterator() {
    // OR result: [0, 1, 2, 4, 5, 6, 8, 10, 13, 15, 16, 17, 18, 19, 20]
    int[] docIds1 = new int[]{1, 4, 6, 10, 15, 17, 18, 20};
    int[] docIds2 = new int[]{0, 1, 5, 8, 15, 18};
    int[] docIds3 = new int[]{1, 2, 6, 13, 16, 19};
    int[] docIds4 = new int[]{0, 1, 2, 3, 4, 5};

    MutableRoaringBitmap bitmap1 = new MutableRoaringBitmap();
    bitmap1.add(docIds1);
    MutableRoaringBitmap bitmap2 = new MutableRoaringBitmap();
    bitmap2.add(docIds2);
    MutableRoaringBitmap bitmap3 = new MutableRoaringBitmap();
    bitmap3.add(docIds3);
    MutableRoaringBitmap bitmap4 = new MutableRoaringBitmap();
    bitmap4.add(docIds4);
    OrDocIdIterator orDocIdIterator = new OrDocIdIterator(new BlockDocIdIterator[]{
        new RangelessBitmapDocIdIterator(bitmap1), new RangelessBitmapDocIdIterator(
        bitmap2), new RangelessBitmapDocIdIterator(bitmap3)
    });
    NotDocIdIterator notDocIdIterator = new NotDocIdIterator(new RangelessBitmapDocIdIterator(bitmap1), 25);

    assertEquals(notDocIdIterator.advance(1), 2);
    assertEquals(notDocIdIterator.next(), 3);
    assertEquals(notDocIdIterator.next(), 5);
    assertEquals(notDocIdIterator.advance(7), 7);
    assertEquals(notDocIdIterator.advance(13), 13);
    assertEquals(notDocIdIterator.next(), 14);
    assertEquals(notDocIdIterator.advance(18), 19);
    assertEquals(notDocIdIterator.advance(21), 21);
    assertEquals(notDocIdIterator.advance(26), Constants.EOF);

    notDocIdIterator = new NotDocIdIterator(new RangelessBitmapDocIdIterator(bitmap1), 25);
    assertEquals(notDocIdIterator.next(), 0);
    assertEquals(notDocIdIterator.next(), 2);
    assertEquals(notDocIdIterator.next(), 3);
    assertEquals(notDocIdIterator.next(), 5);
    assertEquals(notDocIdIterator.next(), 7);
    assertEquals(notDocIdIterator.next(), 8);
    assertEquals(notDocIdIterator.next(), 9);
    assertEquals(notDocIdIterator.next(), 11);
    assertEquals(notDocIdIterator.next(), 12);
    assertEquals(notDocIdIterator.next(), 13);
    assertEquals(notDocIdIterator.next(), 14);
    assertEquals(notDocIdIterator.next(), 16);
    assertEquals(notDocIdIterator.next(), 19);
    assertEquals(notDocIdIterator.next(), 21);
    assertEquals(notDocIdIterator.next(), 22);
    assertEquals(notDocIdIterator.next(), 23);
    assertEquals(notDocIdIterator.next(), 24);
    assertEquals(notDocIdIterator.next(), Constants.EOF);

    notDocIdIterator = new NotDocIdIterator(orDocIdIterator, 25);
    assertEquals(notDocIdIterator.next(), 3);
    assertEquals(notDocIdIterator.next(), 7);
    assertEquals(notDocIdIterator.next(), 9);
    assertEquals(notDocIdIterator.next(), 11);
    assertEquals(notDocIdIterator.next(), 12);
    assertEquals(notDocIdIterator.next(), 14);
    assertEquals(notDocIdIterator.next(), 21);
    assertEquals(notDocIdIterator.next(), 22);
    assertEquals(notDocIdIterator.next(), 23);
    assertEquals(notDocIdIterator.next(), 24);
    assertEquals(notDocIdIterator.next(), Constants.EOF);

    notDocIdIterator = new NotDocIdIterator(new RangelessBitmapDocIdIterator(bitmap4), 6);
    assertEquals(notDocIdIterator.next(), Constants.EOF);

    notDocIdIterator = new NotDocIdIterator(new RangelessBitmapDocIdIterator(bitmap4), 9);
    assertEquals(notDocIdIterator.next(), 6);
    assertEquals(notDocIdIterator.next(), 7);
    assertEquals(notDocIdIterator.next(), 8);
  }