Package smsqmulator

Class FifoQueue<T>

java.lang.Object
smsqmulator.FifoQueue<T>
Type Parameters:
T - the objects in the buffer.

public class FifoQueue<T> extends Object
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
    Constructor
    Description
    Creates the queue with a capacity of 10 elements.
    FifoQueue(int n)
    Creates the buffer with a capacity of n elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(T newElement)
    Tries to add an element to the end of the queue.
    Gets the head element of this buffer.
    Shows some info about the queue.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • FifoQueue

      public FifoQueue()
      Creates the queue with a capacity of 10 elements.
    • FifoQueue

      public FifoQueue(int n) throws IllegalArgumentException
      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

      public boolean add(T newElement)
      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

      public T 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

      public String toString()
      Shows some info about the queue.
      Overrides:
      toString in class Object
      Returns:
      string with info (queue size).