Module MaterialFX

Class CircularQueue<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, Deque<E>, List<E>, Queue<E>

public class CircularQueue<E> extends LinkedList<E>
This is the implementation of a circular FIFO queue. When the maximum size is reached the oldest element is removed and replaced by the new one.
See Also:
  • Constructor Details

    • CircularQueue

      public CircularQueue(int size)
  • Method Details

    • setSize

      public void setSize(int size)
      Sets the maximum size of the queue and removes exceeding elements if the specified size is lesser than the number of elements.
      Parameters:
      size - The new desired size
      Throws:
      IllegalArgumentException - if the desired size is 0
    • add

      public boolean add(E e)
      Adds the specified element to the queue and if it is full removes the oldest element and then adds the new one.

      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface Deque<E>
      Specified by:
      add in interface List<E>
      Specified by:
      add in interface Queue<E>
      Overrides:
      add in class LinkedList<E>