Android APIs
public final class

CircularIntArray

extends Object
java.lang.Object
   ↳ android.support.v4.util.CircularIntArray

Class Overview

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()
Create a CircularIntArray with default capacity.
CircularIntArray(int minCapacity)
Create a CircularIntArray 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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public CircularIntArray ()

Create a CircularIntArray with default capacity.

public CircularIntArray (int minCapacity)

Create a CircularIntArray with capacity for at least minCapacity elements.

Parameters
minCapacity The minimum capacity required for the CircularIntArray.

Public Methods

public void addFirst (int e)

Add an integer in front of the CircularIntArray.

Parameters
e Integer to add.

public void addLast (int e)

Add an integer at end of the CircularIntArray.

Parameters
e Integer to add.

public void clear ()

Remove all integers from the CircularIntArray.

public int get (int n)

Get nth (0 <= n <= size()-1) integer of the CircularIntArray.

Parameters
n The zero based element index in the CircularIntArray.
Returns
  • The nth integer.
Throws
ArrayIndexOutOfBoundsException} if n < 0 or n >= size().

public int getFirst ()

Get first integer of the CircularIntArray.

Returns
  • The first integer.
Throws
ArrayIndexOutOfBoundsException} if CircularIntArray is empty.

public int getLast ()

Get last integer of the CircularIntArray.

Returns
  • The last integer.
Throws
ArrayIndexOutOfBoundsException} if CircularIntArray is empty.

public boolean isEmpty ()

Return true if size() is 0.

Returns
  • true if size() is 0.

public int popFirst ()

Remove first integer from front of the CircularIntArray and return it.

Returns
  • The integer removed.
Throws
ArrayIndexOutOfBoundsException if CircularIntArray is empty.

public int popLast ()

Remove last integer from end of the CircularIntArray and return it.

Returns
  • The integer removed.
Throws
ArrayIndexOutOfBoundsException if CircularIntArray is empty.

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 Number of integers to remove.
Throws
ArrayIndexOutOfBoundsException if numOfElements is larger than size()

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 Number of integers to remove.
Throws
ArrayIndexOutOfBoundsException if numOfElements is larger than size()

public int size ()

Get number of integers in the CircularIntArray.

Returns
  • Number of integers in the CircularIntArray.