Class GrowingCircularBuffer<T>

  • Type Parameters:
    T - buffer element type.

    public final class GrowingCircularBuffer<T>
    extends Object
    Implementaton of circular FIFO unbouded buffer. Instance is not a bit synchronized.
    Author:
    Matej Sekoranja
    • Constructor Detail

      • GrowingCircularBuffer

        public GrowingCircularBuffer​(int capacity)
                              throws IllegalArgumentException
        Create a BoundedBuffer with the given capacity.
        Parameters:
        capacity - buffer capacity.
        Throws:
        IllegalArgumentException - if capacity less or equal to zero
    • Method Detail

      • size

        public int size()
        Get number of elements in the buffer.
        Returns:
        number of elements in the buffer.
      • capacity

        public int capacity()
        Get current buffer capacity.
        Returns:
        buffer current capacity.
      • insert

        public final boolean insert​(T x)
        Insert a new element in to the buffer. If buffer full, oldest element will be overriden.
        Parameters:
        x - element to insert.
        Returns:
        true if first element.
      • extract

        public final T extract()
        Extract the oldest element from the buffer.
        Returns:
        the oldest element from the buffer.