Class MultiDimensionalArray<T>

java.lang.Object
dev.nm.misc.datastructure.MultiDimensionalArray<T>
Type Parameters:
T - the type of data stored
All Implemented Interfaces:
MultiDimensionalCollection<T>

public class MultiDimensionalArray<T> extends Object implements MultiDimensionalCollection<T>
A generic multi-dimensional array, with an arbitrary number of dimensions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MultiDimensionalArray(int... sizes)
    Creates an instance with the specified size along each dimension.
    A copy constructor that constructs a shallow copy of the given collection of instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of dimensions of the collection.
    get(int... indices)
    Returns the element at the specified position in this collection.
    set(T value, int... indices)
    Replaces the element at the specified position in this list with the specified element.
    int
    size(int i)
    Returns the size of the collection along the given dimension.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MultiDimensionalArray

      public MultiDimensionalArray(int... sizes)
      Creates an instance with the specified size along each dimension.
      Parameters:
      sizes - the sizes of the dimensions
    • MultiDimensionalArray

      public MultiDimensionalArray(MultiDimensionalCollection<T> that)
      A copy constructor that constructs a shallow copy of the given collection of instances. That is, although the created array structure is independent of the input argument, the stored items are referencing the same collection of instances.
      Parameters:
      that - the collection to copy
  • Method Details

    • set

      public T set(T value, int... indices)
      Description copied from interface: MultiDimensionalCollection
      Replaces the element at the specified position in this list with the specified element.
      Specified by:
      set in interface MultiDimensionalCollection<T>
      Parameters:
      value - element to be stored at the specified position
      indices - the indices of the element to replace
    • get

      public T get(int... indices)
      Description copied from interface: MultiDimensionalCollection
      Returns the element at the specified position in this collection.
      Specified by:
      get in interface MultiDimensionalCollection<T>
      Parameters:
      indices - the indices of the element to return
      Returns:
      the element at the specified position in the list
    • size

      public int size(int i)
      Description copied from interface: MultiDimensionalCollection
      Returns the size of the collection along the given dimension.
      Specified by:
      size in interface MultiDimensionalCollection<T>
      Parameters:
      i - the index of the dimension for which to determine the size
      Returns:
      the size of the collection along the given dimension
    • dimension

      public int dimension()
      Description copied from interface: MultiDimensionalCollection
      Returns the number of dimensions of the collection.
      Specified by:
      dimension in interface MultiDimensionalCollection<T>
      Returns:
      the number of dimensions