Package org.klomp.snark
Class BitField
- java.lang.Object
- 
- org.klomp.snark.BitField
 
- 
 public class BitField extends Object Container of a byte array representing set and unset bits.
- 
- 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(int bit)Sets the given bit to false.booleancomplete()Return true if all bits are set.intcount()Return the number of set bits.booleanequals(Object o)booleanget(int bit)Return true if the bit is set or false if it is not.byte[]getFieldBytes()This returns the actual byte array used.inthashCode()voidset(int bit)Sets the given bit to true.voidsetAll()Sets all bits to true.intsize()Return the size of the BitField.StringtoString()
 
- 
- 
- 
Constructor Detail- 
BitFieldpublic BitField(int size) Creates a new BitField that representssizeunset bits.
 - 
BitFieldpublic BitField(byte[] bitfield, int size)Creates a new BitField that representssizebits as set by the given byte array. This will make a copy of the array. Extra bytes will be ignored.- Throws:
- IndexOutOfBoundsException- if give byte array is not large enough.
 
 
- 
 - 
Method Detail- 
getFieldBytespublic byte[] getFieldBytes() This returns the actual byte array used. Changes to this array affect this BitField. Note that some bits at the end of the byte array are supposed to be always unset if they represent bits bigger then the size of the bitfield. Caller should synch on this and copy!
 - 
sizepublic int size() Return the size of the BitField. The returned value is one bigger then the last valid bit number (since bit numbers are counted from zero).
 - 
setpublic void set(int bit) Sets the given bit to true.- Throws:
- IndexOutOfBoundsException- if bit is smaller then zero bigger then size (inclusive).
 
 - 
clearpublic void clear(int bit) Sets the given bit to false.- Throws:
- IndexOutOfBoundsException- if bit is smaller then zero bigger then size (inclusive).
- Since:
- 0.9.22
 
 - 
setAllpublic void setAll() Sets all bits to true.- Since:
- 0.9.21
 
 - 
getpublic boolean get(int bit) Return true if the bit is set or false if it is not.- Throws:
- IndexOutOfBoundsException- if bit is smaller then zero bigger then size (inclusive).
 
 - 
countpublic int count() Return the number of set bits.
 - 
completepublic boolean complete() Return true if all bits are set.
 
- 
 
-