Package com.saperion.common.lang.string
Class Strings
- java.lang.Object
-
- com.saperion.common.lang.string.Strings
-
public final class Strings extends java.lang.ObjectContains utility methods for Strings.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEMPTY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcamelCase2ConstantName(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 firststatic java.lang.StringconstantName2CamelCase(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 casestatic java.lang.StringescapeSql(java.lang.String query)Sanitizes the string for SQL query.static java.lang.Stringformat(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 fornull-elements.static intgetCountOfOccurrence(java.lang.String string, char c)Returns how often the specified character occurs in the specifiedString.static intgetCountOfOccurrence(java.lang.String stringToScan, java.lang.String stringContained)Returns how often the specified potentially containedStringoccurs in the specifiedStringto scan.static booleanisBlank(java.lang.String string)Checks if aStringisnull,emptyor consists of whitespace characters only.static booleanisNullOrEmpty(java.lang.String string)Checks if aStringisnullorempty.static java.lang.StringnewString(char c, int length)Creates a newStringof the specified length filled with the specified character.
-
-
-
Field Detail
-
EMPTY
public static final java.lang.String EMPTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
isBlank
public static boolean isBlank(java.lang.String string)
Checks if aStringisnull,emptyor consists of whitespace characters only.- Parameters:
string-Stringto check- Returns:
- true if string is blank
-
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String string)
Checks if aStringisnullorempty.- Parameters:
string- string to check- Returns:
- true if string is empty
-
newString
public static java.lang.String newString(char c, int length)Creates a newStringof the specified length filled with the specified character.- Parameters:
c- character to fill the newStringwithlength- length of the newString- Returns:
- a new
Stringof the specified length filled with the specified character
-
format
public 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 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:
Conversion.convertStringCollectionToString(Collection, char, char, String),Conversion.convertStringToStringList(String, char, char, String)
-
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
null.- Parameters:
constantName- constant name to convertcapitalizeFirstCharacter- 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
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 specifiedString. The specified string must not benull.- Parameters:
string-Stringto search the character inc- 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 containedStringoccurs in the specifiedStringto scan. The specifiedStrings to scan must not benull. The specified potentially containedStrings must not benullor empty.- Parameters:
stringToScan-Stringto scan for occurrences of the potentially containedStringstringContained- potentially containedStringto search for in theStringto 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
-
-