Package org.opendaylight.protocol.util
Class BitArray
java.lang.Object
org.opendaylight.protocol.util.BitArray
This class was created to minimize usage of Java BitSet class, as this one
is hard to use within specifics of network protocols. Uses network byte
order.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns the backing byte array of this bitset.boolean
get
(int index) Returns boolean value for a bit on specific position.void
If the value given is TRUE, sets bit on given position.byte
toByte()
If possible, returns one byte as backing array.void
toByteBuf
(io.netty.buffer.ByteBuf buffer) Writes backing array to given ByteBuf, even if the backing array is empty, to preserve the number of allocated bits.toString()
static BitArray
valueOf
(byte info) Returns new BitArray with given byte as backing.static BitArray
valueOf
(byte[] bytes) Returns a new BitArray with given byte array as backing.static BitArray
valueOf
(io.netty.buffer.ByteBuf buffer, int size) Returns a new BitArray created from bytes from given ByteBuf.
-
Constructor Details
-
BitArray
public BitArray(int size) Creates a BitArray with fixed size of bits. For sizes smaller than 8 the whole byte is allocated.- Parameters:
size
- Number of bits relevant for this BitArray. Needs to be greater than 0.
-
-
Method Details
-
valueOf
Returns a new BitArray created from bytes from given ByteBuf.- Parameters:
buffer
- ByteBuf, whose readerIndex will be moved by minimum number of bytes required for the bit size.size
- Number of bits to be allocated in BitArray- Returns:
- new BitArray
-
valueOf
Returns a new BitArray with given byte array as backing. array.- Parameters:
bytes
- byte array- Returns:
- new BitArray
-
valueOf
Returns new BitArray with given byte as backing. array.- Parameters:
info
- unsigned byte- Returns:
- new BitArray
-
set
If the value given is TRUE, sets bit on given position. Checks for null value. Index is counted from the rightmost bit as 0 to size -1 being the leftmost bit.- Parameters:
index
- position of bit that will be setvalue
- Boolean
-
get
public boolean get(int index) Returns boolean value for a bit on specific position. Index is counted from the rightmost bit as 0 to size -1 being the leftmost bit.- Parameters:
index
- position of bit- Returns:
- boolean value
-
array
public byte[] array()Returns the backing byte array of this bitset.- Returns:
- byte[]
-
toByte
public byte toByte()If possible, returns one byte as backing array.- Returns:
- byte
-
toByteBuf
public void toByteBuf(io.netty.buffer.ByteBuf buffer) Writes backing array to given ByteBuf, even if the backing array is empty, to preserve the number of allocated bits.- Parameters:
buffer
- ByteBuf
-
toString
-