Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.
added in version 1.0.0
belongs to Maven artifact androidx.collection:collection:1.0.0-rc01

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 minCapacity elements.

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

added in version 1.0.0
public CircularIntArray ()

Creates a circular array with default capacity.

CircularIntArray

added in version 1.0.0
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

added in version 1.0.0
public void addFirst (int e)

Add an integer in front of the CircularIntArray.

Parameters
e int: Integer to add.

addLast

added in version 1.0.0
public void addLast (int e)

Add an integer at end of the CircularIntArray.

Parameters
e int: Integer to add.

clear

added in version 1.0.0
public void clear ()

Remove all integers from the CircularIntArray.

get

added in version 1.0.0
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

added in version 1.0.0
public int getFirst ()

Get first integer of the CircularIntArray.

Returns
int The first integer.

Throws
ArrayIndexOutOfBoundsException} if CircularIntArray is empty.

getLast

added in version 1.0.0
public int getLast ()

Get last integer of the CircularIntArray.

Returns
int The last integer.

Throws
ArrayIndexOutOfBoundsException} if CircularIntArray is empty.

isEmpty

added in version 1.0.0
public boolean isEmpty ()

Return true if size() is 0.

Returns
boolean true if size() is 0.

popFirst

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
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

added in version 1.0.0
public int size ()

Get number of integers in the CircularIntArray.

Returns
int Number of integers in the CircularIntArray.