Package xal.tools.collections
Class LinearBuffer<T>
java.lang.Object
xal.tools.collections.LinearBuffer<T>
- All Implemented Interfaces:
Iterable<T>
,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.
- Since:
- Sep 2007
- Author:
- Christopher K. Allen
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLinearBuffer
(int szBuffLen) Create a new, emptyFixedSizeBuffer
instance with the specified length. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.get
(int index) Return the object at the specified position in this buffer.iterator()
Return an iterator object for this buffer which traverses the buffer objects in Last In First Out order.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.toString()
Print out the contents of the buffer as a string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEF_LEN_BUFFER
Deprecated.the default buffer length- See Also:
-
-
Constructor Details
-
LinearBuffer
public LinearBuffer(int szBuffLen) Create a new, emptyFixedSizeBuffer
instance with the specified length.- Parameters:
szBuffLen
- Length of the data buffer
-
-
Method Details
-
setBufferLength
public void setBufferLength(int szBuffer) (Re)set the size of the buffer length. If the new size of the buffer is less the previous size objects at the tail are lost.- Parameters:
szBuffer
- new length of the data buffer
-
size
public int size()Returns the maximum number of objects that this collection can hold.- Specified by:
size
in interfaceIBoundedList<T>
- Returns:
- capacity of the buffer
- Since:
- Apr 11, 2013
-
add
Adds an object to the buffer, pushing off an old object if the buffer is full.- Specified by:
add
in interfaceIBoundedList<T>
- Parameters:
objNew
- object to be inserted at buffer head
-
get
Return the object at the specified position in this buffer. The buffer uses a last in first out (LIFO) policy.- Specified by:
get
in interfaceIBoundedList<T>
- Parameters:
index
- index position from head- Returns:
- object at position index
- Throws:
IndexOutOfBoundsException
- index value exceeds buffer size
-
clear
public void clear()Clear out the contents of the data buffer.- Specified by:
clear
in interfaceIBoundedList<T>
-
iterator
Return an iterator object for this buffer which traverses the buffer objects in Last In First Out order. -
iterator
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.- Returns:
- offset iterator for the buffer
-
toString
Print out the contents of the buffer as a string.
-