Class ArrayHelpers

java.lang.Object
org.symbol.sdk.utils.ArrayHelpers

public final class ArrayHelpers extends Object
ArrayHelpers
Helpers for reading / writing arrays of Serializer objects.
  • Method Details

    • size

      public static int size(List<? extends Serializer> elements, int alignment, boolean skipLastElementPadding)
      ArrayHelpers.size
      Calculates size of variable size objects.
      Parameters:
      elements - Serializable elements.
      alignment - Alignment used for calculations (0 means no alignment).
      skipLastElementPadding - true if last element should not be aligned.
      Returns:
      Computed size.
    • size

      public static int size(List<? extends Serializer> elements)
      ArrayHelpers.size
      Calculates size of variable size objects with default alignment of 0.
      Parameters:
      elements - Serializable elements.
      Returns:
      Computed size.
    • readArray

      public static <T extends Serializer> List<T> readArray(BufferView view, ArrayHelpers.Factory<T> factoryClass)
      ArrayHelpers.readArray
      Reads array of objects until the view's window is exhausted, without order verification.
      Type Parameters:
      T - Element type.
      Parameters:
      view - View positioned at the array, whose window bounds the read.
      factoryClass - Factory used to deserialize objects.
      Returns:
      Array of deserialized objects.
    • readArray

      public static <T extends Serializer> List<T> readArray(BufferView view, ArrayHelpers.Factory<T> factoryClass, Comparator<? super T> comparator)
      ArrayHelpers.readArray
      Reads array of objects until the view's window is exhausted, verifying strictly increasing element order.
      Type Parameters:
      T - Element type.
      Parameters:
      view - View positioned at the array, whose window bounds the read.
      factoryClass - Factory used to deserialize objects.
      comparator - Sort-key comparator enforcing element order; null skips the check.
      Returns:
      Array of deserialized objects.
    • readArrayCount

      public static <T extends Serializer> List<T> readArrayCount(BufferView view, ArrayHelpers.Factory<T> factoryClass, int count)
      ArrayHelpers.readArrayCount
      Reads array of a deterministic number of objects.
      Type Parameters:
      T - Element type.
      Parameters:
      view - View positioned at the array, whose window bounds the read.
      factoryClass - Factory used to deserialize objects.
      count - Number of objects to deserialize.
      Returns:
      Array of deserialized objects.
    • readArrayCount

      public static <T extends Serializer> List<T> readArrayCount(BufferView view, ArrayHelpers.Factory<T> factoryClass, int count, Comparator<? super T> comparator)
      ArrayHelpers.readArrayCount
      Reads array of a deterministic number of objects, verifying strictly increasing element order.
      Type Parameters:
      T - Element type.
      Parameters:
      view - View positioned at the array, whose window bounds the read.
      factoryClass - Factory used to deserialize objects.
      count - Number of objects to deserialize.
      comparator - Sort-key comparator enforcing element order; null skips the check.
      Returns:
      Array of deserialized objects.
      Throws:
      IndexOutOfBoundsException - if count is negative (e.g. a corrupt u32 count field that narrowed below zero).
    • readVariableSizeElements

      public static <T extends Serializer> List<T> readVariableSizeElements(BufferView view, ArrayHelpers.Factory<T> factoryClass, int alignment, boolean skipLastElementPadding)
      ArrayHelpers.readVariableSizeElements
      Reads array of variable size objects.
      Type Parameters:
      T - Element type.
      Parameters:
      view - View positioned at the array, whose window bounds the read.
      factoryClass - Factory used to deserialize objects.
      alignment - Alignment used to make sure each object is at boundary.
      skipLastElementPadding - true if last element is not aligned/padded.
      Returns:
      Array of deserialized objects.
    • writeArray

      public static <T extends Serializer> void writeArray(Writer output, List<T> elements)
      ArrayHelpers.writeArray
      Writes array of objects.
      Type Parameters:
      T - Element type.
      Parameters:
      output - Output sink.
      elements - Serializable elements.
    • writeArray

      public static <T extends Serializer> void writeArray(Writer output, List<T> elements, Comparator<? super T> comparator)
      ArrayHelpers.writeArray
      Writes array of objects, verifying strictly increasing element order.
      Type Parameters:
      T - Element type.
      Parameters:
      output - Output sink.
      elements - Serializable elements.
      comparator - Sort-key comparator enforcing element order; null skips the check.
    • writeVariableSizeElements

      public static <T extends Serializer> void writeVariableSizeElements(Writer output, List<T> elements, int alignment, boolean skipLastElementPadding)
      ArrayHelpers.writeVariableSizeElements
      Writes array of variable size objects.
      Type Parameters:
      T - Element type.
      Parameters:
      output - Output sink.
      elements - Serializable elements.
      alignment - Alignment used to make sure each object is at boundary.
      skipLastElementPadding - true if last element should not be aligned/padded.
    • writeVariableSizeElements

      public static <T extends Serializer> void writeVariableSizeElements(Writer output, List<T> elements, int alignment)
      ArrayHelpers.writeVariableSizeElements
      Writes array of variable size objects without skipping the last element's padding.
      Type Parameters:
      T - Element type.
      Parameters:
      output - Output sink.
      elements - Serializable elements.
      alignment - Alignment.
    • concat

      public static byte[] concat(byte[]... parts)
      ArrayHelpers.concat
      Concatenates byte arrays in order into a single new array.
      Parameters:
      parts - Byte arrays to concatenate, in order.
      Returns:
      New array holding every part end to end.
    • reverse

      public static byte[] reverse(byte[] input)
      ArrayHelpers.reverse
      Returns a new array with the bytes of input in reverse order (NEM reverses the private-key seed before ed25519 use).
      Parameters:
      input - Byte array to reverse.
      Returns:
      New reversed array.