Class FixedSizeQueue<T>

  • Type Parameters:
    T - Type of objects stored in this queue

    public class FixedSizeQueue<T>
    extends java.lang.Object
    Instance of this class are queues that have a fixed size.
    When the queue is full, the elements are shifted and the first element is lost.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private T[] buffer  
      private int index  
    • Constructor Summary

      Constructors 
      Constructor Description
      FixedSizeQueue​(int capacity)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getSize()  
      java.util.List<T> getValues()  
      void put​(T element)
      Store an element in the buffer
      void resizeTo​(int newSize)  
      • Methods inherited from class java.lang.Object

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

      • buffer

        private T[] buffer
      • index

        private int index
    • Constructor Detail

      • FixedSizeQueue

        public FixedSizeQueue​(int capacity)
        Constructor
        Parameters:
        capacity - initial capacity
    • Method Detail

      • put

        public void put​(T element)
        Store an element in the buffer
        Parameters:
        element - element to store
      • getValues

        public java.util.List<T> getValues()
        Returns:
        all values stored in this queue
      • getSize

        public int getSize()
        Returns:
        size of the buffer
      • resizeTo

        public void resizeTo​(int newSize)
        Parameters:
        newSize - new size of the buffer. If newSize is lower than the actual size, the buffer will contain the last elements that have been stored