Module com.github.akurilov.commons
Class CircularArrayBuffer<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- com.github.akurilov.commons.collection.CircularArrayBuffer<E>
-
- All Implemented Interfaces:
CircularBuffer<E>,java.io.Serializable,java.lang.Cloneable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess
public class CircularArrayBuffer<E> extends java.util.AbstractList<E> implements CircularBuffer<E>, java.lang.Cloneable, java.util.RandomAccess, java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classCircularArrayBuffer.ListIteratorImpl<E>
-
Constructor Summary
Constructors Constructor Description CircularArrayBuffer(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(java.util.Collection<? extends E> elements)intcapacity()voidclear()intend()Eget(int i)booleanisEmpty()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.CircularArrayBuffer<E>removeFirst(int n)Remove the elements from the beginning.CircularArrayBuffer<E>removeLast(int n)Remove the last elementsEset(int i, E e)Replace the element valueintsize()java.util.List<E>subList(int fromIndex, int toIndex)Not supported-
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, lastIndexOf, removeRange
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Field Detail
-
array
protected final E[] array
-
capacity
protected final int capacity
-
-
Method Detail
-
capacity
public final int capacity()
- Specified by:
capacityin interfaceCircularBuffer<E>- Returns:
- the buffer capacity
-
offset
public final int offset()
- Specified by:
offsetin interfaceCircularBuffer<E>- Returns:
- the index of the 1st element
-
end
public final int end()
- Specified by:
endin interfaceCircularBuffer<E>- Returns:
- the index which points to the next element after the last one (exclusive), -1 if the buffer is empty
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
clear
public final void clear()
-
add
public final boolean add(E e)
-
addAll
public final boolean addAll(java.util.Collection<? extends E> elements)
-
get
public E get(int i)
- Specified by:
getin interfaceCircularBuffer<E>- Specified by:
getin interfacejava.util.List<E>- Specified by:
getin classjava.util.AbstractList<E>- Parameters:
i- element index- Returns:
- element
-
set
public E set(int i, E e)
Description copied from interface:CircularBufferReplace the element value- Specified by:
setin interfaceCircularBuffer<E>- Specified by:
setin interfacejava.util.List<E>- Overrides:
setin classjava.util.AbstractList<E>- Parameters:
i- element indexe- new element value- Returns:
- previous element value
-
remove
public final E remove(int i)
Description copied from interface:CircularBufferRemove the element. The implementation is able to remove only 1st either last element.- Specified by:
removein interfaceCircularBuffer<E>- Specified by:
removein interfacejava.util.List<E>- Overrides:
removein classjava.util.AbstractList<E>- Parameters:
i- element index- Returns:
- previous element value
-
removeFirst
public final CircularArrayBuffer<E> removeFirst(int n)
Description copied from interface:CircularBufferRemove the elements from the beginning.- Specified by:
removeFirstin interfaceCircularBuffer<E>- Parameters:
n- the count of elements to remove- Returns:
- this
-
removeLast
public final CircularArrayBuffer<E> removeLast(int n)
Description copied from interface:CircularBufferRemove the last elements- Specified by:
removeLastin interfaceCircularBuffer<E>- Parameters:
n- the count of elements to remove- Returns:
- this
-
subList
public java.util.List<E> subList(int fromIndex, int toIndex)
Description copied from interface:CircularBufferNot supported- Specified by:
subListin interfaceCircularBuffer<E>- Specified by:
subListin interfacejava.util.List<E>- Overrides:
subListin classjava.util.AbstractList<E>
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iteratorin interfaceCircularBuffer<E>- Specified by:
iteratorin interfacejava.util.Collection<E>- Specified by:
iteratorin interfacejava.lang.Iterable<E>- Specified by:
iteratorin interfacejava.util.List<E>- Overrides:
iteratorin classjava.util.AbstractList<E>- Returns:
- the iterator instance
-
listIterator
public java.util.ListIterator<E> listIterator()
Description copied from interface:CircularBufferNot supported- Specified by:
listIteratorin interfaceCircularBuffer<E>- Specified by:
listIteratorin interfacejava.util.List<E>- Overrides:
listIteratorin classjava.util.AbstractList<E>
-
listIterator
public java.util.ListIterator<E> listIterator(int i)
Description copied from interface:CircularBufferNot supported- Specified by:
listIteratorin interfaceCircularBuffer<E>- Specified by:
listIteratorin interfacejava.util.List<E>- Overrides:
listIteratorin classjava.util.AbstractList<E>
-
-