Class StringUtils

java.lang.Object
migratedb.v1.core.internal.util.StringUtils

public final class StringUtils extends Object
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • trimChar

      public static String trimChar(String s, char c)
    • trimOrPad

      public static String trimOrPad(String str, int length)
      Trims or pads (with spaces) this string, so it has this exact length.
      Parameters:
      str - The string to adjust. null is treated as an empty string.
      length - The exact length to reach.
      Returns:
      The adjusted string.
    • trimOrPad

      public static String trimOrPad(String str, int length, char padChar)
      Trims or pads this string, so it has this exact length.
      Parameters:
      str - The string to adjust. null is treated as an empty string.
      length - The exact length to reach.
      padChar - The padding character.
      Returns:
      The adjusted string.
    • trimOrLeftPad

      public static String trimOrLeftPad(String str, int length, char padChar)
      Trims or pads this string, so it has this exact length.
      Parameters:
      str - The string to adjust. null is treated as an empty string.
      length - The exact length to reach.
      padChar - The padding character.
      Returns:
      The adjusted string.
    • leftPad

      public static String leftPad(String original, int length, char padChar)
    • collapseWhitespace

      public static String collapseWhitespace(String str)
      Replaces all sequences of whitespace by a single blank. Ex.: "    " -> " "
      Parameters:
      str - The string to analyse.
      Returns:
      The input string, with all whitespace collapsed.
    • left

      public static String left(String str, int count)
      Returns the first n characters from this string, where n = count. If the string is shorter, the entire string will be returned. If the string is longer, it will be truncated.
      Parameters:
      str - The string to parse.
      count - The amount of characters to return.
      Returns:
      The first n characters from this string, where n = count.
    • replaceAll

      public static String replaceAll(String str, String originalToken, String replacementToken)
      Replaces all occurrences of this originalToken in this string with this replacementToken.
      Parameters:
      str - The string to process.
      originalToken - The token to replace.
      replacementToken - The replacement.
      Returns:
      The transformed str.
    • hasLength

      public static boolean hasLength(String str)
      Checks whether this string is not null and not empty.
      Parameters:
      str - The string to check.
      Returns:
      true if it has content, false if it is null or blank.
    • arrayToCommaDelimitedString

      public static String arrayToCommaDelimitedString(Object[] strings)
      Turns this string array in one comma-delimited string.
      Parameters:
      strings - The array to process.
      Returns:
      The new comma-delimited string. An empty string if strings is empty. null if strings is null.
    • arrayToDelimitedString

      public static String arrayToDelimitedString(String delimiter, Object[] strings)
      Turns this string array in one delimited string.
      Parameters:
      delimiter - The delimiter to use.
      strings - The array to process.
      Returns:
      The new delimited string. An empty string if strings is empty. null if strings is null.
    • hasText

      public static boolean hasText(String s)
      Checks whether this string isn't null and contains at least one non-blank character.
      Parameters:
      s - The string to check.
      Returns:
      true if it has text, false if not.
    • tokenizeToStringArray

      public static String[] tokenizeToStringArray(String str, String delimiters)
      Splits this string into an array using these delimiters.
      Parameters:
      str - The string to split.
      delimiters - The delimiters to use.
      Returns:
      The resulting array.
    • tokenizeToStringCollection

      public static List<String> tokenizeToStringCollection(String str, String delimiters)
      Splits this string into a collection using these delimiters.
      Parameters:
      str - The string to split.
      delimiters - The delimiters to use.
      Returns:
      The resulting array.
    • tokenizeToStringCollection

      public static List<String> tokenizeToStringCollection(String str, char delimiterChar, char groupDelimiterChar)
      Splits this string into a collection using this delimiter and this group delimiter.
      Parameters:
      str - The string to split.
      delimiterChar - The delimiter to use.
      groupDelimiterChar - The character to use to delimit groups.
      Returns:
      The resulting array.
    • replace

      public static String replace(String inString, String oldPattern, String newPattern)
      Replace all occurrences of a substring within a string with another string.
      Parameters:
      inString - String to examine
      oldPattern - String to replace
      newPattern - String to insert
      Returns:
      a String with the replacements
    • collectionToCommaDelimitedString

      public static String collectionToCommaDelimitedString(Collection<?> collection)
      Convenience method to return a Collection as a comma-delimited String. e.g. useful for toString() implementations.
      Parameters:
      collection - the Collection to analyse
      Returns:
      The comma-delimited String.
    • collectionToDelimitedString

      public static String collectionToDelimitedString(Collection<?> collection, String delimiter)
      Convenience method to return a Collection as a delimited String. E.g. useful for toString() implementations.
      Parameters:
      collection - the Collection to analyse
      delimiter - The delimiter.
      Returns:
      The delimited String.
    • trimLeadingCharacter

      public static String trimLeadingCharacter(String str, char character)
      Trim any leading occurrence of this character from the given String.
      Parameters:
      str - the String to check.
      character - The character to trim.
      Returns:
      the trimmed String
      See Also:
    • startsAndEndsWith

      public static boolean startsAndEndsWith(String str, String prefix, Collection<String> suffixes)
      Checks whether str both begins with this prefix and ends withs either of these suffixes.
      Parameters:
      str - The string to check.
      prefix - The prefix.
      suffixes - The suffixes.
      Returns:
      true if it does, false if not.
    • wrap

      public static String wrap(String str, int lineSize)
      Wrap this string every lineSize characters.
      Parameters:
      str - The string to wrap.
      lineSize - The maximum size of each line.
      Returns:
      The wrapped string.
    • wordWrap

      public static String wordWrap(String str, int lineSize)
      Wrap this string at the word boundary at or below lineSize characters.
      Parameters:
      str - The string to wrap.
      lineSize - The maximum size of each line.
      Returns:
      The word-wrapped string.
    • isCharAnyOf

      public static boolean isCharAnyOf(char c, String chars)
      Checks whether this character matches any of these characters.
      Parameters:
      c - The char to check.
      chars - The chars that should match.
      Returns:
      true if it does, false if not.