- java.lang.Object
-
- com.tigerbeetle.Batch
-
- com.tigerbeetle.IdBatch
-
-
Constructor Summary
Constructors Constructor Description IdBatch(int capacity)
Constructs an empty batch of ids with the desired maximum capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(byte[] id)
Adds a new id at the end of this batch.void
add(long leastSignificant)
Adds a new id at the end of this batch.void
add(long leastSignificant, long mostSignificant)
Adds a new id at the end of this batch.byte[]
getId()
Gets the id.long
getId(UInt128 part)
Gets the id.void
setId(byte[] id)
Sets the id.void
setId(long leastSignificant, long mostSignificant)
Sets the id.-
Methods inherited from class com.tigerbeetle.Batch
add, at, beforeFirst, getArray, getCapacity, getLength, getPosition, getUInt128, getUInt128, getUInt16, getUInt32, getUInt64, isReadOnly, isValidPosition, next, putArray, putUInt128, putUInt128, putUInt16, putUInt32, putUInt64, setPosition
-
-
-
-
Constructor Detail
-
IdBatch
public IdBatch(int capacity)
Constructs an empty batch of ids with the desired maximum capacity.Once created, an instance cannot be resized, however it may contain any number of ids between zero and its
capacity
.- Parameters:
capacity
- the maximum capacity.- Throws:
IllegalArgumentException
- if capacity is negative.
-
-
Method Detail
-
add
public void add(byte[] id)
Adds a new id at the end of this batch.If successful, moves the current
position
to the newly created id.- Parameters:
id
- an array of 16 bytes representing the 128-bit value.- Throws:
IllegalStateException
- if this batch is read-only.IndexOutOfBoundsException
- if exceeds the batch's capacity.
-
add
public void add(long leastSignificant, long mostSignificant)
Adds a new id at the end of this batch.If successful, moves the current
position
to the newly created id.- Parameters:
leastSignificant
- along
representing the the first 8 bytes of the 128-bit value.mostSignificant
- along
representing the the last 8 bytes of the 128-bit value.- Throws:
IllegalStateException
- if this batch is read-only.IndexOutOfBoundsException
- if exceeds the batch's capacity.
-
add
public void add(long leastSignificant)
Adds a new id at the end of this batch.If successful, moves the current
position
to the newly created id.- Parameters:
leastSignificant
- along
representing the the first 8 bytes of the 128-bit value.- Throws:
IllegalStateException
- if this batch is read-only.IndexOutOfBoundsException
- if exceeds the batch's capacity.
-
getId
public byte[] getId()
Gets the id.- Returns:
- an array of 16 bytes representing the 128-bit value.
- Throws:
IllegalStateException
- if not at avalid position
.
-
getId
public long getId(UInt128 part)
Gets the id.- Parameters:
part
- aUInt128
enum indicating which part of the 128-bit value is to be retrieved.- Returns:
- a
long
representing the the first 8 bytes of the 128-bit value ifUInt128.LeastSignificant
is informed, or the last 8 bytes ifUInt128.MostSignificant
. - Throws:
IllegalStateException
- if not at avalid position
.
-
setId
public void setId(byte[] id)
Sets the id.- Parameters:
id
- an array of 16 bytes representing the 128-bit value.- Throws:
NullPointerException
- ifid
is null.IllegalArgumentException
- ifid
is not 16 bytes long.IllegalStateException
- if not at avalid position
.IllegalStateException
- if aread-only
batch.
-
setId
public void setId(long leastSignificant, long mostSignificant)
Sets the id.- Parameters:
leastSignificant
- along
representing the the first 8 bytes of the 128-bit value.mostSignificant
- along
representing the the last 8 bytes of the 128-bit value.- Throws:
IllegalStateException
- if not at avalid position
.IllegalStateException
- if aread-only
batch.
-
-