public abstract class AbstractDataBufferWindow<B extends DataBuffer<?>> extends Object implements DataBufferWindow<B>
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractDataBufferWindow(B windowBuffer,
long bufferLimit) |
| Modifier and Type | Method and Description |
|---|---|
B |
buffer()
Returns the buffer backing this window.
|
long |
offset()
Returns the current offset of this window in the original buffer.
|
protected abstract void |
offset(long offset) |
long |
size()
Returns the size of this buffer window.
|
DataBufferWindow<B> |
slide(long step)
Moves the window of
step elements in the original buffer. |
DataBufferWindow<B> |
slideTo(long index)
Moves the window at the given position in the original buffer.
|
protected AbstractDataBufferWindow(B windowBuffer, long bufferLimit)
public final long offset()
DataBufferWindowoffset in interface DataBufferWindow<B extends DataBuffer<?>>public final long size()
DataBufferWindowsize in interface DataBufferWindow<B extends DataBuffer<?>>public final DataBufferWindow<B> slideTo(long index)
DataBufferWindowThe size of the window remains the same and its offset is set to index, so that
accessing the value of DataBufferWindow.buffer() at index x will return the value at
index + x in the original buffer.
slideTo in interface DataBufferWindow<B extends DataBuffer<?>>index - new offset for this windowpublic final DataBufferWindow<B> slide(long step)
DataBufferWindowstep elements in the original buffer.
The size of the window remains the same and its offset is set to offset() + step.
If step is positive, then the window will slide forward. If it is negative, it will
slide backward.
slide in interface DataBufferWindow<B extends DataBuffer<?>>step - value to add to the current offset of this windowpublic final B buffer()
DataBufferWindowEach window instance has it's own buffer providing a view onto the original
DataBuffer. The buffers are mutated when the window slides to different offsets.
For example:
IntDataBuffer buffer = DataBuffers.of(0, 1, 2, 3);
DataBufferWindow<IntDataBuffer> window = buffer.window(0, 2);
IntDataBuffer windowBuffer = window.buffer();
assertEquals(0, windowBuffer.getInt(0));
assertEquals(1, windowBuffer.getInt(1));
window.slideTo(2);
assertEquals(2, windowBuffer.getInt(0));
assertEquals(3, windowBuffer.getInt(1));
assertSame(windowBuffer, window.buffer());
buffer in interface DataBufferWindow<B extends DataBuffer<?>>protected abstract void offset(long offset)
Copyright © 2015–2020. All rights reserved.