Class StringUtils

java.lang.Object
com.kingsrook.qqq.backend.core.utils.StringUtils

public class StringUtils extends Object
Utility methods for working with Strings
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • hasContent

      public static Boolean hasContent(String input)
      test if string is not null and is not empty (after being trimmed).
      Parameters:
      input - the string to test
      Returns:
      Boolean
    • nvl

      public static String nvl(Object input, String nullOutput)
      returns input.toString() if not null, or nullOutput if input == null (as in SQL NVL)
    • nvl

      public static String nvl(String input, String nullOutput)
      returns input if not null, or nullOutput if input == null (as in SQL NVL)
    • allCapsToMixedCase

      public static String allCapsToMixedCase(String input)
      allCapsToMixedCase - ie, UNIT_CODE -> Unit Code
      Parameters:
      input -
      Returns:
    • safeTruncate

      public static String safeTruncate(String input, int maxLength)
      truncate a string (null- and index-bounds- safely) at a max length.
    • safeTruncate

      public static String safeTruncate(String input, int maxLength, String suffix)
      null- and index-bounds- safely truncate a string to a max length, appending a suffix (like "...") if it did get truncated. Note that the returned string, with the suffix added, will be at most maxLength.
    • safeAppend

      public static String safeAppend(String input, String contentToAppend)
      safely appends a string to another, changing empty string if either value is null
    • safeTrim

      public static String safeTrim(String input)
      returns input if not null, or nullOutput if input == null (as in SQL NVL)
    • join

      public static String join(String glue, Collection<? extends Object> collection)
      Join a collection of objects into 1 string
      Parameters:
      glue - - String to insert between entries
      collection - - The collection of objects to join.
      Returns:
      String
    • joinWithCommasAndAnd

      public static String joinWithCommasAndAnd(List<String> input)
      joinWithCommasAndAnd [one] => [one] [one, two] => [one and two] [one, two, three] => [one, two, and three] [one, two, three, four] => [one, two, three, and four] etc.
      Parameters:
      input -
      Returns:
    • ltrim

      public static String ltrim(String input)
      Trims leading white spaces from a String. Returns a blank ("") value if NULL
      Parameters:
      input -
      Returns:
      String
    • rtrim

      public static String rtrim(String input)
      Trims trailing white spaces from a String. Returns a blank ("") value if NULL
      Parameters:
      input -
      Returns:
      String
    • pluralFormat

      public static String pluralFormat(Integer size, String formatString)
      Given a "formatString" containing any number of {singular,plural} style "tokens", replace the "tokens" with the "singular" options if the 'size' parameter is 1 or the "plural" options if not-1 (e.g., 0 or 2+) e.g.: StringUtils.pluralFormat(n, "Apple{,s} {was,were} eaten")) // seems easier. e.g.: StringUtils.pluralFormat(n, "Apple{ was,s were} eaten")) // also works...
    • plural

      public static String plural(Collection<?> collection)
      Switch between strings based on if the size of the parameter collection. If it is 1 (the singular) or not-1 (0 or 2+, the plural). Get back "" or "s"
    • plural

      public static String plural(Integer size)
      Switch between strings based on if the 'size' parameter is 1 (the singular) or not-1 (0 or 2+, the plural). Get back "" or "s"
    • plural

      public static String plural(Collection<?> collection, String ifOne, String ifNotOne)
      Switch between strings based on if the size of the parameter collection. If it is 1 (the singular) or not-1 (0 or 2+, the plural). Specify/customize the values that you get back (e.g., "y", "ies")
    • plural

      public static String plural(Integer size, String ifOne, String ifNotOne)
      Switch between strings based on if the 'size' parameter is 1 (the singular) or not-1 (0 or 2+, the plural). Specify/customize the values that you get back (e.g., "y", "ies")
    • lcFirst

      public static String lcFirst(String s)
      Lowercase the first char of a string.
    • ucFirst

      public static String ucFirst(String s)
      Uppercase the first char of a string.
    • isUUID

      public static boolean isUUID(String s)
      determines if a given string is a UUID
    • replaceNonAsciiCharacters

      public static String replaceNonAsciiCharacters(String s)
    • emptyToNull

      public static String emptyToNull(String s)
    • safeEqualsIgnoreCase

      public static boolean safeEqualsIgnoreCase(String a, String b)
    • appendIncrementingSuffix

      public static String appendIncrementingSuffix(String input)
    • maskAndTruncate

      public static String maskAndTruncate(String value)
    • maskAndTruncate

      public static String maskAndTruncate(String value, String mask, int minLengthToMask, int charsToShowOnEnds)
    • nCopies

      public static String nCopies(int n, String s)
    • nCopiesWithGlue

      public static String nCopiesWithGlue(int n, String s, String glue)