Class BoundedFIFOQueue<T>

  • Type Parameters:
    T - The type of elements collected.
    All Implemented Interfaces:
    Serializable, Iterable<T>

    public class BoundedFIFOQueue<T>
    extends Object
    implements Iterable<T>, Serializable
    BoundedFIFOQueue collects elements up to given amount. Reaching this limit will result in removing the oldest element from this queue (First-In/First-Out; FIFO).
    See Also:
    Serialized Form
    • Constructor Detail

      • BoundedFIFOQueue

        public BoundedFIFOQueue​(int maxSize)
        Creates a BoundedFIFOQueue with the given maximum size.
        Parameters:
        maxSize - The maximum size of this queue. Exceeding this limit would result in removing the oldest element (FIFO).
        Throws:
        IllegalArgumentException - If maxSize is less than 0.
    • Method Detail

      • add

        public void add​(T element)
        Adds an element to the end of the queue. An element will be removed from the head of the queue if the queue would exceed its maximum size by adding the new element.
        Parameters:
        element - The element that should be added to the end of the queue.
        Throws:
        NullPointerException - If null is passed as an element.
      • size

        public int size()
        Returns the number of currently stored elements.
        Returns:
        The number of currently stored elements.