Class CyclicBufferList

  • All Implemented Interfaces:
    Iterable, Collection, List

    public class CyclicBufferList
    extends AbstractList
    implements List
    CyclicBuffer implementation that is Object generic, and implements the List interface.

    Original CyclicBuffer @author Ceki Gülcü

    This implementation (although there's very little change) @author Paul Smith <psmith@apache.org>

    • Constructor Detail

      • CyclicBufferList

        public CyclicBufferList​(int maxSize)
        Instantiate a new CyclicBuffer of at most maxSize events.

        The maxSize argument must a positive integer.

        Parameters:
        maxSize - The maximum number of elements in the buffer.
      • CyclicBufferList

        public CyclicBufferList()
    • Method Detail

      • remove

        public Object remove​(int index)
        Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
        Specified by:
        remove in interface List
        Overrides:
        remove in class AbstractList
        Parameters:
        index - the index of the element to removed.
        Returns:
        the element that was removed from the list.
        Throws:
        IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).
      • add

        public boolean add​(Object event)
        Add an event as the last event in the buffer.
        Specified by:
        add in interface Collection
        Specified by:
        add in interface List
        Overrides:
        add in class AbstractList
      • get

        public Object get​(int i)
        Get the ith oldest event currently in the buffer. If i is outside the range 0 to the number of elements currently in the buffer, then null is returned.
        Specified by:
        get in interface List
        Specified by:
        get in class AbstractList
      • getMaxSize

        public int getMaxSize()
      • getLast

        public int getLast()
      • get

        public Object get()
        Get the oldest (first) element in the buffer. The oldest element is removed from the buffer.
      • size

        public int size()
        Get the number of elements in the buffer. This number is guaranteed to be in the range 0 to maxSize (inclusive).
        Specified by:
        size in interface Collection
        Specified by:
        size in interface List
        Specified by:
        size in class AbstractCollection
      • resize

        public void resize​(int newSize)
        Resize the cyclic buffer to newSize.
        Throws:
        IllegalArgumentException - if newSize is negative.