public int andCardinality(BitmapCollection bitmaps) {
    ImmutableRoaringBitmap left = reduceInternal();
    ImmutableRoaringBitmap right = bitmaps.reduceInternal();
    if (!_inverted) {
      if (!bitmaps._inverted) {
        return ImmutableRoaringBitmap.andCardinality(left, right);
      }
      return ImmutableRoaringBitmap.andNotCardinality(left, right);
    } else {
      if (!bitmaps._inverted) {
        return ImmutableRoaringBitmap.andNotCardinality(right, left);
      }
      return _numDocs - ImmutableRoaringBitmap.orCardinality(left, right);
    }
  }
@Test(dataProvider = "andCardinalityTestCases")
  public void testAndCardinality(int numDocs, ImmutableRoaringBitmap left, boolean leftInverted,
      ImmutableRoaringBitmap right, boolean rightInverted, int expected) {
    assertEquals(new BitmapCollection(numDocs, leftInverted, left).andCardinality(
        new BitmapCollection(numDocs, rightInverted, right)), expected);
    assertEquals(new BitmapCollection(numDocs, leftInverted, split(left)).andCardinality(
        new BitmapCollection(numDocs, rightInverted, right)), expected);
    assertEquals(new BitmapCollection(numDocs, leftInverted, left).andCardinality(
        new BitmapCollection(numDocs, rightInverted, split(right))), expected);
    assertEquals(new BitmapCollection(numDocs, leftInverted, split(left)).andCardinality(
        new BitmapCollection(numDocs, rightInverted, split(right))), expected);
  }