BitField implements Comparable<BitField> { public int deser(DataInput in) throws IOException { int idx = 0; byte current; do { current = in.readByte(); ensureSpace(idx + 1); bits[idx] = (byte) (current & ~1); idx++; } while ((current & 1) != 0); for (int i = idx; i < bits.length; i++) { bits[i] = 0; } return idx; } BitField(); void set(int bit, boolean value); void set(int bit); void unset(int bit); boolean isSet(int bit); void ser(DataOutput out); int deser(DataInput in); int deser(byte[] bytes, int start); @Override int compareTo(BitField o); void clear(); String toString();  }
@Test public void testDeSer() throws Exception { BitField b1 = new BitField(); serDeCheck(b1); b1.set(0); serDeCheck(b1); b1.unset(0); serDeCheck(b1); b1.set(0); b1.set(1); serDeCheck(b1); b1.set(7); serDeCheck(b1); b1.set(13); serDeCheck(b1); b1.set(14); serDeCheck(b1); Random r = new Random(0); int MAX_BIT = 100; int ITERATIONS = 40; for (int i=0; i<ITERATIONS; i++) { b1.set(r.nextInt(MAX_BIT)); serDeCheck(b1); } }