Package dev.nm.misc.datastructure
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.MultiDimensionalArray(MultiDimensionalCollection<T> that)
A copy constructor that constructs a shallow copy of the given collection of instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
dimension()
Returns the number of dimensions of the collection.T
get(int... indices)
Returns the element at the specified position in this collection.T
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.
-
-
-
Constructor Detail
-
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 Detail
-
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 interfaceMultiDimensionalCollection<T>
- Parameters:
value
- element to be stored at the specified positionindices
- 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 interfaceMultiDimensionalCollection<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 interfaceMultiDimensionalCollection<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 interfaceMultiDimensionalCollection<T>
- Returns:
- the number of dimensions
-
-