T - type of elements in the arraypublic class SimpleArray<T>
extends java.lang.Object
implements java.lang.Iterable<T>
This class is useful in a few cases:
| Constructor and Description |
|---|
SimpleArray(T[] initial)
Create an instance backed by an array.
|
SimpleArray(T[] initial,
int size)
Create an instance backed by an array with a specified number of preallocated elements.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T element)
Add an element to the end of the list.
|
void |
addAll(T[] src)
Add all elements from an array.
|
private void |
addAll(T[] src,
int offset,
int len)
Add a portion of elements from an array.
|
protected int |
calculateNewCapacity(int currentCapacity) |
void |
clear()
Clear all elements.
|
void |
copyTo(T[] dst,
int offset)
Copy all elements from the backing array to another array.
|
T[] |
elements()
Get an array with all elements.
|
T |
get(int index)
Get the element at the specified index.
|
java.util.Iterator<T> |
iterator() |
int |
size()
Get the number of stored elements.
|
private T[] elements
private int size
public SimpleArray(T[] initial)
initial - array to use for storagepublic SimpleArray(T[] initial, int size)
initial - array to use for storagesize - number of preallocated elementspublic T get(int index)
index - element indexpublic void add(T element)
element - element to addpublic void addAll(T[] src)
src - array containing elements to addprivate void addAll(T[] src, int offset, int len)
src - array containing elements to addoffset - offset in array to start adding elements fromlen - number of elements from the array to addpublic void copyTo(T[] dst, int offset)
dst - array to copy elements tooffset - starting position in the destination arrayprotected int calculateNewCapacity(int currentCapacity)
public int size()
public void clear()
public T[] elements()