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