. If unordered, this class
avoids a memory copy when removing elements (the last element is moved to the removed element's position).
- Author:
- Nathan Sweet
Constructor Summary |
LongArray()
Creates an ordered array with a capacity of 16. |
LongArray(boolean ordered,
int capacity)
|
LongArray(boolean ordered,
long[] array)
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 |
void |
add(long value)
|
void |
addAll(long[] array)
|
void |
addAll(long[] array,
int offset,
int length)
|
void |
addAll(LongArray array)
|
void |
addAll(LongArray array,
int offset,
int length)
|
void |
clear()
|
boolean |
contains(long value)
|
long[] |
ensureCapacity(int additionalCapacity)
Increases the size of the backing array to acommodate the specified number of additional items. |
long |
get(int index)
|
int |
indexOf(long value)
|
void |
insert(int index,
long value)
|
long |
peek()
Returns the last item. |
long |
pop()
Removes and returns the last item. |
long |
removeIndex(int index)
Removes and returns the item at the specified index. |
boolean |
removeValue(long value)
|
protected long[] |
resize(int newSize)
|
void |
reverse()
|
void |
set(int index,
long value)
|
void |
shrink()
Reduces the size of the backing array to the size of the actual items. |
void |
shuffle()
|
void |
sort()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
items
public long[] items
size
public int size
ordered
public boolean ordered
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)
- 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.
add
public void add(long value)
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)
insert
public void insert(int index,
long value)
contains
public boolean contains(long value)
indexOf
public int indexOf(long value)
removeValue
public boolean removeValue(long value)
removeIndex
public long removeIndex(int index)
- Removes and returns the item at the specified index.
pop
public long pop()
- Removes and returns the last item.
peek
public long peek()
- Returns the last item.
clear
public void clear()
shrink
public void 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.
ensureCapacity
public long[] ensureCapacity(int additionalCapacity)
- Increases the size of the backing array to acommodate the specified number of additional items. Useful before adding many
items to avoid multiple backing array resizes.
- Returns:
items
resize
protected long[] resize(int newSize)
sort
public void sort()
reverse
public void reverse()
shuffle
public void shuffle()
toString
public java.lang.String toString()
- Overrides:
toString
in class java.lang.Object
Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)