Package org.symbol.sdk.utils
Class ArrayHelpers
java.lang.Object
org.symbol.sdk.utils.ArrayHelpers
- ArrayHelpers
- Helpers for reading / writing arrays of
Serializerobjects.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceArrayHelpers.Factory<T extends Serializer>Factory used to deserialize objects from a byte slice. -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]concat(byte[]... parts) Concatenates byte arrays in order into a single new array.static <T extends Serializer>
List<T> readArray(BufferView view, ArrayHelpers.Factory<T> factoryClass) Reads array of objects until the view's window is exhausted, without order verification.static <T extends Serializer>
List<T> readArray(BufferView view, ArrayHelpers.Factory<T> factoryClass, Comparator<? super T> comparator) Reads array of objects until the view's window is exhausted, verifying strictly increasing element order.static <T extends Serializer>
List<T> readArrayCount(BufferView view, ArrayHelpers.Factory<T> factoryClass, int count) Reads array of a deterministic number of objects.static <T extends Serializer>
List<T> readArrayCount(BufferView view, ArrayHelpers.Factory<T> factoryClass, int count, Comparator<? super T> comparator) Reads array of a deterministic number of objects, verifying strictly increasing element order.static <T extends Serializer>
List<T> readVariableSizeElements(BufferView view, ArrayHelpers.Factory<T> factoryClass, int alignment, boolean skipLastElementPadding) Reads array of variable size objects.static byte[]reverse(byte[] input) Returns a new array with the bytes ofinputin reverse order (NEM reverses the private-key seed before ed25519 use).static intsize(List<? extends Serializer> elements) Calculates size of variable size objects with default alignment of 0.static intsize(List<? extends Serializer> elements, int alignment, boolean skipLastElementPadding) Calculates size of variable size objects.static <T extends Serializer>
voidwriteArray(Writer output, List<T> elements) Writes array of objects.static <T extends Serializer>
voidwriteArray(Writer output, List<T> elements, Comparator<? super T> comparator) Writes array of objects, verifying strictly increasing element order.static <T extends Serializer>
voidwriteVariableSizeElements(Writer output, List<T> elements, int alignment) Writes array of variable size objects without skipping the last element's padding.static <T extends Serializer>
voidwriteVariableSizeElements(Writer output, List<T> elements, int alignment, boolean skipLastElementPadding) Writes array of variable size 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-trueif last element should not be aligned.- Returns:
- Computed size.
-
size
- 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;nullskips 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;nullskips the check.- Returns:
- Array of deserialized objects.
- Throws:
IndexOutOfBoundsException- ifcountis 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-trueif last element is not aligned/padded.- Returns:
- Array of deserialized objects.
-
writeArray
- 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;nullskips 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-trueif 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
inputin reverse order (NEM reverses the private-key seed before ed25519 use).
- Parameters:
input- Byte array to reverse.- Returns:
- New reversed array.
-