public class MultiDimensionalArray<T> extends AbstractBasicMultiDimensionalArray<T>
There is no enforced limit to the number of dimensions,
but internally this is mapped to an ArrayList
,
which can only hold a limited number of elements.
indexLinearizer
Constructor and Description |
---|
MultiDimensionalArray(int... sizes)
Basic array constructor.
|
MultiDimensionalArray(MultiDimensionalArray<T> baseArray,
Function1<int[],int[]> indexConverter,
int... sizes)
Sub array constructor.
|
MultiDimensionalArray(MultiIndexLinearizer linearizer)
Basic array constructor.
|
Modifier and Type | Method and Description |
---|---|
T |
change(java.util.function.Function<? super T,? extends T> operator,
int... indexes)
Change the value located at the given indexes.
|
boolean |
equals(java.lang.Object o) |
MultiDimensionalArray<T> |
getCopy()
Get an independent copy.
|
<R> MultiDimensionalArray<R> |
getCopy(Function1<? extends R,? super T> mapper)
Get an independent copy with adapted element values.
|
T |
getElement(int... indexes)
Get the element at the given index combination.
|
int |
hashCode() |
void |
setElement(T elem,
int... indexes)
Set the element at the given index combination.
|
void |
setFrom(java.util.Collection<? extends T> elements)
Set all elements in this multi-dimensional array from the given collection.
|
MultiDimensionalArray<T> |
sub(int... indexes)
Get access to a multi-dimensional sub array of this array.
|
asLinearArray, asLinearArray, asLinearArray, asLinearArray, getIndexLinearizer, getNumDimensions, getNumElements, getSize, getSizes, iterator, iterator, setFrom, setFrom, toLinear, toList, toList, toList, toList
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
changeAll, changeAll, setAll, setFrom, setFrom
empty, linearized, visitAll, visitAll
public MultiDimensionalArray(int... sizes)
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
elementspublic MultiDimensionalArray(@NotNull MultiIndexLinearizer linearizer)
linearizer
- multi-index linearizer, defining dimensions and mappingspublic MultiDimensionalArray(@NotNull MultiDimensionalArray<T> baseArray, @NotNull Function1<int[],int[]> indexConverter, int... sizes)
This constructs a new read/write access to the given baseArray
allowing you to do nearly everything. As this gives a lot of power
be sure that the indexConverter
does "the right thing",
otherwise runtime exceptions will occur.
baseArray
- basic array to which accesses to this array are mappedindexConverter
- index converter which converts indexes into this array
to indexes into the basic array. Failing to fulfill
the restrictions (parameter length has to be
the same length as the following sizes
, and
fit into their range, and the result indexes have
to fit the restrictions of the baseArray
will result in runtime errorssizes
- sizes of the dimensions of this arraypublic T getElement(int... indexes)
indexes
- indexes of the elementpublic void setElement(T elem, int... indexes)
elem
- element to setindexes
- indexes of the elementpublic T change(@NotNull java.util.function.Function<? super T,? extends T> operator, int... indexes)
MultiDimensionalAccess
This default implementation is only slightly more efficient than
a get
and set
sequence,
but implementing classes are encouraged to provide better implementations
(e.g. the index linearization has only to happen once).
operator
- operator to apply to the value at the location defined by the given indexes.
When used on a specialized primitive type array the operator
will never receive null
, and must not return null
.
In other cases this depends on usage.indexes
- MultiDimensional.getNumDimensions()
indexes inside the bounds
defined by MultiDimensional.getSizes()
public void setFrom(@NotNull java.util.Collection<? extends T> elements)
AbstractBasicMultiDimensionalArray
MultiDimensionalAccess.setFrom(MultiIndexLinearizer.Sequencer, Collection)
with a high fast sequener
.setFrom
in class AbstractBasicMultiDimensionalArray<T>
elements
- array elements with at least AbstractBasicMultiDimensionalArray.getNumElements()
elements@NotNull public MultiDimensionalArray<T> sub(@NotNull int... indexes)
indexes
- indexes of sub array, negative for open indexes,
0
or positive for fixed indexes, if
there are not enough indexes the missing ones
are considered openpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
@NotNull public MultiDimensionalArray<T> getCopy()
@NotNull public <R> MultiDimensionalArray<R> getCopy(@NotNull Function1<? extends R,? super T> mapper)
R
- element type of copymapper
- mapper for value adaption