Class ArrayHelper

java.lang.Object
com.pixelmonmod.pixelmon.api.util.helpers.ArrayHelper

public class ArrayHelper extends Object
Helper methods when dealing with arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String[]
    addStringAtIndex(String[] array, int indexToAddAt, String value)
    Add a value at a certain spot in the index, shift everything after it one place further
    static <T> boolean
    arrayHasNull(T[] array)
    Checks if an array or any of its elements are null, or if the array is empty.
    static String
    concat(int start, String divider, String... strings)
    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.
    static List<String>
    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 delimiter
    static <T> void
    Validates that an array and its elements are non-null, and the array is not empty.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void encodeArray(net.minecraft.network.FriendlyByteBuf buffer, IEncodeable[] array)
      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

      public static void encodeStringArray(net.minecraft.network.FriendlyByteBuf buffer, String[] array)
      Encodes a string array into a buffer.
      Parameters:
      buffer - The buffer to encode the array into.
      array - The array to encode.
    • decodeStringList

      public static List<String> decodeStringList(net.minecraft.network.FriendlyByteBuf buffer)
      Reads a string list from a buffer.
      Parameters:
      buffer - The buffer to read from.
      Returns:
      The string list from the buffer.
    • decodeStringArray

      public static String[] decodeStringArray(net.minecraft.network.FriendlyByteBuf buffer)
      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

      public static String[] addStringAtIndex(String[] array, int indexToAddAt, String value)
      Add a value at a certain spot in the index, shift everything after it one place further
      Parameters:
      array - given array
      indexToAddAt - index where the value should be added
      value - 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 text
      texts - array of text
      Returns:
      a joined MutableComponent of the texts joined by the delimiter
    • concat

      public static String concat(int start, String divider, String... strings)
      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.