public final class StringUtils
extends java.lang.Object
Utility class providing handy methods to deal with Strings.
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getStringOrDefault(java.lang.String inputString,
java.lang.String def)
Returns a trimmed String containing the provided value or the provided default String.
|
static java.lang.String |
getStringOrEmpty(java.lang.String inputString)
Returns a trimmed String containing the provided value or an empty ("") String.
|
static boolean |
isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
|
static boolean |
isNotEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
|
static boolean |
isNotEmptyTrimmed(java.lang.String str)
Checks if a trimmed String is not empty ("") and not null.
|
static java.lang.String |
replaceWildcardConfigs(java.lang.String contentWithWildcards,
java.util.Map<java.lang.String,java.lang.Object> properties)
Returns a String with replaced wildcard values from the provided properties.
|
static java.lang.String |
trim(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String, handling
null by returning null. |
public static boolean isEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
cs - the CharSequence to check, may be nulltrue if the CharSequence is empty or nullpublic static boolean isNotEmpty(java.lang.CharSequence cs)
Checks if a CharSequence is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is not empty and not nullpublic static boolean isNotEmptyTrimmed(java.lang.String str)
Checks if a trimmed String is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = false
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true
str - the String to check, may be nulltrue if the String is not empty and not nullpublic static java.lang.String trim(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null.
The String is trimmed using String.trim(). Trim removes start and end characters <= 32.
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim("abc") = "abc"
StringUtils.trim(" abc ") = "abc"
str - the String to be trimmed, may be nullnull if null String inputpublic static java.lang.String getStringOrEmpty(java.lang.String inputString)
Returns a trimmed String containing the provided value or an empty ("") String.
StringUtils.getStringOrEmpty(null) = ""
StringUtils.getStringOrEmpty("") = ""
StringUtils.getStringOrEmpty(" ") = ""
StringUtils.getStringOrEmpty("bob") = "bob"
StringUtils.getStringOrEmpty(" bob ") = "bob"
inputString - the String to check, may be nullpublic static java.lang.String getStringOrDefault(java.lang.String inputString,
java.lang.String def)
Returns a trimmed String containing the provided value or the provided default String.
StringUtils.getStringOrDefault(null, "bob") = "bob"
StringUtils.getStringOrDefault("", "bob") = "bob"
StringUtils.getStringOrDefault(" ", "bob") = "bob"
StringUtils.getStringOrDefault("alice", "bob") = "alice"
StringUtils.getStringOrDefault(" alice ", "bob") = "alice"
inputString - the String to check, may be nulldef - the default value to return when inputString is null or emptypublic static java.lang.String replaceWildcardConfigs(java.lang.String contentWithWildcards,
java.util.Map<java.lang.String,java.lang.Object> properties)
Input:
contentWithWildcards: "This is a very ${adjective} helper method"
properties: com.google.common.collect.ImmutableMap.of("adjective", "nice")
Output:
"This is a very nice helper method"
contentWithWildcards - the String containing the wildcards to replaceproperties - the properties with the replacement values for the wildcardsnull