Interface DoubleArray

All Superinterfaces:
BaseArray<Double>, Iterable<Double>, Serializable
All Known Implementing Classes:
DoubleFastArray

public interface DoubleArray extends BaseArray<Double>
A type-safe array of primitive doubles.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default DoubleArray
    Append the provided array a to the end of this array, then returns the resulting array.
    double[]
    Returns a primitive array containing the elements of this array in their proper order.
    Returns an array containing the elements of this array in their boxed form.
    boolean
    contains(double v)
    Returns whether this array contains the provided value v.
    boolean
    Returns whether this array contains multiple objects.
    boolean
    Checks for equality between this array and the provided object obj.
    void
    fill(double v)
    Fills this array with the provided value v.
    void
    fillRange(int s, int e, double v)
    Fills every slot of this array between the range of [s, e) with the provided value v.
    default DoubleArray
    Tests each element of this array using the provided predicate f, collects all elements the predicate returns true to, then returns a new array containing only the filtered elements.
    void
    forEach(BiConsumer<? super Integer,? super Double> a)
    Executes the provided action a once for each element of this array.
    void
    forEach(Consumer<? super Double> a)
    Executes the provided action a once for each element of this array.
    Creates a new type-safe array from the provided stream of values.
    double
    get(int i)
    Returns the ith element of this array.
    Returns an iterator over every element of this array.
    int
    Returns the length of this array.
    Returns an unmodifiable list containing the elements of this array in their proper order.
    Applies the provided mapper function f to each element of this array, then returns a new array containing the return values of the function f.
    <F> SafeArray<F>
    mapToObj(DoubleFunction<? extends F> f)
    Applies the provided mapper function f to each element of this array, then returns a new array containing the return values of the function f.
    Between this array and the provided array a, this applies the merger function f to each corresponding pair of elements, then returns a new array containing the return values of the merger function f.
    of(double... values)
    Creates a new type-safe array from the provided array of values.
    default DoubleArray
    Prepends the provided array a to the front of this array, then returns the resulting array.
    referenceOf(double... values)
    Creates a new type-safe reference array from the provided array of values.
    void
    replaceAll(double oldValue, double newValue)
    Replaces all instances of the old value to the new value.
    void
    replaceFirst(double oldValue, double newValue)
    Replaces only the first instance of the old value to the new value.
    void
    replaceLast(double oldValue, double newValue)
    Replaces only the last instance of the old value to the new value.
    resize(int size)
    Returns a resized array whose elements are mapped from that of this array's elements.
    void
    set(int i, double e)
    Sets the ith element of this array.
    void
    setRange(int s, int e, DoubleArray a)
    Sets a sub-array of this array to the values of the provided sub-array a.
    void
    Shuffles this array, randomizing its elements' order.
    void
    Sorts this array by its natural ascending order.
    void
    sort(Comparator<? super Double> c)
    Sorts this array using the provided comparator function c.
    Returns a stream whose source is the elements of this array.
    subArray(int s, int e)
    Returns a sub-array of this array which represents a portion of this array between the range of [s, e).
    Serializes this array into a string.
    Returns a tuple containing the elements of this array in their proper order.
    void
    Updates the ith element of this array with the provided update function f.
    void
    update(BiFunction<? super Integer,? super Double,Double> f)
    Applies the provided update function f to each element of this array, then assigns the return value of the function to the corresponding index of this array.
    void
    Applies the provided update function f to each element of this array, then assigns the return value of the function to the corresponding index of this array.

    Methods inherited from interface java.lang.Iterable

    spliterator
  • Method Details

    • of

      @Nonnull static DoubleArray of(@Nonnull double... values)
      Creates a new type-safe array from the provided array of values.
      Parameters:
      values - The values to contain in the array
      Returns:
      A new type-safe array containing the provided values
    • referenceOf

      @Nonnull static DoubleArray referenceOf(@Nonnull double... values)
      Creates a new type-safe reference array from the provided array of values. Changes in the type-safe array will be reflected to the original array, as well as from the original array to the type-safe array.
      Parameters:
      values - The values the array should reference
      Returns:
      A new type-safe reference array referencing the provided values
    • from

      @Nonnull static DoubleArray from(@Nonnull DoubleStream s)
      Creates a new type-safe array from the provided stream of values.
      Parameters:
      s - The stream of which to use as the source of the array
      Returns:
      A new type-safe array containing the provided stream's values
    • length

      int length()
      Returns the length of this array.
      Specified by:
      length in interface BaseArray<Double>
      Returns:
      The number of elements this array contains
    • contains

      boolean contains(double v)
      Returns whether this array contains the provided value v.
      Parameters:
      v - The value to check for containment
      Returns:
      true if at least one element of this array is equal to the provided value v
    • containsAll

      boolean containsAll(@Nonnull Iterable<Double> i)
      Returns whether this array contains multiple objects.
      Parameters:
      i - The iterable object of which to check for containment
      Returns:
      true if this array contains every element of the iterable object
    • get

      double get(int i) throws IndexOutOfBoundsException
      Returns the ith element of this array.
      Parameters:
      i - The index of the element to get
      Returns:
      The ith element of this array
      Throws:
      IndexOutOfBoundsException - When the index i is out of bounds
    • set

      void set(int i, double e) throws IndexOutOfBoundsException
      Sets the ith element of this array.
      Parameters:
      i - The index of the element to set
      e - The element of which to set to
      Throws:
      IndexOutOfBoundsException - When the index i is out of bounds
    • update

      void update(int i, @Nonnull DoubleUnaryOperator f) throws IndexOutOfBoundsException
      Updates the ith element of this array with the provided update function f.
      Parameters:
      i - The index of the element to update
      f - The update function of which to apply to the element
      Throws:
      IndexOutOfBoundsException - When the index i is out of bounds
    • fill

      void fill(double v)
      Fills this array with the provided value v. Every element will be reassigned.
      Parameters:
      v - The value to fill this array with
    • fillRange

      void fillRange(int s, int e, double v)
      Fills every slot of this array between the range of [s, e) with the provided value v.
      Parameters:
      s - The starting index at which to start assigning values from
      e - The ending index at which to stop assigning values at
      v - The value of which to assign to every slot within the specified range
      Throws:
      IndexOutOfBoundsException - When the indices are out of bounds
    • update

      void update(@Nonnull DoubleUnaryOperator f)
      Applies the provided update function f to each element of this array, then assigns the return value of the function to the corresponding index of this array.
      Parameters:
      f - The function of which to apply to each element of this array
    • update

      void update(@Nonnull BiFunction<? super Integer,? super Double,Double> f)
      Applies the provided update function f to each element of this array, then assigns the return value of the function to the corresponding index of this array. The first parameter is the index of the value which was provided.
      Parameters:
      f - The function of which to apply to each element of this array
    • replaceAll

      void replaceAll(double oldValue, double newValue)
      Replaces all instances of the old value to the new value.
      Parameters:
      oldValue - The old value to replace
      newValue - The new value to replace to
    • replaceFirst

      void replaceFirst(double oldValue, double newValue)
      Replaces only the first instance of the old value to the new value. (starting from index 0, and incrementing upwards)
      Parameters:
      oldValue - The old value to replace
      newValue - The new value to replace to
    • replaceLast

      void replaceLast(double oldValue, double newValue)
      Replaces only the last instance of the old value to the new value. (starting from the last index, and decrementing downwards)
      Parameters:
      oldValue - The old value to replace
      newValue - The new value to replace to
    • subArray

      @Nonnull DoubleArray subArray(int s, int e) throws IndexOutOfBoundsException
      Returns a sub-array of this array which represents a portion of this array between the range of [s, e). Changes in the sub-array will be reflected to this array. For example, calling a.subArray(1, 3).fill(null); will have the same effect as setting the values of indices 1, 2 of the original array to null.
      Parameters:
      s - The starting index at which to start creating the sub-array (inclusive)
      e - The ending index at which to stop creating the sub-array (exclusive)
      Returns:
      The sub-array representing the index range of [s, e)
      Throws:
      IndexOutOfBoundsException - When the range is invalid, or is out of bounds
    • setRange

      void setRange(int s, int e, @Nonnull DoubleArray a) throws IndexOutOfBoundsException
      Sets a sub-array of this array to the values of the provided sub-array a.
      Parameters:
      s - The starting index at which to start copying values from (inclusive)
      e - The ending index at which to stop copying values from (exclusive)
      a - The sub-array containing the values to assign to this array
      Throws:
      IndexOutOfBoundsException - When the range is invalid, or is out of bounds
    • resize

      @Nonnull DoubleArray resize(int size)
      Returns a resized array whose elements are mapped from that of this array's elements. If the new array is larger than this array, the unmappable part will not be populated, leaving it uninitialized as null.
      Parameters:
      size - The size to resize this array to
      Returns:
      The resized array
    • shuffle

      void shuffle()
      Shuffles this array, randomizing its elements' order.
      Specified by:
      shuffle in interface BaseArray<Double>
    • sort

      void sort()
      Sorts this array by its natural ascending order.
      Specified by:
      sort in interface BaseArray<Double>
    • sort

      void sort(@Nonnull Comparator<? super Double> c)
      Sorts this array using the provided comparator function c.
      Specified by:
      sort in interface BaseArray<Double>
      Parameters:
      c - The comparator function of which to sort this array with
    • filter

      @Nonnull default DoubleArray filter(@Nonnull DoublePredicate f)
      Tests each element of this array using the provided predicate f, collects all elements the predicate returns true to, then returns a new array containing only the filtered elements.
      Parameters:
      f - The predicate to use to filter this array
      Returns:
      The filtered array
    • map

      @Nonnull DoubleArray map(@Nonnull DoubleUnaryOperator f)
      Applies the provided mapper function f to each element of this array, then returns a new array containing the return values of the function f.
      Parameters:
      f - The function of which to apply to each element of this array
      Returns:
      The resulting array
    • mapToObj

      @Nonnull <F> SafeArray<F> mapToObj(@Nonnull DoubleFunction<? extends F> f)
      Applies the provided mapper function f to each element of this array, then returns a new array containing the return values of the function f.
      Type Parameters:
      F - The type of element to map this array to
      Parameters:
      f - The function of which to apply to each element of this array
      Returns:
      The resulting array
    • merge

      @Nonnull DoubleArray merge(@Nonnull DoubleArray a, @Nonnull DoubleBinaryOperator f) throws IllegalArgumentException
      Between this array and the provided array a, this applies the merger function f to each corresponding pair of elements, then returns a new array containing the return values of the merger function f. In other words, this merges the two arrays into a new array using the provided merger function f.
      Parameters:
      a - The array of which to merge this array with
      f - The merger function to handle the merging of the two arrays
      Returns:
      The resulting array
      Throws:
      IllegalArgumentException - When the provided array a's length is different from that of this array's length
    • append

      @Nonnull default DoubleArray append(@Nonnull DoubleArray a)
      Append the provided array a to the end of this array, then returns the resulting array.
      Parameters:
      a - The array of which to append to the end of this array
      Returns:
      The appended array
    • prepend

      @Nonnull default DoubleArray prepend(@Nonnull DoubleArray a)
      Prepends the provided array a to the front of this array, then returns the resulting array.
      Parameters:
      a - The array of which to prepend to the front of this array
      Returns:
      The prepended array
    • iterator

      @Nonnull Iterator<Double> iterator()
      Returns an iterator over every element of this array.
      Specified by:
      iterator in interface BaseArray<Double>
      Specified by:
      iterator in interface Iterable<Double>
      Returns:
      An iterator over every element of this array
    • forEach

      void forEach(@Nonnull Consumer<? super Double> a)
      Executes the provided action a once for each element of this array. A reference to the element is provided as the first parameter of the action.
      Specified by:
      forEach in interface BaseArray<Double>
      Specified by:
      forEach in interface Iterable<Double>
      Parameters:
      a - The action to be performed for each element
    • forEach

      void forEach(@Nonnull BiConsumer<? super Integer,? super Double> a)
      Executes the provided action a once for each element of this array. The index of the element is provided as the first parameter of the action, and a reference to the element is provided as the second parameter of the action.
      Specified by:
      forEach in interface BaseArray<Double>
      Parameters:
      a - The action to be performed for each element
    • array

      @Nonnull double[] array()
      Returns a primitive array containing the elements of this array in their proper order.
      Returns:
      The primitive array representation of this array
    • stream

      @Nonnull DoubleStream stream()
      Returns a stream whose source is the elements of this array.
      Returns:
      A stream whose source is the elements of this array
      See Also:
    • list

      @Nonnull List<Double> list()
      Returns an unmodifiable list containing the elements of this array in their proper order.
      Specified by:
      list in interface BaseArray<Double>
      Returns:
      The list representation of this array
      Throws:
      NullPointerException - When this array contains at least one instance of null
      See Also:
    • tuple

      @Nonnull DoubleTuple tuple()
      Returns a tuple containing the elements of this array in their proper order. Unlike list(), this operation cannot fail as tuples inherently support the usage of null as their values.
      Returns:
      The tuple representation of this array
      See Also:
    • boxed

      @Nonnull SafeArray<Double> boxed()
      Returns an array containing the elements of this array in their boxed form.
      Returns:
      The boxed object representation of this array
      See Also:
    • equals

      boolean equals(@Nullable Object obj)
      Checks for equality between this array and the provided object obj.
      Overrides:
      equals in class Object
      Parameters:
      obj - The object to compare to
      Returns:
      true if the object is also a double array, and the number of elements, the order of the elements, and the elements' values are all equal
    • toString

      @Nonnull String toString()
      Serializes this array into a string.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this array