Am I missing something painfully obvious? Or does just nobody in the world actually use java.util.BitSet?
The following test fails:
@Test
public voi
This puzzled me too, not sure of the rationale behind BitSet's current rather unexpected functionality. However since it's not final, we can use some embrace and extend tactics and do the following to get a fixed BitSet with length semantics as expected:
import java.util.BitSet;
/**
* Variation of BitSet which does NOT interpret the highest bit synonymous with
* its length.
*
* @author casper.bang@gmail.com
*/
public class FixedBitSet extends BitSet{
int fixedLength;
public FixedBitSet(int fixedLength){
super(fixedLength);
this.fixedLength = fixedLength;
}
@Override
public int length() {
return fixedLength;
}
}