public class LinearBuffer<T> extends java.lang.Object implements IBoundedList<T>
Implementation of a linear, fixed-length data buffer. The current version follows a list implementation and, thus, the collection is naturally ordered according to their relative point of insertion.
Objects are added to the head of the buffer. Once the buffer becomes "full", that is, the number of objects contained within equals the buffer size, any additional additions will cause objects to fall off the tail of the buffer.
The primary difference between this class and the class
are the iterators provided. The CircularBuffer
CircularBuffer
class uses a
Last In First Out (LIFO) iteration policy
while this class uses a First In First Out (FIFO) policy.
Modifier and Type | Field and Description |
---|---|
static int |
DEF_LEN_BUFFER
Deprecated.
|
Constructor and Description |
---|
LinearBuffer(int szBuffLen)
Create a new, empty
FixedSizeBuffer instance with the
specified length. |
Modifier and Type | Method and Description |
---|---|
void |
add(T objNew)
Adds an object to the buffer, pushing off an old object
if the buffer is full.
|
void |
clear()
Clear out the contents of the data buffer.
|
T |
get(int index)
Return the object at the specified position in this buffer.
|
java.util.Iterator<T> |
iterator()
Return an iterator object for this buffer which traverses the
buffer objects in Last In First Out order.
|
java.util.Iterator<T> |
iterator(int index)
Return an iterator object for this buffer which starts with the
object at the given index and ends with the last object in the
buffer.
|
void |
setBufferLength(int szBuffer)
(Re)set the size of the buffer length.
|
int |
size()
Returns the maximum number of objects that this collection can
hold.
|
java.lang.String |
toString()
Print out the contents of the buffer as a string.
|
@Deprecated public static final int DEF_LEN_BUFFER
public LinearBuffer(int szBuffLen)
FixedSizeBuffer
instance with the
specified length.szBuffLen
- Length of the data bufferpublic void setBufferLength(int szBuffer)
szBuffer
- new length of the data bufferpublic int size()
size
in interface IBoundedList<T>
public void add(T objNew)
add
in interface IBoundedList<T>
objNew
- object to be inserted at buffer headpublic T get(int index) throws java.lang.IndexOutOfBoundsException
get
in interface IBoundedList<T>
index
- index position from headjava.lang.IndexOutOfBoundsException
- index value exceeds buffer sizepublic void clear()
clear
in interface IBoundedList<T>
public java.util.Iterator<T> iterator()
iterator
in interface java.lang.Iterable<T>
public java.util.Iterator<T> iterator(int index)
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()