Class StringUtils
java.lang.Object
de.iip_ecosphere.platform.support.StringUtils
String utility functions, partially wrapping
org.apache.commons.text.- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classShort prefix style with limited string output. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final org.apache.commons.lang3.builder.ToStringStyleShort prefix style with limited string output. -
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 final StringescapeJava(String input) Escapes the characters in aStringusing Java String rules.static final 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 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 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 final StringunescapeJava(String input) Unescapes any Java literals found in theString.static final StringunescapeJson(String input) Unescapes any Json literals found in theString.
-
Field Details
-
SHORT_STRING_STYLE
static final org.apache.commons.lang3.builder.ToStringStyle SHORT_STRING_STYLEShort prefix style with limited string output.
-
-
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
-
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
-