code: public synchronized int setNextBit(boolean value) {
          increaseLength();
          index = (index + 1) % size;
  
          int previous = bitSet.set(index, value);
          int current = value ? 1 : 0;
          cardinality = cardinality - previous + current;
          return cardinality;
      }
docs: Sets the bit at the next index to the specified value.
  
  @param value a boolean value to set
  @return the number of bits set to {@code true}