Package smsqmulator
Class FifoQueue<T>
java.lang.Object
smsqmulator.FifoQueue<T>
- Type Parameters:
T
- the objects in the buffer.
A fixed size FIFO queue that does not allow null elements.
Null elements are never added to the buffer, but trying to do so will NOT generate any kind of error - they are just silently ignored.
The buffer is backed by an array of element T. A buffer must have at least a capacity of 1 element.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
FifoQueue
public FifoQueue()Creates the queue with a capacity of 10 elements. -
FifoQueue
Creates the buffer with a capacity of n elements.- Parameters:
n
- the number of elements the buffer is to contain.- Throws:
IllegalArgumentException
- if the the number of elements the buffer is to have is smaller than 1.
-
-
Method Details
-
add
Tries to add an element to the end of the queue.- Parameters:
newElement
- the element to add.NULL
elements are NOT added to the buffer, they are silently discarded (no error, no exception).- Returns:
- true if element was added to the buffer, false if it wasn't, which indicates either that the queue is full, or that the element to be inserted was null.
-
remove
Gets the head element of this buffer. This may be null if and only if the queue is empty.- Returns:
- the last element of this buffer. This will be null if and only if the queue is empty.
-
toString
Shows some info about the queue.
-