de.caff.generics.mda

## Class TwoDimensionalArray<T>

- java.lang.Object
- - de.caff.generics.mda.TwoDimensionalReadAccess.Base<T>
  - - de.caff.generics.mda.TwoDimensionalArray<T>

- All Implemented Interfaces:
    MultiDimensional, MultiDimensionalAccess<T>, MultiDimensionalReadAccess<T>, TwoDimensionalAccess<T>, TwoDimensionalReadAccess<T>

      public class TwoDimensionalArray<T>
      extends TwoDimensionalReadAccess.Base<T>
      implements TwoDimensionalAccess<T>

  Since:
    November 11, 2019
  Author:
    Rammi

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface de.caff.generics.mda.TwoDimensionalReadAccess

      `TwoDimensionalReadAccess.Base<TT>`

  - ### Field Summary

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

      `EMPTY`

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

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TwoDimensionalArray(int sy, java.util.Collection<T> elements)` Constructor.
    `TwoDimensionalArray(int sy, Indexable<T> elements)` Constructor.
    `TwoDimensionalArray(int sx, int sy)` Constructor.
    `TwoDimensionalArray(int sx, int sy, IntFunction2<? extends T> filler)` Initializing constructor.
    `TwoDimensionalArray(int sx, int sy, java.lang.Iterable<T> elements)` Constructor.
    `TwoDimensionalArray(int sy, T... elements)` Constructor.
    `TwoDimensionalArray(java.util.function.Supplier<? extends T> supplier, int sx, int sy)` Constructor.
    `TwoDimensionalArray(TwoDimensionalReadAccess<T> source)` Copy constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `<R> TwoDimensionalArray<R>` | `getCopy(java.util.function.Function<? super T,? extends R> copier)` Get an independent copy with a possibly different element type.
    `T` | `getElementAt(int ix, int iy)` Get the element at the given indexes.
    `TwoDimensionalArray<T>` | `resized(int sx, int sy)` Get a resized copy of this array which contains the same elements for equal indexes.
    `<R> TwoDimensionalArray<R>` | `resized(int sx, int sy, java.util.function.Function<? super T,? extends R> copier, IntFunction2<? extends R> filler)` Get a resized copy of this array.
    `TwoDimensionalArray<T>` | `resized(int sx, int sy, IntFunction2<? extends T> filler)` Get a resized copy of this array.
    `void` | `setElementAt(T element, int ix, int iy)` Set the element at the given indexes.
    `int` | `sizeX()` Get the number of elements in X direction.
    `int` | `sizeY()` Get the number of elements in Y direction

    - ### Methods inherited from class de.caff.generics.mda.TwoDimensionalReadAccess.Base

      `asBase, equals, hashCode, toString`

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

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

      `changeAll, changeAll, createConstant, createIndexed, createNulled, createSupplied, empty, fillByIndex, setElement, subAtX, subAtY, transposed, zeroX, zeroY`

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

      `asBase, equal, getElement, getNumDimensions, getNumElements, getSize, getSizes, hash, singleton, toString, view, visitAll, visitAll, xIterable, xIterator, yIterable, yIterator`

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

      `change, setAll, setFrom, setFrom, setFrom`

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

      `empty, linearized`

- - ### Constructor Detail

    - #### TwoDimensionalArray

          public TwoDimensionalArray(int sx,
                                     int sy)

      Constructor. This will init all cells with `null`.
      Parameters:
        `sx` - size in X direction (at least `1`)
        `sy` - size in Y direction (at least `1`)
      See Also:
        `TwoDimensionalArray(int, int, IntFunction2)`

    - #### TwoDimensionalArray

          public TwoDimensionalArray(int sx,
                                     int sy,
                                     @NotNull
                                     IntFunction2<? extends T> filler)

      Initializing constructor.
      Parameters:
        `sx` - size in X direction (at least `1`)
        `sy` - size in Y direction (at least `1`)
        `filler` - function called with all index combinations (x,y)

    - #### TwoDimensionalArray

          public TwoDimensionalArray(@NotNull
                                     java.util.function.Supplier<? extends T> supplier,
                                     int sx,
                                     int sy)

      Constructor. This will call the `supplier` for each cell and fill it with the result.
      Parameters:
        `sx` - size in X direction (at least `1`)
        `sy` - size in Y direction (at least `1`)
        `supplier` - supplier for cell content

    - #### TwoDimensionalArray

          @SafeVarargs
          public TwoDimensionalArray(int sy,
                                                  T... elements)

      Constructor.
      Parameters:
        `sy` - size in Y direction (at least `1`)
        `elements` - `sx * sy` elements

    - #### TwoDimensionalArray

          public TwoDimensionalArray(int sy,
                                     @NotNull
                                     java.util.Collection<T> elements)

      Constructor.
      Parameters:
        `sy` - size in Y direction (at least `1`)
        `elements` - `sx * sy` elements

    - #### TwoDimensionalArray

          public TwoDimensionalArray(int sy,
                                     @NotNull
                                     Indexable<T> elements)

      Constructor.
      Parameters:
        `sy` - size in Y direction (at least `1`)
        `elements` - `sx * sy` elements

    - #### TwoDimensionalArray

          public TwoDimensionalArray(int sx,
                                     int sy,
                                     @NotNull
                                     java.lang.Iterable<T> elements)

      Constructor.
      Parameters:
        `sx` - size in X direction (at least `1`)
        `sy` - size in Y direction (at least `1`)
        `elements` - at least `sx * sy` elements

    - #### TwoDimensionalArray

          public TwoDimensionalArray(@NotNull
                                     TwoDimensionalReadAccess<T> source)

      Copy constructor.
      Parameters:
        `source` - source access

  - ### Method Detail

    - #### setElementAt

          public void setElementAt(T element,
                                   int ix,
                                   int iy)

      Description copied from interface: `TwoDimensionalAccess`
      Set the element at the given indexes.
      Specified by:
        `setElementAt` in interface `TwoDimensionalAccess<T>`
      Parameters:
        `element` - element to set
        `ix` - index in X direction from `0` (included) to `TwoDimensionalReadAccess.sizeX()` (excluded)
        `iy` - index in Y direction from `0` (included) to `TwoDimensionalReadAccess.sizeY()` (excluded)

    - #### sizeX

          public int sizeX()

      Description copied from interface: `TwoDimensionalReadAccess`
      Get the number of elements in X direction.
      Specified by:
        `sizeX` in interface `TwoDimensionalReadAccess<T>`
      Returns:
        number of elements in X direction

    - #### sizeY

          public int sizeY()

      Description copied from interface: `TwoDimensionalReadAccess`
      Get the number of elements in Y direction
      Specified by:
        `sizeY` in interface `TwoDimensionalReadAccess<T>`
      Returns:
        number of elements in Y direction

    - #### getElementAt

          public T getElementAt(int ix,
                                int iy)

      Description copied from interface: `TwoDimensionalReadAccess`
      Get the element at the given indexes.
      Specified by:
        `getElementAt` in interface `TwoDimensionalReadAccess<T>`
      Parameters:
        `ix` - index in X direction from `0` (included) to `TwoDimensionalReadAccess.sizeX()` (excluded)
        `iy` - index in Y direction from `0` (included) to `TwoDimensionalReadAccess.sizeY()` (excluded)
      Returns:
        element at the given indexes

    - #### getCopy

          @NotNull
          public <R> TwoDimensionalArray<R> getCopy(@NotNull
                                                             java.util.function.Function<? super T,? extends R> copier)

      Get an independent copy with a possibly different element type.
      Type Parameters:
        `R` - target element type
      Parameters:
        `copier` - copier which copies elements from this 2dimensional array to the result array.
      Returns:
        2dimensional array with same size but copied elements

    - #### resized

          @NotNull
          public TwoDimensionalArray<T> resized(int sx,
                                                         int sy)

      Get a resized copy of this array which contains the same elements for equal indexes.
      Parameters:
        `sx` - new size in X direction
        `sy` - new size in Y direction
      Returns:
        resized copy of this 2D array where newly created cells are filled with `null`

    - #### resized

          @NotNull
          public TwoDimensionalArray<T> resized(int sx,
                                                         int sy,
                                                         @Nullable
                                                         IntFunction2<? extends T> filler)

      Get a resized copy of this array.
      Parameters:
        `sx` - new size in X direction
        `sy` - new size in Y direction
        `filler` - filler for newly created cells, use `null` to leave them empty
      Returns:
        resized copy of this 2D array

    - #### resized

          @NotNull
          public <R> TwoDimensionalArray<R> resized(int sx,
                                                             int sy,
                                                             @NotNull
                                                             java.util.function.Function<? super T,? extends R> copier,
                                                             @Nullable
                                                             IntFunction2<? extends R> filler)

      Get a resized copy of this array. This will copy elements from this array to the same position in the new array, and fill any elements in the new array whcih have no counterpart in this array.
      Type Parameters:
        `R` - possibly different type of resulting array
      Parameters:
        `sx` - new size in X direction
        `sy` - new size in Y direction
        `copier` - function which copies elements
        `filler` - filler for newly created cells, use `null` to leave them empty
      Returns:
        resized independent copy of this 2D array