public class Array<T>
extends java.lang.Object
implements java.lang.Iterable<T>
限定符和类型 | 类和说明 |
---|---|
static class |
Array.ArrayIterable<T> |
static class |
Array.ArrayIterator<T> |
限定符和类型 | 字段和说明 |
---|---|
T[] |
items
Provides direct access to the underlying array.
|
boolean |
ordered |
int |
size |
构造器和说明 |
---|
Array()
Creates an ordered array with a capacity of 16.
|
Array(Array<? extends T> 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 arrayType)
Creates a new array with
items of the specified type. |
Array(boolean ordered,
T[] array,
int start,
int count)
Creates a new array containing the elements in the specified array.
|
Array(java.lang.Class 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.
|
限定符和类型 | 方法和说明 |
---|---|
void |
add(T value) |
void |
addAll(Array<? extends T> array) |
void |
addAll(Array<? extends T> array,
int start,
int count) |
void |
addAll(T... array) |
void |
addAll(T[] array,
int start,
int count) |
void |
clear() |
boolean |
contains(T value,
boolean identity)
Returns if this array contains value.
|
T[] |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items.
|
boolean |
equals(java.lang.Object object) |
T |
first()
Returns the first item.
|
T |
get(int index) |
int |
hashCode() |
int |
indexOf(T value,
boolean identity)
Returns the index of first occurrence of value in the array, or -1 if no such value exists.
|
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)
Returns an index of last occurrence of value in array or -1 if no such value exists.
|
static <T> Array<T> |
of(boolean ordered,
int capacity,
java.lang.Class<T> arrayType) |
static <T> Array<T> |
of(java.lang.Class<T> arrayType) |
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<? extends 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.
|
void |
removeRange(int start,
int end)
Removes the items between the specified indices, inclusive.
|
boolean |
removeValue(T value,
boolean identity)
Removes the first instance of the specified value in the array.
|
protected T[] |
resize(int newSize)
Creates a new backing array with the specified size containing the current items.
|
void |
reverse() |
java.lang.Iterable<T> |
select(Predicate<T> predicate)
Returns an iterable for the selected items in the array.
|
T |
selectRanked(java.util.Comparator<T> comparator,
int kthLowest)
Selects the nth-lowest element from the Array according to Comparator ranking.
|
int |
selectRankedIndex(java.util.Comparator<T> comparator,
int kthLowest) |
void |
set(int index,
T value) |
T[] |
setSize(int newSize)
Sets the array size, leaving any values beyond the current size null.
|
T[] |
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<? super T> comparator)
Sorts the array.
|
void |
swap(int first,
int second) |
T[] |
toArray()
Returns the items as an array.
|
<V> V[] |
toArray(java.lang.Class 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.
|
static <T> Array<T> |
with(T... array) |
public T[] items
Array(boolean, int, Class)
constructor was used.public int size
public boolean ordered
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 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 arrayType)
items
of the specified type and a capacity of 16.public Array(Array<? extends T> array)
public Array(T[] array)
public Array(boolean ordered, T[] array, int start, int count)
ordered
- If false, methods that remove elements may change the order of other elements in the array, which avoids a
memory copy.public void add(T value)
public void addAll(T... array)
public void addAll(T[] array, int start, int count)
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)
value
- May be null.identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public int indexOf(T value, boolean identity)
value
- May be null.identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public int lastIndexOf(T value, boolean identity)
value
- May be null.identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public boolean removeValue(T value, boolean identity)
value
- May be null.identity
- If true, == comparison will be used. If false, .equals() comparison will be used.public T removeIndex(int index)
public void removeRange(int start, int end)
public boolean removeAll(Array<? extends 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 T[] shrink()
items
public T[] ensureCapacity(int additionalCapacity)
items
public T[] setSize(int newSize)
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<? super T> comparator)
Sort.instance()
).public T selectRanked(java.util.Comparator<T> comparator, int kthLowest)
GdxRuntimeException
will be thrown.comparator
- used for comparisonkthLowest
- rank of desired object according to comparison, n is based on ordinal numbers, not array indices. for min
value use 1, for max value use size of array, using 0 results in runtime exception.Select
public int selectRankedIndex(java.util.Comparator<T> comparator, int kthLowest)
comparator
- used for comparisonkthLowest
- rank of desired object according to comparison, n is based on ordinal numbers, not array indices. for min
value use 1, for max value use size of array, using 0 results in runtime exception.selectRanked(Comparator, int)
public void reverse()
public void shuffle()
public java.util.Iterator<T> iterator()
Array.ArrayIterator
constructor for nested or multithreaded iteration.iterator
在接口中 java.lang.Iterable<T>
public java.lang.Iterable<T> select(Predicate<T> predicate)
Predicate.PredicateIterable
constructor for nested or multithreaded iteration.public void truncate(int newSize)
public T random()
public T[] toArray()
Array(Class)
constructor must have been used.
Otherwise use toArray(Class)
to specify the array type.public <V> V[] toArray(java.lang.Class type)
public int hashCode()
hashCode
在类中 java.lang.Object
public boolean equals(java.lang.Object object)
equals
在类中 java.lang.Object
public java.lang.String toString()
toString
在类中 java.lang.Object
public java.lang.String toString(java.lang.String separator)
public static <T> Array<T> of(java.lang.Class<T> arrayType)
Array(Class)
public static <T> Array<T> of(boolean ordered, int capacity, java.lang.Class<T> arrayType)
public static <T> Array<T> with(T... array)
Array(Object[])