Class ShortVLA

java.lang.Object
squidpony.squidmath.ShortVLA
All Implemented Interfaces:
Serializable

public class ShortVLA
extends Object
implements Serializable
A resizable, ordered or unordered short variable-length array. Avoids the boxing that occurs with ArrayList<Short>. If unordered, this class avoids a memory copy when removing elements (the last element is moved to the removed element's position). Used internally by CoordPacker, and unlikely to be used outside of it.
Was called IntArray in libGDX; to avoid confusion with the fixed-length primitive array type, VLA (variable-length array) was chosen as a different name. Also uses short instead of int, of course. Copied from LibGDX by Tommy Ettinger on 10/1/2015.
Author:
Nathan Sweet
See Also:
Serialized Form
  • Field Summary

    Fields 
    Modifier and Type Field Description
    short[] items  
    boolean ordered  
    int size  
  • Constructor Summary

    Constructors 
    Constructor Description
    ShortVLA()
    Creates an ordered array with a capacity of 16.
    ShortVLA​(boolean ordered, int capacity)  
    ShortVLA​(boolean ordered, short[] array, int startIndex, int count)
    Creates a new array containing the elements in the specified array.
    ShortVLA​(int capacity)
    Creates an ordered array with the specified capacity.
    ShortVLA​(int[] array)
    Creates a new ordered array containing the elements in the specified array, converted to short.
    ShortVLA​(short[] array)
    Creates a new ordered array containing the elements in the specified array.
    ShortVLA​(ShortVLA array)
    Creates a new array containing the elements in the specific array.
  • Method Summary

    Modifier and Type Method Description
    void add​(short value)  
    void addAll​(int[] array)  
    void addAll​(short... array)  
    void addAll​(short[] array, int offset, int length)  
    void addAll​(ShortVLA array)  
    void addAll​(ShortVLA array, int offset, int length)  
    void addFractionRange​(int start, int end, int fraction)  
    void addRange​(int start, int end)  
    int[] asInts()  
    void clear()  
    boolean contains​(short value)  
    short[] ensureCapacity​(int additionalCapacity)
    Increases the size of the backing array to accommodate the specified number of additional items.
    boolean equals​(Object object)  
    short first()
    Returns the first item.
    short get​(int index)  
    int hashCode()  
    void incr​(int index, short value)
    Adds value to the item in the ShortVLA at index.
    int indexOf​(short value)  
    void insert​(int index, short value)  
    int lastIndexOf​(short value)  
    void mul​(int index, short value)  
    short peek()
    Returns the last item.
    short pop()
    Removes and returns the last item.
    boolean removeAll​(ShortVLA array)
    Removes from this array all of elements contained in the specified array.
    short removeIndex​(int index)
    Removes and returns the item at the specified index.
    void removeRange​(int start, int end)
    Removes the items between the specified indices, inclusive.
    boolean removeValue​(short value)  
    protected short[] resize​(int newSize)  
    void reverse()  
    void set​(int index, short value)  
    short[] shrink()
    Reduces the size of the backing array to the size of the actual items.
    void sort()  
    void swap​(int first, int second)  
    short[] toArray()  
    String toString()  
    String toString​(String separator)  
    void truncate​(int newSize)
    Reduces the size of the array to the specified size.
    static ShortVLA with​(short... array)  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • ShortVLA

      public ShortVLA()
      Creates an ordered array with a capacity of 16.
    • ShortVLA

      public ShortVLA​(int capacity)
      Creates an ordered array with the specified capacity.
    • ShortVLA

      public ShortVLA​(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.
    • ShortVLA

      public ShortVLA​(ShortVLA 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.
    • ShortVLA

      public ShortVLA​(short[] 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.
    • ShortVLA

      public ShortVLA​(int[] array)
      Creates a new ordered array containing the elements in the specified array, converted to short. The capacity is set to the number of elements, so any subsequent elements added will cause the backing array to be grown.
    • ShortVLA

      public ShortVLA​(boolean ordered, short[] array, int startIndex, int count)
      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.
  • Method Details