Package gaiasky.util

Class DoubleArray

java.lang.Object
gaiasky.util.DoubleArray

public class DoubleArray extends Object
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    double[]
     
    boolean
     
    int
     
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Creates an ordered array with a capacity of 16.
    DoubleArray(boolean ordered, double[] array, int startIndex, int count)
    Creates a new array containing the elements in the specified array.
    DoubleArray(boolean ordered, int capacity)
     
    DoubleArray(double[] array)
    Creates a new ordered array containing the elements in the specified array.
    DoubleArray(int capacity)
    Creates an ordered array with the specified capacity.
    Creates a new array containing the elements in the specific array.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    add(double value)
     
    void
    add(double value1, double value2)
     
    void
    add(double value1, double value2, double value3)
     
    void
    add(double value1, double value2, double value3, double value4)
     
    void
    addAll(double... array)
     
    void
    addAll(double[] array, int offset, int length)
     
    void
     
    void
    addAll(DoubleArray array, int offset, int length)
     
    void
     
    boolean
    contains(double value)
     
    double[]
    ensureCapacity(int additionalCapacity)
    Increases the size of the backing array to accommodate the specified number of additional items.
    boolean
    equals(Object object)
    Returns false if either array is unordered.
    boolean
    equals(Object object, double epsilon)
    Returns false if either array is unordered.
    double
    Returns the first item.
    double
    get(int index)
     
    int
     
    void
    incr(double value)
     
    void
    incr(int index, double value)
     
    int
    indexOf(double value)
     
    void
    insert(int index, double value)
     
    void
    insertRange(int index, int count)
    Inserts the specified number of items at the specified index.
    boolean
    Returns true if the array is empty.
    int
    lastIndexOf(double value)
     
    void
    mul(double value)
     
    void
    mul(int index, double value)
     
    boolean
    Returns true if the array has one or more items.
    double
    Returns the last item.
    double
    pop()
    Removes and returns the last item.
    double
    Returns a random item from the array, or zero if the array is empty.
    boolean
    Removes from this array all of elements contained in the specified array.
    double
    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(double value)
     
    protected double[]
    resize(int newSize)
     
    void
     
    void
    set(int index, double value)
     
    double[]
    setSize(int newSize)
    Sets the array size, leaving any values beyond the current size undefined.
    double[]
    Reduces the size of the backing array to the size of the actual items.
    void
     
    void
     
    void
    swap(int first, int second)
     
    double[]
     
     
    toString(String separator)
     
    void
    truncate(int newSize)
    Reduces the size of the array to the specified size.
    with(double... array)
     

    Methods inherited from class java.lang.Object Link icon

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

    • items Link icon

      public double[] items
    • size Link icon

      public int size
    • ordered Link icon

      public boolean ordered
  • Constructor Details Link icon

    • DoubleArray Link icon

      public DoubleArray()
      Creates an ordered array with a capacity of 16.
    • DoubleArray Link icon

      public DoubleArray(int capacity)
      Creates an ordered array with the specified capacity.
    • DoubleArray Link icon

      public DoubleArray(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.
    • DoubleArray Link icon

      public DoubleArray(DoubleArray 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.
    • DoubleArray Link icon

      public DoubleArray(double[] 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.
    • DoubleArray Link icon

      public DoubleArray(boolean ordered, double[] 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 Link icon

    • with Link icon

      public static DoubleArray with(double... array)
      See Also:
    • add Link icon

      public void add(double value)
    • add Link icon

      public void add(double value1, double value2)
    • add Link icon

      public void add(double value1, double value2, double value3)
    • add Link icon

      public void add(double value1, double value2, double value3, double value4)
    • addAll Link icon

      public void addAll(DoubleArray array)
    • addAll Link icon

      public void addAll(DoubleArray array, int offset, int length)
    • addAll Link icon

      public void addAll(double... array)
    • addAll Link icon

      public void addAll(double[] array, int offset, int length)
    • get Link icon

      public double get(int index)
    • set Link icon

      public void set(int index, double value)
    • incr Link icon

      public void incr(int index, double value)
    • incr Link icon

      public void incr(double value)
    • mul Link icon

      public void mul(int index, double value)
    • mul Link icon

      public void mul(double value)
    • insert Link icon

      public void insert(int index, double value)
    • insertRange Link icon

      public void insertRange(int index, int count)
      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.
    • swap Link icon

      public void swap(int first, int second)
    • contains Link icon

      public boolean contains(double value)
    • indexOf Link icon

      public int indexOf(double value)
    • lastIndexOf Link icon

      public int lastIndexOf(double value)
    • removeValue Link icon

      public boolean removeValue(double value)
    • removeIndex Link icon

      public double removeIndex(int index)
      Removes and returns the item at the specified index.
    • removeRange Link icon

      public void removeRange(int start, int end)
      Removes the items between the specified indices, inclusive.
    • removeAll Link icon

      public boolean removeAll(DoubleArray array)
      Removes from this array all of elements contained in the specified array.
      Returns:
      true if this array was modified.
    • pop Link icon

      public double pop()
      Removes and returns the last item.
    • peek Link icon

      public double peek()
      Returns the last item.
    • first Link icon

      public double first()
      Returns the first item.
    • notEmpty Link icon

      public boolean notEmpty()
      Returns true if the array has one or more items.
    • isEmpty Link icon

      public boolean isEmpty()
      Returns true if the array is empty.
    • clear Link icon

      public void clear()
    • shrink Link icon

      public double[] shrink()
      Reduces the size of the backing array to the size of the actual items. This is useful to release memory when many items have been removed, or if it is known that more items will not be added.
      Returns:
      items
    • ensureCapacity Link icon

      public double[] ensureCapacity(int additionalCapacity)
      Increases the size of the backing array to accommodate the specified number of additional items. Useful before adding many items to avoid multiple backing array resizes.
      Returns:
      items
    • setSize Link icon

      public double[] setSize(int newSize)
      Sets the array size, leaving any values beyond the current size undefined.
      Returns:
      items
    • resize Link icon

      protected double[] resize(int newSize)
    • sort Link icon

      public void sort()
    • reverse Link icon

      public void reverse()
    • shuffle Link icon

      public void shuffle()
    • truncate Link icon

      public void truncate(int newSize)
      Reduces the size of the array to the specified size. If the array is already smaller than the specified size, no action is taken.
    • random Link icon

      public double random()
      Returns a random item from the array, or zero if the array is empty.
    • toArray Link icon

      public double[] toArray()
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals Link icon

      public boolean equals(Object object)
      Returns false if either array is unordered.
      Overrides:
      equals in class Object
    • equals Link icon

      public boolean equals(Object object, double epsilon)
      Returns false if either array is unordered.
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • toString Link icon

      public String toString(String separator)