Class StringUtils

java.lang.Object
me.hsgamer.hscore.common.StringUtils

public final class StringUtils extends Object
Methods for String
  • Method Details

    • replacePattern

      public static String replacePattern(@NotNull @NotNull String input, @NotNull @NotNull Pattern pattern, @NotNull @NotNull Function<@NotNull Matcher,@Nullable String> replacementFunction)
      Replace the string given the pattern and the replacement function
      Parameters:
      input - the input string
      pattern - the pattern
      replacementFunction - the replacement function
      Returns:
      the replaced string
    • replaceChar

      @NotNull public static @NotNull String replaceChar(char altChar, char finalChar, @NotNull @NotNull String input, @NotNull @NotNull Map<Character,Supplier<Character>> charMappers)
      Replace all alternative character format to the final characters. The format is "?<a-zA-Z0-9>", where ? is the alternative character and <a-zA-Z0-9> is the code.
      Parameters:
      altChar - The alternative character
      finalChar - The final character
      input - The input string
      charMappers - The character mappers to replace some special characters
      Returns:
      The converted string
    • replaceHex

      @NotNull public static @NotNull String replaceHex(char indicator, @NotNull @NotNull Function<char[],String> replacer, @NotNull @NotNull String input)
      Replace HEX string with the replacer. The HEX string format is "?#rrggbb", where "?" is the indicator character, and "rrggbb" is the HEX string.
      Parameters:
      indicator - the indicator character
      replacer - the replacer to replace the HEX string, which is a character array of length 6
      input - the string
      Returns:
      the colored string
    • normalizeHex

      public static char[] normalizeHex(@NotNull @NotNull String input)
      Normalize the raw hex string to the 6-digit hex string
      Parameters:
      input - the raw hex string
      Returns:
      the 6-digit hex string
    • deepReplace

      public static Object deepReplace(Object object, UnaryOperator<String> replacer)
      Replace the string in the object
      Parameters:
      object - the object
      replacer - the replacer
      Returns:
      the replaced object