public final class CircularArray<E> extends Object
| Constructor and Description |
|---|
CircularArray()
Create a CircularArray with default capacity.
|
CircularArray(int minCapacity)
Create a CircularArray with capacity for at least minCapacity elements.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public CircularArray()
public CircularArray(int minCapacity)
minCapacity - The minimum capacity required for the CircularArray.public void addFirst(E e)
e - Element to add.public void addLast(E e)
e - Element to add.public E popFirst()
ArrayIndexOutOfBoundsException - if CircularArray is empty.public E popLast()
ArrayIndexOutOfBoundsException - if CircularArray is empty.public void clear()
public void removeFromStart(int numOfElements)
numOfElements - Number of elements to remove.ArrayIndexOutOfBoundsException - if numOfElements is larger than
size()public void removeFromEnd(int numOfElements)
numOfElements - Number of elements to remove.ArrayIndexOutOfBoundsException - if numOfElements is larger than
size()public E getFirst()
{@link - ArrayIndexOutOfBoundsException} if CircularArray is empty.public E getLast()
{@link - ArrayIndexOutOfBoundsException} if CircularArray is empty.public E get(int n)
n - The zero based element index in the CircularArray.{@link - ArrayIndexOutOfBoundsException} if n < 0 or n >= size().public int size()
public boolean isEmpty()
Copyright © 2015. All rights reserved.