public final class ObjectBuffer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
_freeBuffer
Reusable Object array, stored here after buffer has been released having
been used previously.
|
private LinkedNode<java.lang.Object[]> |
_head |
private int |
_size
Number of total buffered entries in this buffer, counting all instances
within linked list formed by following
_head . |
private LinkedNode<java.lang.Object[]> |
_tail |
private static int |
MAX_CHUNK
Let's limit maximum size of chunks we use; helps avoid excessive allocation
overhead for huge data sets.
|
private static int |
SMALL_CHUNK
Also: let's expand by doubling up until 64k chunks (which is 16k entries for
32-bit machines)
|
Constructor and Description |
---|
ObjectBuffer() |
Modifier and Type | Method and Description |
---|---|
protected void |
_copyTo(java.lang.Object resultArray,
int totalSize,
java.lang.Object[] lastChunk,
int lastChunkEntries) |
protected void |
_reset() |
java.lang.Object[] |
appendCompletedChunk(java.lang.Object[] fullChunk)
Method called to add a full Object array as a chunk buffered within
this buffer, and to obtain a new array to fill.
|
int |
bufferedSize()
Method that can be used to check how many Objects have been buffered
within this buffer.
|
java.lang.Object[] |
completeAndClearBuffer(java.lang.Object[] lastChunk,
int lastChunkEntries)
Method called to indicate that the buffering process is now
complete; and to construct a combined exactly-sized result
array.
|
<T> T[] |
completeAndClearBuffer(java.lang.Object[] lastChunk,
int lastChunkEntries,
java.lang.Class<T> componentType)
Type-safe alternative to
completeAndClearBuffer(Object[], int) , to allow
for constructing explicitly typed result array. |
void |
completeAndClearBuffer(java.lang.Object[] lastChunk,
int lastChunkEntries,
java.util.List<java.lang.Object> resultList) |
int |
initialCapacity()
Helper method that can be used to check how much free capacity
will this instance start with.
|
java.lang.Object[] |
resetAndStart()
Method called to start buffering process.
|
private static final int SMALL_CHUNK
private static final int MAX_CHUNK
private LinkedNode<java.lang.Object[]> _head
private LinkedNode<java.lang.Object[]> _tail
private int _size
_head
.private java.lang.Object[] _freeBuffer
public java.lang.Object[] resetAndStart()
public java.lang.Object[] appendCompletedChunk(java.lang.Object[] fullChunk)
fullChunk
- Completed chunk that the caller is requesting
to append to this buffer. It is generally chunk that was
returned by an earlier call to resetAndStart()
or
appendCompletedChunk(java.lang.Object[])
(although this is not required or
enforced)public java.lang.Object[] completeAndClearBuffer(java.lang.Object[] lastChunk, int lastChunkEntries)
Resulting array will be of generic Object[]
type:
if a typed array is needed, use the method with additional
type argument.
public <T> T[] completeAndClearBuffer(java.lang.Object[] lastChunk, int lastChunkEntries, java.lang.Class<T> componentType)
completeAndClearBuffer(Object[], int)
, to allow
for constructing explicitly typed result array.componentType
- Type of elements included in the buffer. Will be
used for constructing the result array.public void completeAndClearBuffer(java.lang.Object[] lastChunk, int lastChunkEntries, java.util.List<java.lang.Object> resultList)
public int initialCapacity()
public int bufferedSize()
protected void _reset()
protected final void _copyTo(java.lang.Object resultArray, int totalSize, java.lang.Object[] lastChunk, int lastChunkEntries)