- java.lang.Object
-
- com.tigerbeetle.Batch
-
- Direct Known Subclasses:
AccountBatch
,CreateAccountResultBatch
,CreateTransferResultBatch
,IdBatch
,TransferBatch
public abstract class Batch extends Object
A Batch is contiguous memory block representing a collection of elements of the same type with a cursor pointing to its current position.Initially the cursor is positioned before the first element and must be positioned by calling
next()
,add()
, orsetPosition(int)
prior to reading or writing an element.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add()
Adds a new element at the end of this batch.protected int
at(int fieldOffSet)
void
beforeFirst()
Moves the cursor to the front of this Batch, before the first element.protected byte[]
getArray(int index, int len)
int
getCapacity()
Gets the maximum number of elements this batch can contain.int
getLength()
Gets the number of elements in this batchint
getPosition()
Returns the current element's position.protected byte[]
getUInt128(int index)
protected long
getUInt128(int index, UInt128 part)
protected int
getUInt16(int index)
protected int
getUInt32(int index)
protected long
getUInt64(int index)
boolean
isReadOnly()
Tells whether or not this batch is read-only.boolean
isValidPosition()
Tells if the current position points to an valid element.boolean
next()
Tries to move the currentposition
to the next element in this batch.protected void
putArray(int index, byte[] value)
protected void
putUInt128(int index, byte[] value)
protected void
putUInt128(int index, long leastSignificant, long mostSignificant)
protected void
putUInt16(int index, int value)
protected void
putUInt32(int index, int value)
protected void
putUInt64(int index, long value)
void
setPosition(int newPosition)
Moves to the element int the specified position.
-
-
-
Method Detail
-
isReadOnly
public final boolean isReadOnly()
Tells whether or not this batch is read-only.- Returns:
- true if this batch is read-only
-
add
public final void add()
Adds a new element at the end of this batch.If successful, moves the current
position
to the newly created element.- Throws:
IllegalStateException
- if this batch is read-only.IndexOutOfBoundsException
- if exceeds the batch's capacity.
-
next
public final boolean next()
Tries to move the currentposition
to the next element in this batch.- Returns:
- true if moved or false if the end of the batch was reached.
- Throws:
IndexOutOfBoundsException
- if the batch is already at the end.
-
isValidPosition
public final boolean isValidPosition()
Tells if the current position points to an valid element.- Returns:
- false if the cursor is positioned before the first element or at the end.
-
beforeFirst
public final void beforeFirst()
Moves the cursor to the front of this Batch, before the first element.This causes the batch to be iterable again by calling
next()
.
-
getPosition
public final int getPosition()
Returns the current element's position.- Returns:
- a zero-based index or
-1
if at the end of the batch.
-
setPosition
public final void setPosition(int newPosition)
Moves to the element int the specified position.- Parameters:
newPosition
- a zero-based index.- Throws:
IndexOutOfBoundsException
- ifnewPosition
is negative or greater than the batch'slength
.
-
getLength
public final int getLength()
Gets the number of elements in this batch
-
getCapacity
public final int getCapacity()
Gets the maximum number of elements this batch can contain.
-
at
protected final int at(int fieldOffSet)
-
getUInt128
protected final byte[] getUInt128(int index)
-
getUInt128
protected final long getUInt128(int index, UInt128 part)
-
putUInt128
protected final void putUInt128(int index, byte[] value)
-
putUInt128
protected final void putUInt128(int index, long leastSignificant, long mostSignificant)
-
getUInt64
protected final long getUInt64(int index)
-
putUInt64
protected final void putUInt64(int index, long value)
-
getUInt32
protected final int getUInt32(int index)
-
putUInt32
protected final void putUInt32(int index, int value)
-
getUInt16
protected final int getUInt16(int index)
-
putUInt16
protected final void putUInt16(int index, int value)
-
getArray
protected final byte[] getArray(int index, int len)
-
putArray
protected final void putArray(int index, byte[] value)
-
-