Package com.saperion.common.lang.string
Class Strings
- java.lang.Object
-
- com.saperion.common.lang.string.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 firststatic 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 casestatic 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 fornull
-elements.static java.lang.String
fromCharCode(int... codePoints)
Returns String constructed by appending code pointsstatic java.lang.String
fromCharCode(java.lang.String... codePoints)
Returns String constructed by appending code pointsstatic int
getCountOfOccurrence(java.lang.String string, char c)
Returns how often the specified character occurs in the specifiedString
.static int
getCountOfOccurrence(java.lang.String stringToScan, java.lang.String stringContained)
Returns how often the specified potentially containedString
occurs in the specifiedString
to scan.static boolean
isBlank(java.lang.String string)
Checks if aString
isnull
,empty
or consists of whitespace characters only.static boolean
isNullOrEmpty(java.lang.String string)
Checks if aString
isnull
orempty
.static java.lang.String
newString(char c, int length)
Creates a newString
of 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 aString
isnull
,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 aString
isnull
orempty
.- Parameters:
string
- string to check- Returns:
- true if string is empty
-
newString
public static java.lang.String newString(char c, int length)
Creates a newString
of the specified length filled with the specified character.- Parameters:
c
- character to fill the newString
withlength
- length of the newString
- Returns:
- a new
String
of 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
-String
to 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 containedString
occurs in the specifiedString
to scan. The specifiedString
s to scan must not benull
. The specified potentially containedString
s must not benull
or empty.- Parameters:
stringToScan
-String
to scan for occurrences of the potentially containedString
stringContained
- potentially containedString
to search for in theString
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:
-
-