Class Strings

java.lang.Object
com.saperion.common.lang.string.Strings

public final class Strings extends Object
Contains utility methods for Strings.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Converts the specified camel case string to a constant name, that is: Converts all characters to upper case Inserts an underline ('_') before every upper case character of the camel case string except the first
    static String
    constantName2CamelCase(String constantName, boolean capitalizeFirstCharacter)
    Converts the specified constant string to camel case, that is: Formats the first character to upper or lower case as specified Removes any underline ('_') Converts the character that follows an underline to upper case Converts all other characters to lower case
    static String
    Sanitizes the string for SQL query.
    static String
    format(Collection<String> colStrings, String separator, String nullString)
    Converts the specified collection of strings to a string using the specified separator and string for null-elements.
    static int
    getCountOfOccurrence(String string, char c)
    Returns how often the specified character occurs in the specified String.
    static int
    getCountOfOccurrence(String stringToScan, String stringContained)
    Returns how often the specified potentially contained String occurs in the specified String to scan.
    static boolean
    isBlank(String string)
    Checks if a String is null, empty or consists of whitespace characters only.
    static boolean
    Checks if a String is null or empty.
    static String
    newString(char c, int length)
    Creates a new String of the specified length filled with the specified character.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • isBlank

      public static boolean isBlank(String string)
      Checks if a String is null, empty or consists of whitespace characters only.
      Parameters:
      string - String to check
      Returns:
      true if string is blank
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String string)
      Checks if a String is null or empty.
      Parameters:
      string - string to check
      Returns:
      true if string is empty
    • newString

      public static String newString(char c, int length)
      Creates a new String of the specified length filled with the specified character.
      Parameters:
      c - character to fill the new String with
      length - length of the new String
      Returns:
      a new String of the specified length filled with the specified character
    • format

      public static String format(Collection<String> colStrings, String separator, String nullString)
      Converts the specified collection of strings to a string using the specified separator and string for null-elements.

      This method is not bijective, so the data can not be restored from the resulting string. For a bijective method for data conversion, see Conversion.convertStringCollectionToString(Collection, char, char, String).

      The specified collection must not be null. The specified separator must not be null. The specified nullString must not be null.

      Parameters:
      colStrings - collection of strings to convert
      separator - separator character
      nullString - string for null-elements
      Returns:
      string
      See Also:
    • constantName2CamelCase

      public static String constantName2CamelCase(String constantName, boolean capitalizeFirstCharacter)
      Converts the specified constant string to camel case, that is:
      • Formats the first character to upper or lower case as specified
      • Removes any underline ('_')
      • Converts the character that follows an underline to upper case
      • Converts all other characters to lower case

      The specified constant name must not be null.

      Parameters:
      constantName - constant name to convert
      capitalizeFirstCharacter - whether the first character should be formatted as upper case
      Returns:
      converted string
    • camelCase2ConstantName

      public static String camelCase2ConstantName(String camelCase)
      Converts the specified camel case string to a constant name, that is:
      • Converts all characters to upper case
      • Inserts an underline ('_') before every upper case character of the camel case string except the first

      The specified camel case string must not be null.

      Parameters:
      camelCase - string to convert
      Returns:
      converted string
    • getCountOfOccurrence

      public static int getCountOfOccurrence(String string, char c)
      Returns how often the specified character occurs in the specified String.

      The specified string must not be null.

      Parameters:
      string - String to search the character in
      c - character to search
      Returns:
      count of occurrence of the specified character in the specified String
    • getCountOfOccurrence

      public static int getCountOfOccurrence(String stringToScan, String stringContained)
      Returns how often the specified potentially contained String occurs in the specified String to scan.

      The specified Strings to scan must not be null.

      The specified potentially contained Strings must not be null or empty.

      Parameters:
      stringToScan - String to scan for occurrences of the potentially contained String
      stringContained - potentially contained String to search for in the String to scan
      Returns:
      count of occurrence
    • escapeSql

      public static String escapeSql(String query)
      Sanitizes the string for SQL query. This operation replaces ' with '' \ with \\ and removes \\\\ It is required since StringEscapeUtils#escapeSql was removed in 3.x https://commons.apache.org/proper/commons-lang/article3_0.html#StringEscapeUtils.escapeSql source: https://github.com/geotools/geotools/blob/main/modules/library/jdbc/src/main/java/org/geotools/jdbc/EscapeSql.java#L51
      Parameters:
      query - the sql query
      Returns:
      sanitized sql query