|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.utils.Array<T>
public class Array<T>
A resizable, ordered or unordered array of objects. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
Nested Class Summary | |
---|---|
static class |
Array.ArrayIterable<T>
|
static class |
Array.ArrayIterator<T>
|
Field Summary | |
---|---|
T[] |
items
Provides direct access to the underlying array. |
boolean |
ordered
|
int |
size
|
Constructor Summary | |
---|---|
Array()
Creates an ordered array with a capacity of 16. |
|
Array(Array array)
Creates a new array containing the elements in the specified array. |
|
Array(boolean ordered,
int capacity)
|
|
Array(boolean ordered,
int capacity,
java.lang.Class<T> arrayType)
Creates a new array with items of the specified type. |
|
Array(boolean ordered,
T[] array)
Creates a new array containing the elements in the specified array. |
|
Array(java.lang.Class<T> arrayType)
Creates an ordered array with items of the specified type and a capacity of 16. |
|
Array(int capacity)
Creates an ordered array with the specified capacity. |
|
Array(T[] array)
Creates a new ordered array containing the elements in the specified array. |
Method Summary | ||
---|---|---|
void |
add(T value)
|
|
void |
addAll(Array array)
|
|
void |
addAll(Array array,
int offset,
int length)
|
|
void |
addAll(T[] array)
|
|
void |
addAll(T[] array,
int offset,
int length)
|
|
void |
clear()
|
|
boolean |
contains(T value,
boolean identity)
|
|
T[] |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to acommodate the specified number of additional items. |
|
boolean |
equals(java.lang.Object object)
|
|
T |
first()
Returns the first item. |
|
T |
get(int index)
|
|
int |
indexOf(T value,
boolean identity)
|
|
void |
insert(int index,
T value)
|
|
java.util.Iterator<T> |
iterator()
Returns an iterator for the items in the array. |
|
int |
lastIndexOf(T value,
boolean identity)
|
|
T |
peek()
Returns the last item. |
|
T |
pop()
Removes and returns the last item. |
|
T |
random()
Returns a random item from the array, or null if the array is empty. |
|
boolean |
removeAll(Array<T> array,
boolean identity)
Removes from this array all of elements contained in the specified array. |
|
T |
removeIndex(int index)
Removes and returns the item at the specified index. |
|
boolean |
removeValue(T value,
boolean identity)
|
|
protected T[] |
resize(int newSize)
Creates a new backing array with the specified size containing the current items. |
|
void |
reverse()
|
|
void |
set(int index,
T value)
|
|
void |
shrink()
Reduces the size of the backing array to the size of the actual items. |
|
void |
shuffle()
|
|
void |
sort()
Sorts this array. |
|
void |
sort(java.util.Comparator<T> comparator)
Sorts the array. |
|
void |
swap(int first,
int second)
|
|
T[] |
toArray()
|
|
|
toArray(java.lang.Class<V> type)
|
|
java.lang.String |
toString()
|
|
java.lang.String |
toString(java.lang.String separator)
|
|
void |
truncate(int newSize)
Reduces the size of the array to the specified size. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public T[] items
Array(boolean, int, Class)
constructor was used.
public int size
public boolean ordered
Constructor Detail |
---|
public Array()
public Array(int capacity)
public Array(boolean ordered, int capacity)
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a
memory copy.capacity
- Any elements added beyond this will cause the backing array to be grown.public Array(boolean ordered, int capacity, java.lang.Class<T> arrayType)
items
of the specified type.
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a
memory copy.capacity
- Any elements added beyond this will cause the backing array to be grown.public Array(java.lang.Class<T> arrayType)
items
of the specified type and a capacity of 16.
public Array(Array array)
public Array(T[] array)
public Array(boolean ordered, T[] array)
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a
memory copy.Method Detail |
---|
public void add(T value)
public void addAll(Array array)
public void addAll(Array array, int offset, int length)
public void addAll(T[] array)
public void addAll(T[] array, int offset, int length)
public T get(int index)
public void set(int index, T value)
public void insert(int index, T value)
public void swap(int first, int second)
public boolean contains(T value, boolean identity)
identity
- If true, == comparison will be used. If false, .equals() comaparison will be used.public int indexOf(T value, boolean identity)
public int lastIndexOf(T value, boolean identity)
public boolean removeValue(T value, boolean identity)
public T removeIndex(int index)
public boolean removeAll(Array<T> array, boolean identity)
identity
- True to use ==, false to use .equals().
public T pop()
public T peek()
public T first()
public void clear()
public void shrink()
public T[] ensureCapacity(int additionalCapacity)
items
protected T[] resize(int newSize)
public void sort()
Comparable
. This method is not thread safe (uses
Sort.instance()
).
public void sort(java.util.Comparator<T> comparator)
Sort.instance()
).
public void reverse()
public void shuffle()
public java.util.Iterator<T> iterator()
Array.ArrayIterator
constructor for nested or multithreaded iteration.
iterator
in interface java.lang.Iterable<T>
public void truncate(int newSize)
public T random()
public T[] toArray()
public <V> V[] toArray(java.lang.Class<V> type)
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String separator)
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |