de.caff.generics.mda

## Class AbstractBasicMultiDimensionalArray<T>

- java.lang.Object
- - de.caff.generics.mda.AbstractBasicMultiDimensionalArray<T>

- All Implemented Interfaces:
    MultiDimensional, MultiDimensionalAccess<T>, MultiDimensionalReadAccess<T>, java.lang.Iterable<T>
  Direct Known Subclasses:
    MultiDimensionalArray, MultiDimensionalBooleanArray, MultiDimensionalByteArray, MultiDimensionalCharArray, MultiDimensionalDoubleArray, MultiDimensionalFloatArray, MultiDimensionalIntArray, MultiDimensionalLongArray, MultiDimensionalShortArray

      public abstract class AbstractBasicMultiDimensionalArray<T>
      extends java.lang.Object
      implements MultiDimensionalAccess<T>, java.lang.Iterable<T>

  Basic implementation of a multi-dimensional array.
  Since:
    November 01, 2019
  Author:
    Rammi

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected MultiIndexLinearizer` | `indexLinearizer`

    - ### Fields inherited from interface de.caff.generics.mda.MultiDimensionalReadAccess

      `EMPTY0, EMPTY1, EMPTY2, EMPTY3, EMPTY4, EMPTY5, EMPTY6, EMPTY7`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractBasicMultiDimensionalArray(int... sizes)` Constructor.
    `protected` | `AbstractBasicMultiDimensionalArray(MultiIndexLinearizer linearizer)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Indexable<T>` | `asLinearArray()`
    `<R> Indexable<R>` | `asLinearArray(Function1<R,T> copier)`
    `Indexable<T>` | `asLinearArray(MultiIndexLinearizer.Sequencer sequencer)`
    `<R> Indexable<R>` | `asLinearArray(MultiIndexLinearizer.Sequencer sequencer, Function1<R,T> copier)` View this multi-dimensional array as a linear array.
    `MultiIndexLinearizer` | `getIndexLinearizer()` Get the multi-index linearizer on which this multi-dimensional array is based.
    `int` | `getNumDimensions()` Get the number of dimensions of this array
    `long` | `getNumElements()` Get the combined number of elements in all dimensions.
    `int` | `getSize(int dim)` Get the size of the given dimension.
    `int[]` | `getSizes()` Get the sizes of the dimensions of this array.
    `java.util.Iterator<T>` | `iterator()` Get an iterator over a linearized view of this multi-dimensional array.
    `java.util.Iterator<T>` | `iterator(MultiIndexLinearizer.Sequencer sequencer)` Get an iterator over a linearized view of this multi-dimensional array.
    `void` | `setFrom(java.util.Collection<? extends T> elements)` Set all elements in this multi-dimensional array from the given collection.
    `void` | `setFrom(java.lang.Iterable<? extends T> elements)` Set all elements in this multi-dimensional array in high-fast order.
    `void` | `setFrom(MultiIndexLinearizer.Sequencer sequencer, java.lang.Iterable<? extends T> elements)` Set all elements in this multi-dimensional array in the order defined by the sequencer.
    `protected int` | `toLinear(int... indexes)` Get the linear index for the given multi-dimensional indexes.
    `java.util.ArrayList<T>` | `toList()` Convert this multi-dimensional array into an array list.
    `<R> java.util.ArrayList<R>` | `toList(Function1<R,T> copier)` Convert this multi-dimensional array into an array list using a dedicated copier.
    `java.util.ArrayList<T>` | `toList(MultiIndexLinearizer.Sequencer sequencer)` Convert this multi-dimensional array into an array list.
    `<R> java.util.ArrayList<R>` | `toList(MultiIndexLinearizer.Sequencer sequencer, Function1<R,T> copier)` Convert this multi-dimensional array into an array list.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface de.caff.generics.mda.MultiDimensionalAccess

      `change, changeAll, changeAll, setAll, setElement, setFrom, setFrom`

    - ### Methods inherited from interface de.caff.generics.mda.MultiDimensionalReadAccess

      `empty, getElement, linearized, visitAll, visitAll`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

- - ### Field Detail

    - #### indexLinearizer

          @NotNull
          protected final MultiIndexLinearizer indexLinearizer

  - ### Constructor Detail

    - #### AbstractBasicMultiDimensionalArray

          protected AbstractBasicMultiDimensionalArray(int... sizes)

      Constructor.
      Parameters:
        `sizes` - of the dimensions of this array, e.g. `(2, 3, 4`} will create an oblong array with size 2 in the first, size 3 in the second, and size 4 in the third dimension, containing `2*3*4 = 24` elements

    - #### AbstractBasicMultiDimensionalArray

          protected AbstractBasicMultiDimensionalArray(@NotNull
                                                       MultiIndexLinearizer linearizer)

      Constructor.
      Parameters:
        `linearizer` - multi index linearizer

  - ### Method Detail

    - #### getIndexLinearizer

          @NotNull
          public MultiIndexLinearizer getIndexLinearizer()

      Get the multi-index linearizer on which this multi-dimensional array is based.

      Please note that the linearizer for

      Returns:
        multi-index linearizer

    - #### toLinear

          protected int toLinear(int... indexes)

      Get the linear index for the given multi-dimensional indexes.
      Parameters:
        `indexes` - indexes
      Returns:
        linear index

    - #### getNumDimensions

          public int getNumDimensions()

      Get the number of dimensions of this array
      Specified by:
        `getNumDimensions` in interface `MultiDimensional`
      Returns:
        number of dimensions of this array

    - #### getSize

          public int getSize(int dim)

      Get the size of the given dimension.
      Specified by:
        `getSize` in interface `MultiDimensional`
      Parameters:
        `dim` - dimension
      Returns:
        number of elements in the given dimension

    - #### getSizes

          @NotNull
          public int[] getSizes()

      Get the sizes of the dimensions of this array.
      Specified by:
        `getSizes` in interface `MultiDimensional`
      Returns:
        array of length `getNumDimensions()`

    - #### getNumElements

          public long getNumElements()

      Get the combined number of elements in all dimensions.
      Specified by:
        `getNumElements` in interface `MultiDimensional`
      Returns:
        number of all elements in this multi-dimensional array

    - #### iterator

          @NotNull
          public java.util.Iterator<T> iterator()

      Get an iterator over a linearized view of this multi-dimensional array. This forwards to `iterator(MultiIndexLinearizer.Sequencer)` with a `high fast sequener`.
      Specified by:
        `iterator` in interface `java.lang.Iterable<T>`
      Returns:
        iterator

    - #### iterator

          @NotNull
          public java.util.Iterator<T> iterator(@NotNull
                                                         MultiIndexLinearizer.Sequencer sequencer)

      Get an iterator over a linearized view of this multi-dimensional array.
      Parameters:
        `sequencer` - sequencer to use for iterating over this multi-dimensional array, must provide the same dimensions
      Returns:
        linear iterator over this multi-dimensional array

    - #### setFrom

          public void setFrom(@NotNull
                              java.util.Collection<? extends T> elements)

      Set all elements in this multi-dimensional array from the given collection. This forwards to `MultiDimensionalAccess.setFrom(MultiIndexLinearizer.Sequencer, Collection)` with a `high fast sequener`.
      Parameters:
        `elements` - array elements with at least `getNumElements()` elements

    - #### setFrom

          public void setFrom(@NotNull
                              java.lang.Iterable<? extends T> elements)

      Set all elements in this multi-dimensional array in high-fast order.
      Parameters:
        `elements` - elements in order, at least `getNumElements()`
      Throws:
        `java.lang.IllegalArgumentException` - if there are not enough elements in the iterable

    - #### setFrom

          public void setFrom(@NotNull
                              MultiIndexLinearizer.Sequencer sequencer,
                              @NotNull
                              java.lang.Iterable<? extends T> elements)

      Set all elements in this multi-dimensional array in the order defined by the sequencer.
      Specified by:
        `setFrom` in interface `MultiDimensionalAccess<T>`
      Parameters:
        `sequencer` - sequencer defining the order in which elements are set
        `elements` - elements in order, at least `getNumElements()`
      Throws:
        `java.lang.IllegalArgumentException` - if there are not enough elements in the iterable

    - #### asLinearArray

          @NotNull
          public Indexable<T> asLinearArray()

    - #### asLinearArray

          @NotNull
          public Indexable<T> asLinearArray(@NotNull
                                                     MultiIndexLinearizer.Sequencer sequencer)

    - #### asLinearArray

          @NotNull
          public <R> Indexable<R> asLinearArray(@NotNull
                                                         Function1<R,T> copier)

    - #### asLinearArray

          @NotNull
          public <R> Indexable<R> asLinearArray(@NotNull
                                                         MultiIndexLinearizer.Sequencer sequencer,
                                                         @NotNull
                                                         Function1<R,T> copier)

      View this multi-dimensional array as a linear array. This method allows to define the order of elements in the returned array and how elements are copied over when accessed.
      Type Parameters:
        `R` - result array element type
      Parameters:
        `sequencer` - sequencer defining the element order, its dimensional setup has to fit this multi-dimensional array setup
        `copier` - copier used to copy over elements from this multi-dimensional array when requested
      Returns:
        newly created indexed array in the given order

    - #### toList

          @NotNull
          public java.util.ArrayList<T> toList()

      Convert this multi-dimensional array into an array list.
      Returns:
        newly created list in `high fast order` with elements copied directly

    - #### toList

          @NotNull
          public <R> java.util.ArrayList<R> toList(@NotNull
                                                            Function1<R,T> copier)

      Convert this multi-dimensional array into an array list using a dedicated copier.
      Type Parameters:
        `R` - result list element type
      Parameters:
        `copier` - copier used to copy over elements from this multi-dimensional array to the returned list
      Returns:
        newly created array list in `high fast order`

    - #### toList

          @NotNull
          public java.util.ArrayList<T> toList(@NotNull
                                                        MultiIndexLinearizer.Sequencer sequencer)

      Convert this multi-dimensional array into an array list. This method allows to define the order of elements in the list.
      Parameters:
        `sequencer` - sequencer defining the element order, its dimensional setup has to fit this multi-dimensional array setup
      Returns:
        newly created list in the given order with elements copied directly

    - #### toList

          @NotNull
          public <R> java.util.ArrayList<R> toList(@NotNull
                                                            MultiIndexLinearizer.Sequencer sequencer,
                                                            @NotNull
                                                            Function1<R,T> copier)

      Convert this multi-dimensional array into an array list. This method allows to define the order of elements in the returned list and how elements are copied over.
      Type Parameters:
        `R` - result list element type
      Parameters:
        `sequencer` - sequencer defining the element order, its dimensional setup has to fit this multi-dimensional array setup
        `copier` - copier used to copy over elements from this multi-dimensional array to the returned list
      Returns:
        newly created array list in the given order with copied elements