Class DelayedRemovalArray<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>

    public class DelayedRemovalArray<T>
    extends Array<T>
    An array that queues removal during iteration until the iteration has completed. Queues any removals done after begin() is called to occur once end() is called. This can allow code out of your control to remove items without affecting iteration. Between begin and end, most mutator methods will throw IllegalStateException. Only removeIndex(int), removeValue(Object, boolean), removeRange(int, int), clear(), and add methods are allowed.

    Note that DelayedRemovalArray is not for thread safety, only for removal during iteration.

    Code using this class must not rely on items being removed immediately. Consider using SnapshotArray if this is a problem.

    • Constructor Detail

      • DelayedRemovalArray

        public DelayedRemovalArray()
      • DelayedRemovalArray

        public DelayedRemovalArray​(Array array)
      • DelayedRemovalArray

        public DelayedRemovalArray​(boolean ordered,
                                   int capacity,
                                   java.lang.Class arrayType)
      • DelayedRemovalArray

        public DelayedRemovalArray​(boolean ordered,
                                   int capacity)
      • DelayedRemovalArray

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

        public DelayedRemovalArray​(java.lang.Class arrayType)
      • DelayedRemovalArray

        public DelayedRemovalArray​(int capacity)
      • DelayedRemovalArray

        public DelayedRemovalArray​(T[] array)
    • Method Detail

      • begin

        public void begin()
      • end

        public void end()
      • removeValue

        public boolean removeValue​(T value,
                                   boolean identity)
        Description copied from class: Array
        Removes the first instance of the specified value in the array.
        Overrides:
        removeValue in class Array<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
      • 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>
      • removeRange

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

        public void clear()
        Overrides:
        clear in class Array<T>
      • 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>
      • insertRange

        public void insertRange​(int index,
                                int count)
        Description copied from class: Array
        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.
        Overrides:
        insertRange in class Array<T>
      • swap

        public void swap​(int first,
                         int second)
        Overrides:
        swap 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>
      • 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​(java.util.Comparator<? super 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>
      • setSize

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