Class StringUtils

java.lang.Object
ml.karmaconfigs.api.common.utils.string.StringUtils

public final class StringUtils extends Object
Karma string utilities
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • replaceLast

      public static String replaceLast(String text, String regex, String replace)
      Replace the last regex in the text
      Parameters:
      text - the text to search in
      regex - the text to find
      replace - the text to replace with
      Returns:
      the replaced text
    • insetInEach

      public static String insetInEach(String text, String insert, int period)
      Insert a text each amount of characters
      Parameters:
      text - the original text
      insert - the text to insert
      period - the amount of characters
      Returns:
      the formatted text
    • insertInEachSpace

      public static String insertInEachSpace(String text, String insert, int period, boolean replaceSpace)
      Insert a text each amount of characters as soon as the character is a space/empty
      Parameters:
      text - the original text
      insert - the text to insert
      period - the amount of characters
      replaceSpace - replace the empty character with the insert
      Returns:
      the formatted text
    • splitInEach

      public static String[] splitInEach(String text, int period)
      Split a text by each characters
      Parameters:
      text - the original text
      period - the amount of characters
      Returns:
      the splitted text
    • splitInEachSpace

      public static String[] splitInEachSpace(String text, int period, boolean replaceSpace)
      Split a text by each characters if it's a space
      Parameters:
      text - the original text
      period - the amount of characters
      replaceSpace - replace the empty character with the insert
      Returns:
      the splitted text
    • toColor

      public static String toColor(String text)
      Transform the text colors to a valid colors
      Parameters:
      text - the text to translate
      Returns:
      the translated text
    • toConsoleColor

      public static String toConsoleColor(CharSequence text)
      Transform the text colors to a valid colors
      Parameters:
      text - the text to translate
      Returns:
      the translated text
    • toColor

      public static List<String> toColor(List<String> texts)
      Transform the list of text to a colored list of text
      Parameters:
      texts - the texts to translate
      Returns:
      the colored texts
    • getColors

      public static Set<String> getColors(String text)
      Get a set of colors present in the text
      Parameters:
      text - the text to read from
      Returns:
      the text colors
    • getLastColor

      public static String getLastColor(String text)
      Get the last color present on a text
      Parameters:
      text - the text to read from
      Returns:
      the text colors
    • getLastColor

      public static String getLastColor(List<String> texts, int index)
      Get the last color from a list of texts
      Parameters:
      texts - the list of texts
      index - the text index
      Returns:
      the texts last color
    • stripColor

      public static String stripColor(String text)
      Remove the color on the text
      Parameters:
      text - the text to read
      Returns:
      the text without colors
    • stripColor

      public static List<String> stripColor(List<String> texts)
      Remove the colors from a texts
      Parameters:
      texts - the texts
      Returns:
      the uncolored texts
    • generateString

      public static RandomString generateString()
      Generate a new random text
      Returns:
      a random text creator
    • generateString

      public static RandomString generateString(OptionsBuilder options)
      Generate a new random text
      Parameters:
      options - the random text options
      Returns:
      a random text creator
    • randomColor

      public static String randomColor()
      Generate a random color
      Returns:
      a random color
    • formatString

      public static String formatString(CharSequence text, Object... replaces)
      Format the specified text
      Parameters:
      text - the text to format
      replaces - the text replaces
      Returns:
      the formatted text
    • formatString

      @Deprecated public static String formatString(CharSequence text, Map<String,​Object> replaces)
      Deprecated.
      It's better to use now. By default, KarmaAPI uses GlobalPlaceholderEngine with a implementation of Placeholder as SimplePlaceholder. For now, this method registers the map key to a placeholder which contains the map value and uses global placeholder engine to return the formatted string
      Format the specified text
      Parameters:
      text - the text to format
      replaces - the text replaces
      Returns:
      the formatted text
    • formatString

      public static String formatString(KarmaSource owner, CharSequence text, Level level)
      Format the specified text
      Parameters:
      owner - the text owner
      text - the text to format
      level - the text level
      Returns:
      the formatted text
    • formatString

      public static String formatString(KarmaSource owner, CharSequence text, Level level, Object... replaces)
      Format the specified text
      Parameters:
      owner - the text owner
      text - the text to format
      level - the text level
      replaces - the text replaces
      Returns:
      the formatted text
    • readFrom

      public static String readFrom(File file)
      Read the file completely
      Parameters:
      file - the file to read
      Returns:
      the file content as text
    • listToString

      public static String listToString(List<String> lines, boolean spaces)
      Transform a list of texts into a single text line
      Parameters:
      lines - the lines
      spaces - replace new lines with spaces, otherwise, new lines will be replaced with nothing and '\n' will be added at the end of the line
      Returns:
      the list of texts as single line text
    • unEscapeString

      public static String unEscapeString(String text)
      Un scape text
      Parameters:
      text - the text to un scape
      Returns:
      the unescaped text
    • escapeString

      public static String escapeString(String text)
      Escape text
      Parameters:
      text - the text to scape
      Returns:
      the escaped text
    • serialize

      public static <T> String serialize(T instance)
      Serialize an object into a text
      Type Parameters:
      T - the objet type
      Parameters:
      instance - the object instance
      Returns:
      the serialized object
    • load

      @Nullable public static @Nullable Object load(String instance)
      Load the instance as an unknown object
      Parameters:
      instance - the serialized instance
      Returns:
      the instance object
    • loadUnsafe

      @Nullable public static <T> T loadUnsafe(String instance)
      Load unsafely the instance as a known object
      Type Parameters:
      T - the type
      Parameters:
      instance - the instance
      Returns:
      the instance type
    • containsLetters

      public static boolean containsLetters(CharSequence sequence)
      Get if the text contains letter
      Parameters:
      sequence - the text
      Returns:
      if the text contains letter
    • containsNumbers

      public static boolean containsNumbers(CharSequence sequence)
      Get if the text contains numbers
      Parameters:
      sequence - the text
      Returns:
      if the text contains letter
    • isNullOrEmpty

      public static boolean isNullOrEmpty(Object check)
      Get if the object is null or empty
      Parameters:
      check - the object to check
      Returns:
      if the object is null or empty
    • areNullOrEmpty

      public static boolean areNullOrEmpty(Object... checks)
      Get if the objects are null or empty
      Parameters:
      checks - the objects to check
      Returns:
      if the objects are null or empty
    • compareTo

      public static VersionComparator compareTo(ComparatorBuilder builder)
      Get the version difference between two versions
      Parameters:
      builder - the version difference builder
      Returns:
      a new version comparator
    • removeNumbers

      public static String removeNumbers(CharSequence original)
      Remove the numbers from text
      Parameters:
      original - the original text
      Returns:
      the text without numbers
    • removeLetters

      public static String removeLetters(CharSequence original)
      Remove the letters from text
      Parameters:
      original - the original text
      Returns:
      the text without letters
    • parseNumbers

      public static String parseNumbers(CharSequence original, Character... keep)
      Parse only the numbers from the text
      Parameters:
      original - the original text
      keep - the characters to allow
      Returns:
      the parsed text
    • parseLetters

      public static String parseLetters(CharSequence original, Character... keep)
      Parse only the letters from the text
      Parameters:
      original - the original text
      keep - the characters to allow
      Returns:
      the parsed text
    • timeToString

      public static String timeToString(long milliseconds)
      Convert the time in milliseconds into a readable time string format
      Parameters:
      milliseconds - the milliseconds
      Returns:
      the time in seconds
    • timeToString

      public static String timeToString(long milliseconds, TimeName name)
      Convert the time in milliseconds into a readable time string format
      Parameters:
      milliseconds - the milliseconds
      name - the unit names
      Returns:
      the time in seconds
    • arrayToSet

      public static <T> Set<T> arrayToSet(T[] array)
      Parse an array to a set
      Type Parameters:
      T - the array type
      Parameters:
      array - the array
      Returns:
      the array as set