Package com.badlogic.gdx.utils
Class LongArray
- java.lang.Object
-
- com.badlogic.gdx.utils.LongArray
-
public class LongArray extends java.lang.ObjectA resizable, ordered or unordered long array. Avoids the boxing that occurs with ArrayList. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position).
-
-
Constructor Summary
Constructors Constructor Description LongArray()Creates an ordered array with a capacity of 16.LongArray(boolean ordered, int capacity)LongArray(boolean ordered, long[] array, int startIndex, int count)Creates a new array containing the elements in the specified array.LongArray(int capacity)Creates an ordered array with the specified capacity.LongArray(long[] array)Creates a new ordered array containing the elements in the specified array.LongArray(LongArray array)Creates a new array containing the elements in the specific array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long value)voidadd(long value1, long value2)voidadd(long value1, long value2, long value3)voidadd(long value1, long value2, long value3, long value4)voidaddAll(long... array)voidaddAll(long[] array, int offset, int length)voidaddAll(LongArray array)voidaddAll(LongArray array, int offset, int length)voidclear()booleancontains(long value)long[]ensureCapacity(int additionalCapacity)Increases the size of the backing array to accommodate the specified number of additional items.booleanequals(java.lang.Object object)longfirst()Returns the first item.longget(int index)inthashCode()voidincr(int index, long value)voidincr(long value)intindexOf(long value)voidinsert(int index, long value)voidinsertRange(int index, int count)Inserts the specified number of items at the specified index.booleanisEmpty()Returns true if the array is empty.intlastIndexOf(char value)voidmul(int index, long value)voidmul(long value)booleannotEmpty()Returns true if the array has one or more items.longpeek()Returns the last item.longpop()Removes and returns the last item.longrandom()Returns a random item from the array, or zero if the array is empty.booleanremoveAll(LongArray array)Removes from this array all of elements contained in the specified array.longremoveIndex(int index)Removes and returns the item at the specified index.voidremoveRange(int start, int end)Removes the items between the specified indices, inclusive.booleanremoveValue(long value)protected long[]resize(int newSize)voidreverse()voidset(int index, long value)long[]setSize(int newSize)Sets the array size, leaving any values beyond the current size undefined.long[]shrink()Reduces the size of the backing array to the size of the actual items.voidshuffle()voidsort()voidswap(int first, int second)long[]toArray()java.lang.StringtoString()java.lang.StringtoString(java.lang.String separator)voidtruncate(int newSize)Reduces the size of the array to the specified size.static LongArraywith(long... array)
-
-
-
Constructor Detail
-
LongArray
public LongArray()
Creates an ordered array with a capacity of 16.
-
LongArray
public LongArray(int capacity)
Creates an ordered array with the specified capacity.
-
LongArray
public LongArray(boolean ordered, int capacity)- Parameters:
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.
-
LongArray
public LongArray(LongArray array)
Creates a new array containing the elements in the specific array. The new array will be ordered if the specific array is ordered. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
-
LongArray
public LongArray(long[] array)
Creates a new ordered array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
-
LongArray
public LongArray(boolean ordered, long[] array, int startIndex, int count)Creates a new array containing the elements in the specified array. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.- Parameters:
ordered- If false, methods that remove elements may change the order of other elements in the array, which avoids a memory copy.
-
-
Method Detail
-
add
public void add(long value)
-
add
public void add(long value1, long value2)
-
add
public void add(long value1, long value2, long value3)
-
add
public void add(long value1, long value2, long value3, long value4)
-
addAll
public void addAll(LongArray array)
-
addAll
public void addAll(LongArray array, int offset, int length)
-
addAll
public void addAll(long... array)
-
addAll
public void addAll(long[] array, int offset, int length)
-
get
public long get(int index)
-
set
public void set(int index, long value)
-
incr
public void incr(int index, long value)
-
incr
public void incr(long value)
-
mul
public void mul(int index, long value)
-
mul
public void mul(long value)
-
insert
public void insert(int index, long value)
-
insertRange
public void insertRange(int index, int count)Inserts the specified number of items at the specified index. The new items will have values equal to the values at those indices before the insertion.
-
swap
public void swap(int first, int second)
-
contains
public boolean contains(long value)
-
indexOf
public int indexOf(long value)
-
lastIndexOf
public int lastIndexOf(char value)
-
removeValue
public boolean removeValue(long value)
-
removeIndex
public long removeIndex(int index)
Removes and returns the item at the specified index.
-
removeRange
public void removeRange(int start, int end)Removes the items between the specified indices, inclusive.
-
removeAll
public boolean removeAll(LongArray array)
Removes from this array all of elements contained in the specified array.- Returns:
- true if this array was modified.
-
pop
public long pop()
Removes and returns the last item.
-
peek
public long peek()
Returns the last item.
-
first
public long first()
Returns the first item.
-
notEmpty
public boolean notEmpty()
Returns true if the array has one or more items.
-
isEmpty
public boolean isEmpty()
Returns true if the array is empty.
-
clear
public void clear()
-
shrink
public long[] shrink()
Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.- Returns:
items
-
ensureCapacity
public long[] ensureCapacity(int additionalCapacity)
Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.- Returns:
items
-
setSize
public long[] setSize(int newSize)
Sets the array size, leaving any values beyond the current size undefined.- Returns:
items
-
resize
protected long[] resize(int newSize)
-
sort
public void sort()
-
reverse
public void reverse()
-
shuffle
public void shuffle()
-
truncate
public void truncate(int newSize)
Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
-
random
public long random()
Returns a random item from the array, or zero if the array is empty.
-
toArray
public long[] toArray()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toString
public java.lang.String toString(java.lang.String separator)
-
with
public static LongArray with(long... array)
- See Also:
LongArray(long[])
-
-