BitVectorImpl implements BitVector, Iterable<Boolean> { @Override public void setBit(long position, boolean bit) { ensureSize(position); this.validHashCode = false; int arrayPos = (int) (position >> LG_WORD_SIZE); byte wordPos = (byte) (position & WORD_MASK); this.arrayOfBits[arrayPos] = setBitInWord(wordPos, bit, this.arrayOfBits[arrayPos]); } BitVectorImpl();  BitVectorImpl(BitVector bitVector);  BitVectorImpl(long initialSize); @Override boolean addBit(boolean bit); @Override boolean equals(Object obj); @Override boolean getBit(long position); @Override int hashCode(); @Override Iterator<Boolean> iterator(); @Override void setBit(long position, boolean bit); @Override long size(); @Override String toString();  }
@Test public void testSetBit() { long word = 0; for (byte i = 0; i < 0x40; i++) { word = BitVectorImpl.setBitInWord(i, true, word); } for (byte i = 0; i < 0x40; i++) { Assert.assertTrue(BitVectorImpl.getBitInWord(i, word)); } for (byte i = 0; i < 0x40; i++) { word = BitVectorImpl.setBitInWord(i, false, word); } for (byte i = 0; i < 0x40; i++) { Assert.assertFalse(BitVectorImpl.getBitInWord(i, word)); } word = 0x0362; for (byte i = 0; i < 0x40; i++) { boolean value = BitVectorImpl.getBitInWord(i, word); word = BitVectorImpl.setBitInWord(i, value, word); Assert.assertEquals(value, BitVectorImpl.getBitInWord(i, word)); value = !value; word = BitVectorImpl.setBitInWord(i, value, word); Assert.assertEquals(value, BitVectorImpl.getBitInWord(i, word)); value = !value; word = BitVectorImpl.setBitInWord(i, value, word); Assert.assertEquals(value, BitVectorImpl.getBitInWord(i, word)); } Assert.assertEquals(0x0362, word); }