public final class NibbleArray extends Object
The even indices are stored in the least significant nibble and the odd indices in the most significant bits. For example, [1 5 8 15] is stored as [0x51 0xf8].
Constructor and Description |
---|
NibbleArray(byte... rawData)
Construct a new NibbleArray using the given underlying bytes.
|
NibbleArray(int size)
Construct a new NibbleArray with the given size in nibbles.
|
NibbleArray(int size,
byte value)
Construct a new NibbleArray with the given size in nibble, filled with the specified nibble
value.
|
Modifier and Type | Method and Description |
---|---|
int |
byteSize()
Get the size in bytes, one-half the size in nibbles.
|
void |
fill(byte value)
Fill the nibble array with the specified value.
|
byte |
get(int index)
Get the nibble at the given index.
|
byte[] |
getRawData()
Get the raw bytes of this nibble array.
|
void |
set(int index,
byte value)
Set the nibble at the given index to the given value.
|
void |
setRawData(byte... source)
Copies into the raw bytes of this nibble array from the given source.
|
int |
size()
Get the size in nibbles.
|
NibbleArray |
snapshot()
Take a snapshot of this NibbleArray which will not reflect changes.
|
public NibbleArray(int size)
size
- The number of nibbles in the array.IllegalArgumentException
- If size is not positive and even.public NibbleArray(int size, byte value)
size
- The number of nibbles in the array.value
- The value to fill the array with.IllegalArgumentException
- If size is not positive and even.public NibbleArray(byte... rawData)
rawData
- The raw data to use.public int size()
public int byteSize()
public byte get(int index)
index
- The nibble index.public void set(int index, byte value)
index
- The nibble index.value
- The new value to store.public void fill(byte value)
value
- The value nibble to fill with.public void setRawData(byte... source)
source
- The array to copy from.IllegalArgumentException
- If source is not the correct length.public NibbleArray snapshot()
public byte[] getRawData()
Copyright © 2021. All rights reserved.