Module com.github.akurilov.commons
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 booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> elements)intcapacity()intend()Eget(int i)java.util.Iterator<E>iterator()java.util.ListIterator<E>listIterator()Not supportedjava.util.ListIterator<E>listIterator(int i)Not supportedintoffset()Eremove(int i)Remove the element.CircularBuffer<E>removeFirst(int n)Remove the elements from the beginning.CircularBuffer<E>removeLast(int n)Remove the last elementsEset(int i, E e)Replace the element valuejava.util.List<E>subList(int fromIndex, int toIndex)Not supported
-
-
-
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)
-
addAll
boolean addAll(java.util.Collection<? extends E> elements)
-
get
E get(int i) throws java.lang.IndexOutOfBoundsException
- Specified by:
getin interfacejava.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:
setin interfacejava.util.List<E>- Parameters:
i- element indexe- 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:
removein interfacejava.util.List<E>- Parameters:
i- element index- Returns:
- previous element value
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of boundsjava.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:
subListin interfacejava.util.List<E>- Throws:
java.lang.UnsupportedOperationException- always
-
iterator
java.util.Iterator<E> iterator()
-
listIterator
java.util.ListIterator<E> listIterator() throws java.lang.UnsupportedOperationException
Not supported- Specified by:
listIteratorin interfacejava.util.List<E>- Throws:
java.lang.UnsupportedOperationException- always
-
-