APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.utils

public Class SnapshotArray<T>

extends Array<T>
Class Inheritance
Imports
java.util.Arrays, .Comparator

An array that allows modification during iteration. Guarantees that array entries provided by begin() between indexes 0 and size at the time begin was called will not be modified until end() is called. If modification of the SnapshotArray occurs between begin/end, the backing array is copied prior to the modification, ensuring that the backing array that was returned by begin() is unaffected. To avoid allocation, an attempt is made to reuse any extra array created as a result of this copy on subsequent copies.

Note that SnapshotArray is not for thread safety, only for modification during iteration.

It is suggested iteration be done in this specific way:

SnapshotArray array = new SnapshotArray();
// ...
Object[] items = array.begin();
for (int i = 0, n = array.size; i < n; i++) {
	Item item = (Item)items[i];
	// ...
}
array.end();
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private T[]
private T[]
private int
Inherited from com.badlogic.gdx.utils.Array:
itemsorderedsize

Constructor Summary

AccessConstructor and Description
public
public
SnapshotArray(Array<T> array)

public
SnapshotArray(boolean ordered, int capacity, ArraySupplier<T[]> arraySupplier)

public
SnapshotArray(boolean ordered, int capacity, Class<T> arrayType)
Deprecated

public
SnapshotArray(boolean ordered, int capacity)

public
SnapshotArray(boolean ordered, T[] array, int startIndex, int count)

public
SnapshotArray(ArraySupplier<T[]> arraySupplier)

public
SnapshotArray(Class<T> arrayType)
Deprecated

public
SnapshotArray(int capacity)

public
SnapshotArray(T[] array)

Method Summary

Modifier and TypeMethod and Description
public T[]
begin()

Returns the backing array, which is guaranteed to not be modified before end().

public void
public void
end()

Releases the guarantee that the array returned by begin() won't be modified.

public void
insert(int index, T value)

Overrides com.badlogic.gdx.utils.Array.insert.

public void
insertRange(int index, int count)

Overrides com.badlogic.gdx.utils.Array.insertRange.

Inserts the specified number of items at the specified index.

private void
public T
pop()

Overrides com.badlogic.gdx.utils.Array.pop.

Removes and returns the last item.

public boolean
removeAll(Array<? extends T> array, boolean identity)

Overrides com.badlogic.gdx.utils.Array.removeAll.

Removes from this array the first instance of each element contained in the specified array.

public T
removeIndex(int index)

Overrides com.badlogic.gdx.utils.Array.removeIndex.

Removes and returns the item at the specified index.

public void
removeRange(int start, int end)

Overrides com.badlogic.gdx.utils.Array.removeRange.

Removes the items between the specified indices, inclusive.

public boolean
removeValue(T value, boolean identity)

Overrides com.badlogic.gdx.utils.Array.removeValue.

Removes the first instance of the specified value in the array.

public int
replaceAll(T value, boolean identity, T replacement)

Overrides com.badlogic.gdx.utils.Array.replaceAll.

Returns the number of replacements done.

public boolean
replaceFirst(T value, boolean identity, T replacement)

Overrides com.badlogic.gdx.utils.Array.replaceFirst.

Returns true if the specified value was replaced successfully with the replacement

public void
public void
set(int index, T value)

Overrides com.badlogic.gdx.utils.Array.set.

public T[]
setSize(int newSize)

Overrides com.badlogic.gdx.utils.Array.setSize.

Sets the array size, leaving any values beyond the current size null.

public void
public void
sort()

Overrides com.badlogic.gdx.utils.Array.sort.

Sorts this array.

public void
sort(Comparator<? super T> comparator)

Overrides com.badlogic.gdx.utils.Array.sort.

Sorts the array.

public void
swap(int first, int second)

Overrides com.badlogic.gdx.utils.Array.swap.

public void
truncate(int newSize)

Overrides com.badlogic.gdx.utils.Array.truncate.

Reduces the size of the array to the specified size.

public static <T> SnapshotArray<T>
Inherited from com.badlogic.gdx.utils.Array:
addaddaddaddaddAlladdAlladdAlladdAllcontainscontainsAllcontainsAnyensureCapacityequalsequalsIdentityfirstgethashCodeindexOfisEmptyiteratorlastIndexOfnotEmptyofofofofpeekrandomresizeselectselectRankedselectRankedIndexshrinktoArraytoArraytoArraytoStringtoString

Field Detail

recycledback to summary
private T[] recycled
snapshotback to summary
private T[] snapshot
snapshotsback to summary
private int snapshots

Constructor Detail

SnapshotArrayback to summary
public SnapshotArray()
SnapshotArrayback to summary
public SnapshotArray(Array<T> array)
SnapshotArrayback to summary
public SnapshotArray(boolean ordered, int capacity, ArraySupplier<T[]> arraySupplier)
SnapshotArrayback to summary
public SnapshotArray(boolean ordered, int capacity, Class<T> arrayType)

Deprecated

Annotations
@Deprecated
SnapshotArrayback to summary
public SnapshotArray(boolean ordered, int capacity)
SnapshotArrayback to summary
public SnapshotArray(boolean ordered, T[] array, int startIndex, int count)
SnapshotArrayback to summary
public SnapshotArray(ArraySupplier<T[]> arraySupplier)
SnapshotArrayback to summary
public SnapshotArray(Class<T> arrayType)

Deprecated

Annotations
@Deprecated
SnapshotArrayback to summary
public SnapshotArray(int capacity)
SnapshotArrayback to summary
public SnapshotArray(T[] array)

Method Detail

beginback to summary
public T[] begin()

Returns the backing array, which is guaranteed to not be modified before end().

clearback to summary
public void clear()

Overrides com.badlogic.gdx.utils.Array.clear.

endback to summary
public void end()

Releases the guarantee that the array returned by begin() won't be modified.

insertback to summary
public void insert(int index, T value)

Overrides com.badlogic.gdx.utils.Array.insert.

insertRangeback to summary
public void insertRange(int index, int count)

Overrides com.badlogic.gdx.utils.Array.insertRange.

Doc from com.badlogic.gdx.utils.Array.insertRange.

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.

modifiedback to summary
private void modified()
popback to summary
public T pop()

Overrides com.badlogic.gdx.utils.Array.pop.

Doc from com.badlogic.gdx.utils.Array.pop.

Removes and returns the last item.

removeAllback to summary
public boolean removeAll(Array<? extends T> array, boolean identity)

Overrides com.badlogic.gdx.utils.Array.removeAll.

Doc from com.badlogic.gdx.utils.Array.removeAll.

Removes from this array the first instance of each element contained in the specified array.

removeIndexback to summary
public T removeIndex(int index)

Overrides com.badlogic.gdx.utils.Array.removeIndex.

Doc from com.badlogic.gdx.utils.Array.removeIndex.

Removes and returns the item at the specified index.

removeRangeback to summary
public void removeRange(int start, int end)

Overrides com.badlogic.gdx.utils.Array.removeRange.

Doc from com.badlogic.gdx.utils.Array.removeRange.

Removes the items between the specified indices, inclusive.

removeValueback to summary
public boolean removeValue(T value, boolean identity)

Overrides com.badlogic.gdx.utils.Array.removeValue.

Doc from com.badlogic.gdx.utils.Array.removeValue.

Removes the first instance of the specified value in the array.

replaceAllback to summary
public int replaceAll(T value, boolean identity, T replacement)

Overrides com.badlogic.gdx.utils.Array.replaceAll.

Doc from com.badlogic.gdx.utils.Array.replaceAll.

Returns the number of replacements done.

replaceFirstback to summary
public boolean replaceFirst(T value, boolean identity, T replacement)

Overrides com.badlogic.gdx.utils.Array.replaceFirst.

Doc from com.badlogic.gdx.utils.Array.replaceFirst.

Returns true if the specified value was replaced successfully with the replacement

reverseback to summary
public void reverse()

Overrides com.badlogic.gdx.utils.Array.reverse.

setback to summary
public void set(int index, T value)

Overrides com.badlogic.gdx.utils.Array.set.

setSizeback to summary
public T[] setSize(int newSize)

Overrides com.badlogic.gdx.utils.Array.setSize.

Doc from com.badlogic.gdx.utils.Array.setSize.

Sets the array size, leaving any values beyond the current size null.

shuffleback to summary
public void shuffle()

Overrides com.badlogic.gdx.utils.Array.shuffle.

sortback to summary
public void sort()

Overrides com.badlogic.gdx.utils.Array.sort.

Doc from com.badlogic.gdx.utils.Array.sort.

Sorts this array. The array elements must implement Comparable. This method is not thread safe (uses Sort#instance()).

sortback to summary
public void sort(Comparator<? super T> comparator)

Overrides com.badlogic.gdx.utils.Array.sort.

Doc from com.badlogic.gdx.utils.Array.sort.

Sorts the array. This method is not thread safe (uses Sort#instance()).

swapback to summary
public void swap(int first, int second)

Overrides com.badlogic.gdx.utils.Array.swap.

truncateback to summary
public void truncate(int newSize)

Overrides com.badlogic.gdx.utils.Array.truncate.

Doc from com.badlogic.gdx.utils.Array.truncate.

Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.

withback to summary
public static <T> SnapshotArray<T> with(T... array)

Hides com.badlogic.gdx.utils.Array.with.

See Also
SnapshotArray(Object[])