Class CircularFifoQueue

  • All Implemented Interfaces:
    java.io.Serializable , java.util.Queue , kotlin.collections.Collection , kotlin.collections.Iterable , kotlin.collections.MutableCollection , kotlin.collections.MutableIterable

    
    public final class CircularFifoQueue<E extends Object>
    extends AbstractMutableCollection<E> implements Queue<E>, Serializable
                        

    CircularFifoQueue is a first-in first-out queue with a fixed size that replaces its oldest element if full.

    The removal order of a CircularFifoQueue is based on the insertion order; elements are removed in the same order in which they were added. The iteration order is the same as the removal order.

    The add, remove, peek, poll, offer operations all perform in constant time. All other operations perform in linear time or worse.

    This queue prevents null objects from being added.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Integer size
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      Integer getSize() Returns the number of elements stored in the queue.
      Boolean isEmpty() Returns true if this queue is empty; false otherwise.
      final Boolean isFull() A CircularFifoQueue can never be full, thus this returns always false.
      final Boolean isAtFullCapacity() Returns true if the capacity limit of this queue has been reached, i.e.
      final Integer maxSize() Gets the maximum size of the collection (the bound).
      Unit clear() Clears this queue.
      Boolean add(E element) Adds the given element to this queue.
      final E get(Integer index) Returns the element at the specified position in this queue.
      Boolean offer(E e) Adds the given element to this queue.
      E poll()
      E element()
      E peek()
      E remove()
      Iterator<E> iterator() Returns an iterator over this queue's elements.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CircularFifoQueue

        CircularFifoQueue(Collection<E> coll)
      • CircularFifoQueue

        CircularFifoQueue(Integer size)
      • CircularFifoQueue

        CircularFifoQueue()
    • Method Detail

      • getSize

         Integer getSize()

        Returns the number of elements stored in the queue.

      • isEmpty

         Boolean isEmpty()

        Returns true if this queue is empty; false otherwise.

        Returns:

        true if this queue is empty

      • isAtFullCapacity

         final Boolean isAtFullCapacity()

        Returns true if the capacity limit of this queue has been reached, i.e. the number of elements stored in the queue equals its maximum size.

        Returns:

        true if the capacity limit has been reached, false otherwise

      • maxSize

         final Integer maxSize()

        Gets the maximum size of the collection (the bound).

        Returns:

        the maximum number of elements the collection can hold

      • add

         Boolean add(E element)

        Adds the given element to this queue. If the queue is full, the least recently added element is discarded so that a new element can be inserted.

        Parameters:
        element - the element to add
        Returns:

        true, always

      • get

         final E get(Integer index)

        Returns the element at the specified position in this queue.

        Parameters:
        index - the position of the element in the queue
        Returns:

        the element at position index

      • offer

         Boolean offer(E e)

        Adds the given element to this queue. If the queue is full, the least recently added element is discarded so that a new element can be inserted.

        Parameters:
        e - the element to add
        Returns:

        true, always

      • iterator

         Iterator<E> iterator()

        Returns an iterator over this queue's elements.

        Returns:

        an iterator over this queue's elements