BitSet { public long cardinality() { long sum = 0L; for (long i = 0; i < numWords; i++) { sum += java.lang.Long.bitCount(words.get(i)); } return sum; } BitSet(MemoryBlock memory); MemoryBlock memoryBlock(); long capacity(); void set(long index); void unset(long index); boolean isSet(long index); long cardinality(); long nextSetBit(long fromIndex);  }
@Test public void cardinality() { BitSet bs = createBitSet(64); Assert.assertEquals(0, bs.cardinality()); for (int i = 0; i < bs.capacity(); i++) { bs.set(i); Assert.assertEquals(i + 1, bs.cardinality()); } }