Package arc.struct

Class SnapshotSeq<T>

java.lang.Object
arc.struct.Seq<T>
arc.struct.SnapshotSeq<T>
All Implemented Interfaces:
Eachable<T>, Iterable<T>

public class SnapshotSeq<T> extends Seq<T>
Guarantees that array entries provided by begin() between indexes 0 and Seq.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();
 
  • Constructor Details

    • SnapshotSeq

      public SnapshotSeq()
    • SnapshotSeq

      public SnapshotSeq(Seq<T> array)
    • SnapshotSeq

      public SnapshotSeq(boolean ordered, int capacity, Class<?> arrayType)
    • SnapshotSeq

      public SnapshotSeq(boolean ordered, int capacity)
    • SnapshotSeq

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

      public SnapshotSeq(Class<?> arrayType)
    • SnapshotSeq

      public SnapshotSeq(int capacity)
    • SnapshotSeq

      public SnapshotSeq(T[] array)
  • Method Details

    • with

      public static <T> SnapshotSeq<T> with(T... array)
      See Also:
    • 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 Seq<T>
    • insert

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

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

      public boolean remove(T value, boolean identity)
      Description copied from class: Seq
      Removes the first instance of the specified value in the array.
      Overrides:
      remove in class Seq<T>
      Parameters:
      value - May be null.
      identity - If true, == comparison will be used. If false, .equals() comparison will be used.
      Returns:
      true if value was found and removed, false otherwise
    • remove

      public T remove(int index)
      Description copied from class: Seq
      Removes and returns the item at the specified index.
      Overrides:
      remove in class Seq<T>
    • removeRange

      public void removeRange(int start, int end)
      Description copied from class: Seq
      Removes the items between the specified indices, inclusive.
      Overrides:
      removeRange in class Seq<T>
    • removeAll

      public boolean removeAll(Seq<? extends T> array, boolean identity)
      Description copied from class: Seq
      Removes from this array all of elements contained in the specified array.
      Overrides:
      removeAll in class Seq<T>
      identity - True to use ==, false to use .equals().
      Returns:
      true if this array was modified.
    • pop

      public T pop()
      Description copied from class: Seq
      Removes and returns the last item.
      Overrides:
      pop in class Seq<T>
    • clear

      public Seq<T> clear()
      Overrides:
      clear in class Seq<T>
    • sort

      public Seq<T> sort()
      Description copied from class: Seq
      Sorts this array. The array elements must implement Comparable. This method is not thread safe (uses Sort.instance()).
      Overrides:
      sort in class Seq<T>
    • sort

      public Seq<T> sort(Comparator<? super T> comparator)
      Description copied from class: Seq
      Sorts the array. This method is not thread safe (uses Sort.instance()).
      Overrides:
      sort in class Seq<T>
    • reverse

      public Seq<T> reverse()
      Overrides:
      reverse in class Seq<T>
    • shuffle

      public Seq<T> shuffle()
      Overrides:
      shuffle in class Seq<T>
    • truncate

      public void truncate(int newSize)
      Description copied from class: Seq
      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 Seq<T>
    • setSize

      public T[] setSize(int newSize)
      Description copied from class: Seq
      Sets the array size, leaving any values beyond the current size null.
      Overrides:
      setSize in class Seq<T>
      Returns:
      Seq.items