java.lang.Object
org.eclipse.milo.opcua.stack.core.util.ArrayUtil

public class ArrayUtil extends Object
  • Constructor Details

    • ArrayUtil

      public ArrayUtil()
  • Method Details

    • flatten

      public static Object flatten(Object array)
      Flatten a multi-dimensional array into a one-dimensional array.
      Parameters:
      array - the array to flatten.
      Returns:
      a 1-dimensional array.
    • unflatten

      public static Object unflatten(Object array, int[] dimensions)
      Un-flatten a one-dimensional array into an multi-dimensional array based on the provided dimensions.
      Parameters:
      array - the 1-dimensional array to un-flatten.
      dimensions - the dimensions to un-flatten to.
      Returns:
      a multi-dimensional array of the provided dimensions.
    • getDimensions

      public static int[] getDimensions(Object array)
    • getValueRank

      public static int getValueRank(Object array)
      Get the ValueRank of an Object that may or may not be an array.

      The return value is either -1 (scalar) or the number of dimensions (>=1).

      Parameters:
      array - the Object to check.
      Returns:
      the ValueRank of the object.
    • getType

      public static Class<?> getType(Object array)
      Get the base component type for the provided array.
      Parameters:
      array - the array whose base component type is to be determined.
      Returns:
      the Class object representing the base component type of the array.
    • getBoxedType

      public static Class<?> getBoxedType(Object array)
      Get the (boxed) base component type for the provided array.
      Parameters:
      array - the array whose (boxed) base component type is to be determined.
      Returns:
      the Class object representing the (boxed) base component type of the array.
    • box

      public static Object box(Object value)
      If the provided Object is a primitive array, return a boxed array of the same type, otherwise return the original Object.
      Parameters:
      value - the array to box.
      Returns:
      a boxed array of the same type, or the original Object if it is not a primitive array.
    • transformArray

      public static <F, T> Object transformArray(Object array, Function<F,T> transform, Class<T> toType)
      Transform the values in an array from one type to another using a transformation function.

      Handles multi-dimensional arrays by flattening before the transformation and un-flattening afterwards.

      Parameters:
      array - the original array.
      transform - a function that transforms from F to T.
      toType - the destination type.
      Returns:
      a new array of the same size and dimensions with all elements transformed from F to T using transform.