CircularArray
public
final
class
CircularArray
extends Object
java.lang.Object | |
↳ | android.support.v4.util.CircularArray<E> |
CircularArray is a generic circular array data structure that provides O(1) random read, O(1) prepend and O(1) append. The CircularArray automatically grows its capacity when number of added items is over its capacity.
Summary
Public constructors | |
---|---|
CircularArray()
Creates a circular array with default capacity. |
|
CircularArray(int minCapacity)
Creates a circular array with capacity for at least |
Public methods | |
---|---|
void
|
addFirst(E e)
Add an element in front of the CircularArray. |
void
|
addLast(E e)
Add an element at end of the CircularArray. |
void
|
clear()
Remove all elements from the CircularArray. |
E
|
get(int n)
Get nth (0 <= n <= size()-1) element of the CircularArray. |
E
|
getFirst()
Get first element of the CircularArray. |
E
|
getLast()
Get last element of the CircularArray. |
boolean
|
isEmpty()
Return true if size() is 0. |
E
|
popFirst()
Remove first element from front of the CircularArray and return it. |
E
|
popLast()
Remove last element from end of the CircularArray and return it. |
void
|
removeFromEnd(int numOfElements)
Remove multiple elements from end of the CircularArray, ignore when numOfElements is less than or equals to 0. |
void
|
removeFromStart(int numOfElements)
Remove multiple elements from front of the CircularArray, ignore when numOfElements is less than or equals to 0. |
int
|
size()
Get number of elements in the CircularArray. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
Public constructors
CircularArray
CircularArray ()
Creates a circular array with default capacity.
CircularArray
CircularArray (int minCapacity)
Creates a circular array with capacity for at least minCapacity
elements.
Parameters | |
---|---|
minCapacity |
int : the minimum capacity, between 1 and 2^30 inclusive
|
Public methods
addFirst
void addFirst (E e)
Add an element in front of the CircularArray.
Parameters | |
---|---|
e |
E : Element to add.
|
addLast
void addLast (E e)
Add an element at end of the CircularArray.
Parameters | |
---|---|
e |
E : Element to add.
|
get
E get (int n)
Get nth (0 <= n <= size()-1) element of the CircularArray.
Parameters | |
---|---|
n |
int : The zero based element index in the CircularArray. |
Returns | |
---|---|
E |
The nth element. |
Throws | |
---|---|
|
ArrayIndexOutOfBoundsException} if n < 0 or n >= size(). |
getFirst
E getFirst ()
Get first element of the CircularArray.
Returns | |
---|---|
E |
The first element. |
Throws | |
---|---|
|
ArrayIndexOutOfBoundsException} if CircularArray is empty. |
getLast
E getLast ()
Get last element of the CircularArray.
Returns | |
---|---|
E |
The last element. |
Throws | |
---|---|
|
ArrayIndexOutOfBoundsException} if CircularArray is empty. |
isEmpty
boolean isEmpty ()
Return true if size() is 0.
Returns | |
---|---|
boolean |
true if size() is 0. |
popFirst
E popFirst ()
Remove first element from front of the CircularArray and return it.
Returns | |
---|---|
E |
The element removed. |
Throws | |
---|---|
ArrayIndexOutOfBoundsException |
if CircularArray is empty. |
popLast
E popLast ()
Remove last element from end of the CircularArray and return it.
Returns | |
---|---|
E |
The element removed. |
Throws | |
---|---|
ArrayIndexOutOfBoundsException |
if CircularArray is empty. |
removeFromEnd
void removeFromEnd (int numOfElements)
Remove multiple elements from end of the CircularArray, ignore when numOfElements is less than or equals to 0.
Parameters | |
---|---|
numOfElements |
int : Number of elements to remove. |
Throws | |
---|---|
ArrayIndexOutOfBoundsException |
if numOfElements is larger than
size()
|
removeFromStart
void removeFromStart (int numOfElements)
Remove multiple elements from front of the CircularArray, ignore when numOfElements is less than or equals to 0.
Parameters | |
---|---|
numOfElements |
int : Number of elements to remove. |
Throws | |
---|---|
ArrayIndexOutOfBoundsException |
if numOfElements is larger than
size()
|
size
int size ()
Get number of elements in the CircularArray.
Returns | |
---|---|
int |
Number of elements in the CircularArray. |