Class ArrayHelper
java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.ArrayHelper
Helper methods when dealing with arrays.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String[]
addStringAtIndex
(String[] array, int indexToAddAt, String value) Add a value at a certain spot in the index, shift everything after it one place furtherstatic <T> boolean
arrayHasNull
(T[] array) Checks if an array or any of its elements are null, or if the array is empty.static String
Concatenate a string array with a specified start position and divider.static <T> boolean
contains
(T[] array, T value) Checks if an array contains a value.static String[]
decodeStringArray
(net.minecraft.network.FriendlyByteBuf buffer) Reads a string array from a buffer.decodeStringList
(net.minecraft.network.FriendlyByteBuf buffer) Reads a string list from a buffer.static boolean[][]
deepCopy
(boolean[][] array) static <T> T[][]
deepCopy
(T[][] array) static <T> T[][][]
deepCopy
(T[][][] array) static void
encodeArray
(net.minecraft.network.FriendlyByteBuf buffer, IEncodeable[] array) Encodes an array into a buffer.static void
encodeList
(net.minecraft.network.FriendlyByteBuf buffer, List<? extends IEncodeable> list) Encodes a list into a buffer.static void
encodeStringArray
(net.minecraft.network.FriendlyByteBuf buffer, String[] array) Encodes a string array into a buffer.static void
encodeStringList
(net.minecraft.network.FriendlyByteBuf buffer, List<String> list) Encodes a list into a buffer.static <T> int
indexOf
(T[] array, T object) static net.minecraft.network.chat.Component
join
(net.minecraft.network.chat.Component delimiter, net.minecraft.network.chat.Component... texts) Join an array of MutableComponent with a delimiterstatic <T> void
validateArrayNonNull
(T[] array) Validates that an array and its elements are non-null, and the array is not empty.
-
Constructor Details
-
ArrayHelper
public ArrayHelper()
-
-
Method Details
-
indexOf
public static <T> int indexOf(T[] array, T object) -
contains
public static <T> boolean contains(T[] array, T value) Checks if an array contains a value.- Parameters:
array
- The array to search for a value in.value
- The value to find in the array.- Returns:
- Whether the value is in the array.
-
arrayHasNull
public static <T> boolean arrayHasNull(T[] array) Checks if an array or any of its elements are null, or if the array is empty.- Parameters:
array
- The array to check.- Returns:
- Whether the array or any of its elements are null, or if the array is empty.
-
validateArrayNonNull
public static <T> void validateArrayNonNull(T[] array) Validates that an array and its elements are non-null, and the array is not empty.- Parameters:
array
- The array to check.- Throws:
IllegalArgumentException
- If the array validation fails.
-
encodeArray
Encodes an array into a buffer.- Parameters:
buffer
- The buffer to encode the array into.array
- The array to encode.
-
encodeList
public static void encodeList(net.minecraft.network.FriendlyByteBuf buffer, List<? extends IEncodeable> list) Encodes a list into a buffer.- Parameters:
buffer
- The buffer to encode the list into.list
- The list to encode.
-
encodeStringList
public static void encodeStringList(net.minecraft.network.FriendlyByteBuf buffer, List<String> list) Encodes a list into a buffer.- Parameters:
buffer
- The buffer to encode the list into.list
- The list to encode.
-
encodeStringArray
Encodes a string array into a buffer.- Parameters:
buffer
- The buffer to encode the array into.array
- The array to encode.
-
decodeStringList
Reads a string list from a buffer.- Parameters:
buffer
- The buffer to read from.- Returns:
- The string list from the buffer.
-
decodeStringArray
Reads a string array from a buffer.- Parameters:
buffer
- The buffer to read from.- Returns:
- The string array from the buffer.
-
deepCopy
public static boolean[][] deepCopy(boolean[][] array) -
deepCopy
public static <T> T[][] deepCopy(T[][] array) -
deepCopy
public static <T> T[][][] deepCopy(T[][][] array) -
addStringAtIndex
Add a value at a certain spot in the index, shift everything after it one place further- Parameters:
array
- given arrayindexToAddAt
- index where the value should be addedvalue
- to be added- Returns:
- the updated array with the value in the required index, everything after that shifted on place to the right.
-
join
public static net.minecraft.network.chat.Component join(net.minecraft.network.chat.Component delimiter, net.minecraft.network.chat.Component... texts) Join an array of MutableComponent with a delimiter- Parameters:
delimiter
- between each texttexts
- array of text- Returns:
- a joined MutableComponent of the texts joined by the delimiter
-
concat
Concatenate a string array with a specified start position and divider.- Parameters:
start
- Index in the array at where to begin concatenation.divider
- String to place between concatenated strings.strings
- The string array to concatenate.- Returns:
- The result of the concatenation.
-