Interface CircularBuffer<E>

  • All Superinterfaces:
    java.util.Collection<E>, java.lang.Iterable<E>, java.util.List<E>
    All Known Implementing Classes:
    CircularArrayBuffer

    public interface CircularBuffer<E>
    extends java.util.List<E>
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean add​(E e)  
      boolean addAll​(java.util.Collection<? extends E> elements)  
      int capacity()  
      int end()  
      E get​(int i)  
      java.util.Iterator<E> iterator()  
      java.util.ListIterator<E> listIterator()
      Not supported
      java.util.ListIterator<E> listIterator​(int i)
      Not supported
      int offset()  
      E remove​(int i)
      Remove the element.
      CircularBuffer<E> removeFirst​(int n)
      Remove the elements from the beginning.
      CircularBuffer<E> removeLast​(int n)
      Remove the last elements
      E set​(int i, E e)
      Replace the element value
      java.util.List<E> subList​(int fromIndex, int toIndex)
      Not supported
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        add, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, lastIndexOf, remove, removeAll, replaceAll, retainAll, size, sort, spliterator, toArray, toArray
    • Method Detail

      • capacity

        int capacity()
        Returns:
        the buffer capacity
      • offset

        int offset()
        Returns:
        the index of the 1st element
      • end

        int end()
        Returns:
        the index which points to the next element after the last one (exclusive), -1 if the buffer is empty
      • add

        boolean add​(E e)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.List<E>
        Parameters:
        e - element to add to the end of the buffer
        Returns:
        false if the buffer is full
      • addAll

        boolean addAll​(java.util.Collection<? extends E> elements)
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.List<E>
        Parameters:
        elements -
        Returns:
        true if all elements have been added, false if not enough capacity
      • get

        E get​(int i)
        throws java.lang.IndexOutOfBoundsException
        Specified by:
        get in interface java.util.List<E>
        Parameters:
        i - element index
        Returns:
        element
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of bounds
      • set

        E set​(int i,
              E e)
        throws java.lang.IndexOutOfBoundsException
        Replace the element value
        Specified by:
        set in interface java.util.List<E>
        Parameters:
        i - element index
        e - new element value
        Returns:
        previous element value
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of bounds
      • remove

        E remove​(int i)
          throws java.lang.IndexOutOfBoundsException,
                 java.lang.UnsupportedOperationException
        Remove the element. The implementation is able to remove only 1st either last element.
        Specified by:
        remove in interface java.util.List<E>
        Parameters:
        i - element index
        Returns:
        previous element value
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is out of bounds
        java.lang.UnsupportedOperationException - if the index points to not 1st neither last element
      • removeFirst

        CircularBuffer<E> removeFirst​(int n)
                               throws java.lang.IndexOutOfBoundsException
        Remove the elements from the beginning.
        Parameters:
        n - the count of elements to remove
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if the count of elements to remove is more than the current size
      • removeLast

        CircularBuffer<E> removeLast​(int n)
                              throws java.lang.IndexOutOfBoundsException
        Remove the last elements
        Parameters:
        n - the count of elements to remove
        Returns:
        this
        Throws:
        java.lang.IndexOutOfBoundsException - if the count of elements to remove is more than the current size
      • subList

        java.util.List<E> subList​(int fromIndex,
                                  int toIndex)
                           throws java.lang.UnsupportedOperationException
        Not supported
        Specified by:
        subList in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • iterator

        java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Returns:
        the iterator instance
      • listIterator

        java.util.ListIterator<E> listIterator()
                                        throws java.lang.UnsupportedOperationException
        Not supported
        Specified by:
        listIterator in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • listIterator

        java.util.ListIterator<E> listIterator​(int i)
                                        throws java.lang.UnsupportedOperationException
        Not supported
        Specified by:
        listIterator in interface java.util.List<E>
        Throws:
        java.lang.UnsupportedOperationException - always