Class Strings


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

      Fields 
      Modifier and Type Field Description
      static java.lang.String EMPTY  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String camelCase2ConstantName​(java.lang.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
      static java.lang.String constantName2CamelCase​(java.lang.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 java.lang.String escapeSql​(java.lang.String query)
      Sanitizes the string for SQL query.
      static java.lang.String format​(java.util.Collection<java.lang.String> colStrings, java.lang.String separator, java.lang.String nullString)
      Converts the specified collection of strings to a string using the specified separator and string for null-elements.
      static java.lang.String fromCharCode​(int... codePoints)
      Returns String constructed by appending code points
      static java.lang.String fromCharCode​(java.lang.String... codePoints)
      Returns String constructed by appending code points
      static int getCountOfOccurrence​(java.lang.String string, char c)
      Returns how often the specified character occurs in the specified String.
      static int getCountOfOccurrence​(java.lang.String stringToScan, java.lang.String stringContained)
      Returns how often the specified potentially contained String occurs in the specified String to scan.
      static boolean isBlank​(java.lang.String string)
      Checks if a String is null, empty or consists of whitespace characters only.
      static boolean isNullOrEmpty​(java.lang.String string)
      Checks if a String is null or empty.
      static java.lang.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
    • Method Detail

      • isBlank

        public static boolean isBlank​(java.lang.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​(java.lang.String string)
        Checks if a String is null or empty.
        Parameters:
        string - string to check
        Returns:
        true if string is empty
      • newString

        public static java.lang.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
      • constantName2CamelCase

        public static java.lang.String constantName2CamelCase​(java.lang.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 java.lang.String camelCase2ConstantName​(java.lang.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​(java.lang.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​(java.lang.String stringToScan,
                                               java.lang.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 java.lang.String escapeSql​(java.lang.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
      • fromCharCode

        public static java.lang.String fromCharCode​(int... codePoints)
        Returns String constructed by appending code points
        Parameters:
        codePoints -
        Returns:
      • fromCharCode

        public static java.lang.String fromCharCode​(java.lang.String... codePoints)
        Returns String constructed by appending code points
        Parameters:
        codePoints -
        Returns: