public class MultiDimensionArrayUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
MultiDimensionArrayUtils.ArrayIterator<T> |
| Constructor and Description |
|---|
MultiDimensionArrayUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Class<?> |
arrayClassOf(Class<?> clazz,
int dimensions)
Returns a equivalent Class object that is an array Class with the given dimensions.
|
static <R> MultiDimensionArrayUtils.ArrayIterator<R> |
arrayIterator(Object array,
int[] dimLens)
arrayIterator.
|
static boolean |
checkValueAgainstInstrumentRange(Variant variantValue,
Range range,
NodeId dataTypeId)
Checks if the value of a Variant is within the InstrumentRange of target UaValueNode.
|
static Object |
clone(Object array)
Clones the multi-dimension structure of an array but the not the individual elements.
|
static Object[] |
createMultiDimArray(Class<?> componentType,
int[] dims)
Deep create multi-level array.
|
static <T,E extends Exception> |
createMultiDimArray(Class<T> componentType,
int[] dims,
CheckedFunction<int[],T,E> generator)
Deep create multi-level array.
|
static Object |
deepClone(Object array)
Deep clone structure and elements.
|
static <E extends Exception> |
deepForEach(Object data,
CheckedConsumer<Object,E> operation)
Similar to
#forEachIndexed(Object, Class, CheckedConsumer), but the given operation is
recursively called for elements of data that are arrays (it is not called for the "intermediate
array objects"). |
static Object |
deepGet(Object array,
int... selector)
Selects a part of an array and returns it.
|
static Object |
deepGet(Object array,
List<Integer> selector)
Selects a part of an array and returns it.
|
static void |
deepSet(Object array,
Object newValue,
int... selector)
Sets a value to a multidimensional array for the selected index.
|
static void |
deepSet(Object array,
Object newValue,
List<Integer> selector)
Sets a value to a multidimensional array for the selected index.
|
static Object |
demuxArray(Object src,
int[] dims)
Demux single-dimension array (x[]) to a multi-dimension array (x[][][]).
|
static Object |
demuxArray(Object src,
int[] dims,
Class<?> componentType)
Demux single-dimension array (x[]) to a multi-dimension array (x[][][]).
|
static void |
demuxArray(Object src,
int[] dims,
Object dst)
Demuxes single dimension array into a multi-dimension array.
|
static <T,E extends Exception> |
forEach(Object data,
Class<T> componentClass,
CheckedConsumer<T,E> operation)
Applies the given operation for each "element" of the data.
|
static <T,E extends Exception> |
forEachIndexed(Object data,
Class<T> componentClass,
CheckedBiConsumer<T,int[],E> operation)
Same as
forEach(Object, Class, CheckedConsumer) , but additionally provides the
indexes of the given element. |
static int[] |
getArrayLengths(Object value)
Get array length of each dimension of a multi-dimension array.
|
static int |
getClassDimensions(Class<?> clazz)
Get the number of dimensions the class has.
|
static <T extends Cloneable> |
getCloneMethod(Class<T> clazz)
Returns
Method for the given class that can be used to call clone via reflection. |
static Class<?> |
getComponentType(Class<?> clazz)
Get the component type of an array class.
|
static int |
getDimension(Object value)
Get the number of dimensions in a multi-dimension array.
|
static int |
getLength(int[] dims)
Returns the total number of elements in a multi-dimension array.
|
static <S,T,E extends Exception> |
map(Object data,
Class<S> sourceComponentClass,
Class<T> targetComponentClass,
CheckedFunction<? super S,? extends T,E> transformer)
Converts the given data with the given transformer and returns the output, that is of the same
dimension.
|
static <S,T,E extends Exception> |
mapIndexed(Object data,
Class<S> sourceComponentClass,
Class<T> targetComponentClass,
CheckedBiFunction<? super S,int[],? extends T,E> transformer)
Same as
map(Object, Class, Class, CheckedFunction), but additionally provides the
indexes of the given element to map. |
static Object |
muxArray(Object src)
Multiplex multi-dimension array (x[][][]) to single-dimension array (x[]).
|
static Object |
muxArray(Object src,
int[] dims)
Multiplex multi-dimension array (x[][][]) to single-dimension array (x[]).
|
static Object |
muxArray(Object src,
int[] dims,
Class<?> componentType)
Multiplex multi-dimension array (x[][][]) to single-dimension array (x[]).
|
static void |
muxArray(Object src,
int[] dims,
Object dst)
Multiplexes multi-dimension array into a single-dimension array.
|
static void |
printArrayDeep(Object value,
PrintStream out)
Print multi-dimension array.
|
static <T,E extends Exception> |
replaceAll(Object data,
Class<T> componentClass,
CheckedBiFunction<T,int[],T,E> transformer)
Replaces in-place all elements in the given array (of any dimension) using the given
transformer.
|
static <T,E extends Exception> |
resize(Object array,
Class<T> componentType,
int[] newDimensions)
Returns a new array with the given dimensions.
|
static <T,E extends Exception> |
resize(Object array,
Class<T> componentType,
int[] newDimensions,
CheckedFunction<int[],T,E> generator)
Returns a new array with the given dimensions.
|
static <T,E extends Exception> |
setAll(Object data,
Class<T> componentClass,
CheckedFunction<int[],T,E> generator)
Sets all elements of the given array (of any dimension) using the given generator function to
compute each element.
|
static String |
toString(Object object)
Format object to String.
|
static String |
toString(Object object,
EncoderContext ctx)
Format object to String, try decoding
ExtensionObjects with the given context. |
public static Class<?> arrayClassOf(Class<?> clazz, int dimensions)
clazz - class to make array Class variant out ofdimensions - the number of dimensions the class will haveIllegalArgumentException - if given negative dimensionspublic static <R> MultiDimensionArrayUtils.ArrayIterator<R> arrayIterator(Object array, int[] dimLens)
arrayIterator.
R - a R object.array - a Object object.dimLens - an array of int.MultiDimensionArrayUtils.ArrayIterator object.public static boolean checkValueAgainstInstrumentRange(Variant variantValue, Range range, NodeId dataTypeId)
variantValue - the new valuerange - the InstrumentRangevalueNode - the target UaValueNodepublic static Object clone(Object array)
array - a Object object.public static Object[] createMultiDimArray(Class<?> componentType, int[] dims)
componentType - component typedims - dimension lengthspublic static <T,E extends Exception> Object[] createMultiDimArray(Class<T> componentType, int[] dims, CheckedFunction<int[],T,E> generator) throws E extends Exception
MultiDimensionArrayUtils.ArrayIterator.getIndices()).componentType - component typedims - dimension lengthsE extends Exceptionpublic static Object deepClone(Object array)
public static <E extends Exception> void deepForEach(Object data, CheckedConsumer<Object,E> operation) throws E extends Exception
#forEachIndexed(Object, Class, CheckedConsumer), but the given operation is
recursively called for elements of data that are arrays (it is not called for the "intermediate
array objects"). Throws any exception thrown by the given operation. The results are undefined
if the array refers itself in any element.E extends Exceptionpublic static Object deepGet(Object array, int... selector)
public static Object deepGet(Object array, List<Integer> selector)
deepGet(Object, int...) for an example.public static void deepSet(Object array, Object newValue, int... selector)
public static void deepSet(Object array, Object newValue, List<Integer> selector)
deepSet(Object, Object, int...) for an example.public static Object demuxArray(Object src, int[] dims)
src - single-dimension arraydims - an array of int.public static Object demuxArray(Object src, int[] dims, Class<?> componentType)
src - single-dimension arraydims - an array of int.componentType - a Class object.public static void demuxArray(Object src, int[] dims, Object dst)
src - one dimension array (e.g. int[])dims - length of each dimensiondst - multi-dimension array to be filled (use createMultiDimArray())public static <T,E extends Exception> void forEach(Object data, Class<T> componentClass, CheckedConsumer<T,E> operation) throws E extends Exception
IllegalArgumentException if the given data elements
cannot be casted to the given component class.T - Component type.E - Exception (if any) thrown by the operationdata - Scalar or anydimensional array to whose elements the operation is appliedcomponentClass - class of the components i.e. elements of the arrayoperation - The operation to perform for each element. The second parameter is the
position of the element (see MultiDimensionArrayUtils.ArrayIterator.getIndices(); for scalar data this is
an empty array).E - Throws if the operation throws.E extends Exceptionpublic static <T,E extends Exception> void forEachIndexed(Object data, Class<T> componentClass, CheckedBiConsumer<T,int[],E> operation) throws E extends Exception
forEach(Object, Class, CheckedConsumer) , but additionally provides the
indexes of the given element. Scalar (non-null) inputs receive empty int[] array.E extends Exceptionpublic static int[] getArrayLengths(Object value)
value - multi-dimension arraypublic static int getClassDimensions(Class<?> clazz)
public static <T extends Cloneable> Method getCloneMethod(Class<T> clazz) throws Exception
Method for the given class that can be used to call clone via reflection. Note
that this method is mainly intended for SDK internal use (public due to uses from multiple
packages) and may change in the future. Returns cached results for subsequent calls per Class
(cleared on StackUtils.shutdown()). Throws if the method is not found (which in general
should be a coding mistake as every Cloneable should have public clone method).Exceptionpublic static Class<?> getComponentType(Class<?> clazz)
clazz - (array) classpublic static int getDimension(Object value)
value - multi-dimension arraypublic static int getLength(int[] dims)
dims - lengths of each dimensionpublic static <S,T,E extends Exception> Object map(Object data, Class<S> sourceComponentClass, Class<T> targetComponentClass, CheckedFunction<? super S,? extends T,E> transformer) throws E extends Exception
IllegalArgumentException if mapping fails (also throws anything the given
transformer throws). The return for non-null data will be of the targetComponentClass having
the same dimensions as the given data.E extends Exceptionpublic static <S,T,E extends Exception> Object mapIndexed(Object data, Class<S> sourceComponentClass, Class<T> targetComponentClass, CheckedBiFunction<? super S,int[],? extends T,E> transformer) throws E extends Exception
map(Object, Class, Class, CheckedFunction), but additionally provides the
indexes of the given element to map. Scalar transformation use an empty array as the indexes.E extends Exceptionpublic static Object muxArray(Object src)
src - multi-dimension arraypublic static Object muxArray(Object src, int[] dims)
src - multi-dimension arraydims - an array of int.public static Object muxArray(Object src, int[] dims, Class<?> componentType)
src - multi-dimension arraydims - an array of int.componentType - a Class object.public static void muxArray(Object src, int[] dims, Object dst)
src - multi-dimension arraydims - dimensionsdst - single-dimension arraypublic static void printArrayDeep(Object value, PrintStream out)
value - a Object object.out - output streampublic static <T,E extends Exception> void replaceAll(Object data, Class<T> componentClass, CheckedBiFunction<T,int[],T,E> transformer) throws E extends Exception
MultiDimensionArrayUtils.ArrayIterator.getIndices()). Throws if the given transformer throws.E extends Exceptionpublic static <T,E extends Exception> Object resize(Object array, Class<T> componentType, int[] newDimensions)
If the new dimensions are smaller than the old dimensions, the data from the old array is truncated, only data from the index [0][0]... (repeated for the difference in dimensions) is used. Conversely, if the new dimensions are larger than the old dimensions, the old data indexes are treated as-if prefixed with [0][0]... (repeated for the difference in dimensions).
T - Expected element type.E - Exception (if any) type thrown by the given generator.array - the original array to clone. The dimensions shall be rectangular, i.e. the array
must be representable as array[][]....[] with known size for all dimensions. Shall not
be be an array of primitives.componentType - element Class the array has.newDimensions - the dimensions of the array to return.E - any exception thrown from the generatorpublic static <T,E extends Exception> Object resize(Object array, Class<T> componentType, int[] newDimensions, CheckedFunction<int[],T,E> generator) throws E extends Exception
If the new dimensions are smaller than the old dimensions, the data from the old array is truncated, only data from the index [0][0]... (repeated for the difference in dimensions) is used. Conversely, if the new dimensions are larger than the old dimensions, the old data indexes are treated as-if prefixed with [0][0]... (repeated for the difference in dimensions).
T - Expected element type.E - Exception (if any) type thrown by the given generator.array - the original array to clone. The dimensions shall be rectangular, i.e. the array
must be representable as array[][]....[] with known size for all dimensions. Shall not
be be an array of primitives.componentType - element Class the array has.newDimensions - the dimensions of the array to return.generator - Generator function to initialize new elements, the input is the position in
the array (see MultiDimensionArrayUtils.ArrayIterator.getIndices()).E - any exception thrown from the generatorE extends Exceptionpublic static <T,E extends Exception> void setAll(Object data, Class<T> componentClass, CheckedFunction<int[],T,E> generator) throws E extends Exception
replaceAll(Object, Class, CheckedBiFunction) instead.E extends Exceptionpublic static String toString(Object object)
toString(Object, EncoderContext) for that).object - a Object object.public static String toString(Object object, EncoderContext ctx)
ExtensionObjects with the given context. Uses
ExtensionObject.toString() if decoding fails.object - the objectctx - context to use for ExtensionObject decoding, can be null, in which case no
decoding is attemptedCopyright © 2026. All rights reserved.