Class Array<T>

Type Parameters:
T - the array element type
All Implemented Interfaces:
BaseMSeq<T>, BaseSeq<T>, Serializable, Iterable<T>, RandomAccess

public final class Array<T> extends Object implements BaseMSeq<T>, Serializable
Array implementation class. This class manages the actual array (store) and the start index and the length.
Since:
3.4
Version:
6.0
See Also:
  • Method Details

    • get

      public T get(int index)
      Get the array value at the given index. The array index is not checked.
      Specified by:
      get in interface BaseSeq<T>
      Parameters:
      index - the array index
      Returns:
      the value at the given index
    • length

      public int length()
      Return the array length.
      Specified by:
      length in interface BaseSeq<T>
      Returns:
      the array length
    • set

      public void set(int index, T value)
      Set the value at the given index. The array index is not checked.
      Specified by:
      set in interface BaseMSeq<T>
      Parameters:
      index - the array index
      value - the value to set
    • store

      public Array.Store<T> store()
      Return the underlying array store.
      Returns:
      the underlying array store
    • copyIfSealed

      public void copyIfSealed()
    • seal

      public Array<T> seal()
      Return a new sealed array instance. The underlying store is sealed as well, but not copied.
      Returns:
      a new sealed array
    • isSealed

      public boolean isSealed()
      Return the seal state of the array.
      Returns:
      true is the array is sealed, false otherwise
    • sort

      public void sort(int from, int until, Comparator<? super T> comparator)
      Sort the store.
      Parameters:
      from - the start index where to start sorting (inclusively)
      until - the end index where to stop sorting (exclusively)
      comparator - the Comparator used to compare sequence elements. A null value indicates that the elements' Comparable natural ordering should be used
    • append

      public Array<T> append(Array<T> array)
      Return a new Array object with the given values appended.
      Parameters:
      array - the values to append
      Returns:
      a new Array object with the elements of this array and the given array appended.
      Throws:
      NullPointerException - if the given array is null
      Since:
      3.4
    • append

      public Array<T> append(Iterable<? extends T> values)
      Return a new Array with the given values appended.
      Parameters:
      values - the values to append
      Returns:
      a new Array with the elements of this array and the given values appended.
      Throws:
      NullPointerException - if the given values iterable is null
      Since:
      3.4
    • prepend

      public Array<T> prepend(Iterable<? extends T> values)
      Return a new Array with the given values prepended.
      Parameters:
      values - the values to prepend
      Returns:
      a new Array with the elements of this array and the given values appended.
      Throws:
      NullPointerException - if the given values iterable is null
      Since:
      3.4
    • copy

      public Array<T> copy()
      Return a copy of this array.
      Returns:
      a copy of this array
    • slice

      public Array<T> slice(int from)
      Return a new array slice starting with the from index.
      Parameters:
      from - the start index
      Returns:
      a new array slice
      Throws:
      ArrayIndexOutOfBoundsException - if the index is out of bounds.
    • slice

      public Array<T> slice(int from, int until)
      Return a new array slice starting with the from index and until index.
      Parameters:
      from - the start index
      until - the end index
      Returns:
      a new array slice
      Throws:
      ArrayIndexOutOfBoundsException - if the indexes are out of bounds.
    • checkIndex

      public void checkIndex(int index)
      Check the given array index
      Parameters:
      index - the index to check
      Throws:
      ArrayIndexOutOfBoundsException - if the given index is not in the valid range.
    • checkIndex

      public void checkIndex(int from, int until)
      Check the given from and until indices.
      Parameters:
      from - the from index, inclusively.
      until - the until index, exclusively.
      Throws:
      ArrayIndexOutOfBoundsException - if the given index is not in the valid range.
    • checkIndex

      public static void checkIndex(int from, int until, int size)
      Check the given from and until indices.
      Parameters:
      from - the from index, inclusively.
      until - the until index, exclusively.
      size - the array size
      Throws:
      ArrayIndexOutOfBoundsException - if the given index is not in the valid range.
    • of

      public static <T> Array<T> of(Array.Store<T> store)
      Create a new Array from the given object store.
      Type Parameters:
      T - the array type
      Parameters:
      store - the object store
      Returns:
      a new array with the given store
    • ofLength

      public static <T> Array<T> ofLength(int length)
      Create a new Array with the given length. The array is created with the default ObjectStore object.
      Type Parameters:
      T - the array type
      Parameters:
      length - the array length
      Returns:
      a new array with the given length