public class CircularBuffer<T>
extends java.lang.Object
| Constructor and Description |
|---|
CircularBuffer()
Creates a resizable
CircularBuffer. |
CircularBuffer(int initialCapacity)
Creates a resizable
CircularBuffer with the given initial capacity. |
CircularBuffer(int initialCapacity,
boolean resizable)
Creates a
CircularBuffer with the given initial capacity. |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all items from this circular buffer.
|
void |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array (if necessary) to accommodate the specified number of additional items.
|
boolean |
isEmpty()
Returns
true if this circular buffer is empty; false otherwise. |
boolean |
isFull()
Returns
true if this circular buffer contains as many items as its capacity; false otherwise. |
boolean |
isResizable()
Returns
true if this circular buffer can be resized; false otherwise. |
T |
read()
Removes and returns the item at the head of this circular buffer (if any).
|
protected void |
resize(int newCapacity)
Creates a new backing array with the specified capacity containing the current items.
|
void |
setResizable(boolean resizable)
Sets the flag specifying whether this circular buffer can be resized or not.
|
int |
size()
Returns the number of elements in this circular buffer.
|
boolean |
store(T item)
Adds the given item to the tail of this circular buffer.
|
public CircularBuffer()
CircularBuffer.public CircularBuffer(int initialCapacity)
CircularBuffer with the given initial capacity.initialCapacity - the initial capacity of this circular bufferpublic CircularBuffer(int initialCapacity,
boolean resizable)
CircularBuffer with the given initial capacity.initialCapacity - the initial capacity of this circular bufferresizable - whether this buffer is resizable or has fixed capacitypublic boolean store(T item)
item - the item to addtrue if the item has been successfully added to this circular buffer; false otherwise.public T read()
null if this circular buffer is empty.public void clear()
public boolean isEmpty()
true if this circular buffer is empty; false otherwise.public boolean isFull()
true if this circular buffer contains as many items as its capacity; false otherwise.public int size()
public boolean isResizable()
true if this circular buffer can be resized; false otherwise.public void setResizable(boolean resizable)
resizable - the flagpublic void ensureCapacity(int additionalCapacity)
additionalCapacity - the number of additional itemsprotected void resize(int newCapacity)
newCapacity - the new capacity