Class StringUtils
java.lang.Object
de.iip_ecosphere.platform.support.StringUtils
String utility functions.
- Author:
- Holger Eichelberger, SSE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends CharSequence>
TdefaultIfBlank(T str, T defaultStr) Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null, the value ofdefaultStr.static <T extends CharSequence>
TdefaultIfEmpty(T str, T defaultStr) Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value ofdefaultStr.static StringescapeJava(String input) Escapes the characters in aStringusing Java String rules.static StringescapeJson(String input) Escapes the characters in aStringusing Json String rules.static booleanisBlank(CharSequence cs) Checks if a CharSequence is empty (""), null or whitespace only.static booleanisEmpty(CharSequence cs) Checks if a CharSequence is empty ("") or null.static booleanChecks if a CharSequence is not empty (""), not null and not whitespace only.static intlength(CharSequence cs) Gets a CharSequence length or0if the CharSequence isnull.static StringRemoves a substring only if it is at the end of a source string, otherwise returns the source string.static StringremoveStart(String str, String remove) Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.static StringreplaceOnce(String text, String searchString, String replacement) Replaces a String with another String inside a larger String, once.static String[]Turns a string list to an array.static StringTurns an object to an readable string, usually using reflection.static StringtoStringShortStyle(Object obj) Turns an object to an readable string, usually using reflection.static String[]toTokenArray(StringTokenizer tokenizer) Turns the tokens of the given tokenizer into an array.toTokenList(StringTokenizer tokenizer) Turns the tokens of the given tokenizer into a list.static StringunescapeJava(String input) Unescapes any Java literals found in theString.static StringunescapeJson(String input) Unescapes any Json literals found in theString.
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
escapeJava
Escapes the characters in aStringusing Java String rules. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)- Parameters:
input- String to escape values in, may be null- Returns:
- String with escaped values, null if null string input
-
unescapeJava
Unescapes any Java literals found in theString.- Parameters:
input- theStringto unescape, may be null- Returns:
- a new unescaped
String, null if null string input
-
escapeJson
Escapes the characters in aStringusing Json String rules. Escapes any values it finds into their Json String form. Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)- Parameters:
input- String to escape values in, may be null- Returns:
- String with escaped values, null if null string input
-
unescapeJson
Unescapes any Json literals found in theString.- Parameters:
input- theStringto unescape, may be null- Returns:
- A new unescaped
String, null if null string input
-
defaultIfBlank
Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null, the value ofdefaultStr.- Type Parameters:
T- the specific kind of CharSequence- Parameters:
str- the CharSequence to check, may be nulldefaultStr- the default CharSequence to return if the input is whitespace, empty ("") or null- Returns:
- the passed in CharSequence, or the default
-
defaultIfEmpty
Returns either the passed in CharSequence, or if the CharSequence is empty or null, the value ofdefaultStr.- Type Parameters:
T- the specific kind of CharSequence- Parameters:
str- the CharSequence to check, may be nulldefaultStr- the default CharSequence to return if the input is empty ("") or null- Returns:
- the passed in CharSequence, or the default
-
length
Gets a CharSequence length or0if the CharSequence isnull.- Parameters:
cs- a CharSequence, may be null- Returns:
- CharSequence length or
0if the CharSequence is null.
-
isBlank
Checks if a CharSequence is empty (""), null or whitespace only.- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace only
-
isNotBlank
Checks if a CharSequence is not empty (""), not null and not whitespace only.- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is not empty and not null and not whitespace only
-
replaceOnce
Replaces a String with another String inside a larger String, once.- Parameters:
text- text to search and replace in, may be nullsearchString- the String to search for, may be nullreplacement- the String to replace with, may be null- Returns:
- the text with any replacements processed, null if null String input
-
isEmpty
Checks if a CharSequence is empty ("") or null.- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null
-
toString
Turns an object to an readable string, usually using reflection. Uses some default style.- Parameters:
obj- the object- Returns:
- the string representation
-
toStringShortStyle
Turns an object to an readable string, usually using reflection. Uses oktoflow short style.- Parameters:
obj- the object- Returns:
- the string representation
-
removeStart
Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.- Parameters:
str- the source String to search, may be nullremove- the String to search for and remove, may be null- Returns:
- the substring with the string removed if found, null if null String input
-
removeEnd
Removes a substring only if it is at the end of a source string, otherwise returns the source string.- Parameters:
str- the source String to search, may be nullremove- the String to search for and remove, may be null- Returns:
- the substring with the string removed if found, null if null String input
-
toTokenList
Turns the tokens of the given tokenizer into a list.- Parameters:
tokenizer- the tokenizer- Returns:
- the list
-
toArray
Turns a string list to an array.- Parameters:
list- the list, may be null- Returns:
- the corresponding array, also null if
listis null
-
toTokenArray
Turns the tokens of the given tokenizer into an array.- Parameters:
tokenizer- the tokenizer- Returns:
- the array
-