Class StringUtils

java.lang.Object
panda.utilities.StringUtils

public final class StringUtils extends Object
  • Field Details

    • EMPTY

      public static final String EMPTY
      Instance of the empty string
      See Also:
    • EMPTY_ARRAY

      public static final String[] EMPTY_ARRAY
      Instance of the empty array of string
  • Method Details

    • splitFirst

      public static String[] splitFirst(String text, String delimiter)
      Split text by the specified delimiter, but only once (to the first occurrence of the specified delimiter)
      Parameters:
      text - the text to split
      delimiter - the delimiter to search for
      Returns:
      array of split text
    • split

      public static String[] split(String text, String delimiter)
      Split text by the specified delimiter (without regex)
      Parameters:
      text - the text to split
      delimiter - the delimiting text
      Returns:
      the array of elements
    • lastIndexOfBefore

      public static int lastIndexOfBefore(String text, String element, int occurrences)
      Last index of the element with given amount of last occurrences to ignore
      Parameters:
      text - the text to search in
      element - the element to search for
      occurrences - amount of occurrences to ignore before the element to search for
      Returns:
      index of the element, -1 when the element is not found
    • lastIndexOf

      public static int lastIndexOf(String text, String element, int toIndex)
      Returns the index within this string of the last occurrence of the specified substring
      Parameters:
      text - the text to search
      element - the substring to search for
      toIndex - the previous last index
      Returns:
      the index of the last occurrence of the specified substring, or -1 if there is no such occurrence or toIndex is smaller than 1
    • replace

      public static String replace(String text, String searchString, String replacement)
      Faster alternative to String#replace
      Parameters:
      text - the text to search and replace in
      searchString - the text to search for
      replacement - the text to replace with
      Returns:
      the resulting text
    • replaceFirst

      public static String replaceFirst(String text, String pattern, String replacement)
      Replace the first occurrence of the specified pattern in the text
      Parameters:
      text - the text to search and replace in
      pattern - the text to search for
      replacement - the text to replace with
      Returns:
      the processed text
    • replaceFirst

      public static String replaceFirst(String text, String pattern, String replacement, int start)
      Replace the first occurrence of the specified pattern in the text
      Parameters:
      text - the text to search and replace in
      pattern - the text to search for
      replacement - the text to replace with
      start - position to start searching for
      Returns:
      the processed text
    • replaceRespectively

      public static String replaceRespectively(String text, String pattern, String... values)
      Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, using the next element of the specified values
      Parameters:
      text - The sequence of char values to be replace replacement – The replacement sequence of char values
      pattern - The pattern to search
      values - The replacement sequences
      Returns:
      the resulting string
      Throws:
      IllegalArgumentException - if the amount of patterns is different than the amount of values
    • replaceRespectivelyAndSoftly

      public static String replaceRespectivelyAndSoftly(String text, String pattern, String... values)
      Replaces respectively substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, using the next element of the specified values
      Parameters:
      text - The sequence of char values to be replace replacement – The replacement sequence of char values
      pattern - The pattern to search
      values - The replacement sequences
      Returns:
      the resulting string
    • capitalize

      public static String capitalize(String text)
      Capitalize characters in string, merged from StringUtils.capitalize [modules - commons-lang:commons-lang3]
      Parameters:
      text - the string to capitalize, may be null
      Returns:
      the capitalized string, null if null string input
    • startsWith

      public static boolean startsWith(String text, Predicate<char[]> filter)
      Check how the specified text starts
      Parameters:
      text - the text to check
      filter - condition
      Returns:
      result of the condition
    • trimStart

      public static String trimStart(String text)
      Trim the beginning of the text
      Parameters:
      text - the text to trim
      Returns:
      trimmed string
    • trimEnd

      public static String trimEnd(String text)
      Trim the of end of the specified text
      Parameters:
      text - the text to trim
      Returns:
      trimmed string
    • extractParagraph

      public static String extractParagraph(String str)
      Extracts paragraph/indentation from the beginning of the text
      Parameters:
      str - a string to search
      Returns:
      whitespaces at the beginning of the specified string
    • buildSpace

      public static String buildSpace(int spaces)
      Generate space
      Parameters:
      spaces - number of spaces
      Returns:
      generated indentation
    • repeated

      public static String repeated(int repetitions, String... elements)
    • countOccurrences

      public static int countOccurrences(String text, String element)
      Amount of the occurrences of the specified text in string
      Parameters:
      text - the string to search in
      element - the string to search for
      Returns:
      amount of the occurrences
    • containsCharacter

      public static boolean containsCharacter(String text, char... characters)
      Checks if the specified text contains any character from the specified array
      Parameters:
      text - a string to search
      characters - searched characters
      Returns:
      true if the specified string contains any of the specified characters
    • containsSpecialCharacters

      public static boolean containsSpecialCharacters(String text)
      Checks if the specified text contains character other than letter or digit
      Parameters:
      text - the string to search in
      Returns:
      true if the specified string contains a character other than a letter or a digit
    • containsOtherCharacters

      public static boolean containsOtherCharacters(String text, char[]... characters)
      Checks if the specified text contains other characters than these from the specified array
      Parameters:
      text - the string to search in
      Returns:
      true if the string contains a character other than the specified in arrays
    • join

      public static String join(String... strings)
      Join string into the one string
      Parameters:
      strings - strings to join
      Returns:
      joined string
    • toString

      public static String toString(@Nullable @Nullable Object object)
      Object to string with array support
      Parameters:
      object - the object to stringify
      Returns:
      object represented by string
    • isNumber

      public static boolean isNumber(String str)
      Check if the specified string can be parsed as a number Allowed characters: 0-9 - digits x - hexadecimal . - float
      Parameters:
      str - string to check
      Returns:
      true if the specified text can be a number
    • isEmpty

      public static String isEmpty(String text, String exceptionMessage)
      Checks if the specified text is null or empty, throw exception if it is
      Parameters:
      text - to check
      exceptionMessage - the message is used by IllegalArgumentException
      Returns:
      the checked text
    • isEmpty

      public static boolean isEmpty(String text)
      Checks if the specified text is null or empty
      Parameters:
      text - to check
      Returns:
      true if a specified text is null or empty