public final class BitIterable
extends java.lang.Object
implements java.lang.Iterable<java.lang.Boolean>
Iterable
that iterates through an array of byte
s and their respective bits.
It returns a Boolean
for each and every bit, which tells us whether it is set or not.
Constructor and Description |
---|
BitIterable(byte[] bytes)
Constructs a new
BitIterable given an array of byte s. |
Modifier and Type | Method and Description |
---|---|
byte |
getByte(int index)
Returns the
byte at the index :th position. |
byte[] |
getBytes()
Returns a new copy of the
byte array contained within this BitIterable . |
boolean |
isSet(int byteIndex,
int bitIndex)
Returns
true if, and only if, the bit on the byteIndex :th byte position and the bitIndex :th bit position is set, false otherwise. |
java.util.Iterator<java.lang.Boolean> |
iterator()
Returns a new
Iterator . |
public BitIterable(byte[] bytes)
BitIterable
given an array of byte
s.
If bytes
is null
, a NullPointerException
will be thrown.
bytes
- the array of byte
s to iteratejava.lang.NullPointerException
- thrown if, and only if, bytes
is null
public byte getByte(int index)
byte
at the index
:th position.
If index
is less than 0
or greater than or equal to getBytes().length
, an IllegalArgumentException
will be thrown.
index
- the index of the byte
to getbyte
at the index
:th positionjava.lang.IllegalArgumentException
- thrown if, and only if, index
is less than 0
or greater than or equal to getBytes().length
public byte[] getBytes()
byte
array contained within this BitIterable
.byte
array contained within this BitIterable
public boolean isSet(int byteIndex, int bitIndex)
true
if, and only if, the bit on the byteIndex
:th byte
position and the bitIndex
:th bit position is set, false
otherwise.
If, and only if, byteIndex
is less than 0
or greater than or equal to getBytes().length
or bitIndex
is less than 0
or greater than 7
, an
IllegalArgumentException
will be thrown.
byteIndex
- the byte
index to be usedbitIndex
- the bit index to be usedtrue
if, and only if, the bit on the byteIndex
:th byte
position and the bitIndex
:th bit position is set, false
otherwisejava.lang.IllegalArgumentException
- thrown if, and only if, byteIndex
is less than 0
or greater than or equal to getBytes().length
or bitIndex
is less than 0
or greater than
7
public java.util.Iterator<java.lang.Boolean> iterator()
Iterator
.iterator
in interface java.lang.Iterable<java.lang.Boolean>
Iterator