com.badlogic.gdx.utils
Class SnapshotArray<T>

java.lang.Object
  extended by com.badlogic.gdx.utils.Array<T>
      extended by com.badlogic.gdx.utils.SnapshotArray<T>
All Implemented Interfaces:
Iterable<T>

public class SnapshotArray<T>
extends Array<T>

Guarantees that array entries provided by begin() between indexes 0 and Array.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.

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++) {
        Object item = items[i];
        // ...
 }
 array.end();
 

Author:
Nathan Sweet

Nested Class Summary
 
Nested classes/interfaces inherited from class com.badlogic.gdx.utils.Array
Array.ArrayIterable<T>, Array.ArrayIterator<T>
 
Field Summary
 
Fields inherited from class com.badlogic.gdx.utils.Array
items, ordered, size
 
Constructor Summary
SnapshotArray()
           
SnapshotArray(Array array)
           
SnapshotArray(boolean ordered, int capacity)
           
SnapshotArray(boolean ordered, int capacity, Class arrayType)
           
SnapshotArray(boolean ordered, T[] array, int startIndex, int count)
           
SnapshotArray(Class arrayType)
           
SnapshotArray(int capacity)
           
SnapshotArray(T[] array)
           
 
Method Summary
 T[] begin()
          Returns the backing array, which is guaranteed to not be modified before end().
 void clear()
           
 void end()
          Releases the guarantee that the array returned by begin() won't be modified.
 void insert(int index, T value)
           
 T pop()
          Removes and returns the last item.
 T removeIndex(int index)
          Removes and returns the item at the specified index.
 boolean removeValue(T value, boolean identity)
          Removes value from an array if it exists.
 void reverse()
           
 void set(int index, T value)
           
 void shuffle()
           
 void sort()
          Sorts this array.
 void sort(Comparator<T> comparator)
          Sorts the array.
 void swap(int first, int second)
           
 void truncate(int newSize)
          Reduces the size of the array to the specified size.
 
Methods inherited from class com.badlogic.gdx.utils.Array
add, addAll, addAll, addAll, addAll, contains, ensureCapacity, equals, first, get, indexOf, iterator, lastIndexOf, peek, random, removeAll, select, selectRanked, selectRankedIndex, shrink, toArray, toArray, toString, toString
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SnapshotArray

public SnapshotArray()

SnapshotArray

public SnapshotArray(Array array)

SnapshotArray

public SnapshotArray(boolean ordered,
                     int capacity,
                     Class arrayType)

SnapshotArray

public SnapshotArray(boolean ordered,
                     int capacity)

SnapshotArray

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

SnapshotArray

public SnapshotArray(Class arrayType)

SnapshotArray

public SnapshotArray(int capacity)

SnapshotArray

public SnapshotArray(T[] array)
Method Detail

begin

public T[] begin()
Returns the backing array, which is guaranteed to not be modified before end().


end

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


set

public void set(int index,
                T value)
Overrides:
set in class Array<T>

insert

public void insert(int index,
                   T value)
Overrides:
insert in class Array<T>

swap

public void swap(int first,
                 int second)
Overrides:
swap in class Array<T>

removeValue

public boolean removeValue(T value,
                           boolean identity)
Description copied from class: Array
Removes value from an array if it exists.

Overrides:
removeValue in class Array<T>
identity - If true, == comparison will be used. If false, .equals() comparison will be used.
Returns:
true if value was found and removed, false otherwise

removeIndex

public T removeIndex(int index)
Description copied from class: Array
Removes and returns the item at the specified index.

Overrides:
removeIndex in class Array<T>

pop

public T pop()
Description copied from class: Array
Removes and returns the last item.

Overrides:
pop in class Array<T>

clear

public void clear()
Overrides:
clear in class Array<T>

sort

public void sort()
Description copied from class: Array
Sorts this array. The array elements must implement Comparable. This method is not thread safe (uses Sort.instance()).

Overrides:
sort in class Array<T>

sort

public void sort(Comparator<T> comparator)
Description copied from class: Array
Sorts the array. This method is not thread safe (uses Sort.instance()).

Overrides:
sort in class Array<T>

reverse

public void reverse()
Overrides:
reverse in class Array<T>

shuffle

public void shuffle()
Overrides:
shuffle in class Array<T>

truncate

public void truncate(int newSize)
Description copied from class: Array
Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.

Overrides:
truncate in class Array<T>


Copyright © 2013. All Rights Reserved.