Package com.saperion.common.lang.string
Class Strings
java.lang.Object
com.saperion.common.lang.string.Strings
Contains utility methods for Strings.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 firststatic 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 casestatic 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 fornull
-elements.static int
getCountOfOccurrence
(String string, char c) Returns how often the specified character occurs in the specifiedString
.static int
getCountOfOccurrence
(String stringToScan, String stringContained) static boolean
static boolean
isNullOrEmpty
(String string) static String
newString
(char c, int length) Creates a newString
of the specified length filled with the specified character.
-
Field Details
-
EMPTY
- See Also:
-
-
Method Details
-
isBlank
- Parameters:
string
-String
to check- Returns:
- true if string is blank
-
isNullOrEmpty
- Parameters:
string
- string to check- Returns:
- true if string is empty
-
newString
Creates a newString
of the specified length filled with the specified character. -
format
Converts the specified collection of strings to a string using the specified separator and string fornull
-elements. This method is not bijective, so the data can not be restored from the resulting string. For a bijective method for data conversion, seeConversion.convertStringCollectionToString(Collection, char, char, String)
. The specified collection must not benull
. The specified separator must not benull
. The specified nullString must not benull
.- Parameters:
colStrings
- collection of strings to convertseparator
- separator characternullString
- string fornull
-elements- Returns:
- string
- See Also:
-
constantName2CamelCase
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
null
.- Parameters:
constantName
- constant name to convertcapitalizeFirstCharacter
- whether the first character should be formatted as upper case- Returns:
- converted string
-
camelCase2ConstantName
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
null
.- Parameters:
camelCase
- string to convert- Returns:
- converted string
-
getCountOfOccurrence
Returns how often the specified character occurs in the specifiedString
. The specified string must not benull
. -
getCountOfOccurrence
-
escapeSql
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
-