Package org.swisspush.gateleen.core.util
Class StringUtils
- java.lang.Object
-
- org.swisspush.gateleen.core.util.StringUtils
-
public final class StringUtils extends java.lang.ObjectUtility class providing handy methods to deal with Strings.
- Author:
- https://github.com/mcweba [Marc-Andre Weber]
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetStringOrDefault(java.lang.String inputString, java.lang.String def)Returns a trimmed String containing the provided value or the provided default String.static java.lang.StringgetStringOrEmpty(java.lang.String inputString)Returns a trimmed String containing the provided value or an empty ("") String.static booleanisEmpty(java.lang.CharSequence cs)Checks if a CharSequence is empty ("") or null.static booleanisNotEmpty(java.lang.CharSequence cs)Checks if a CharSequence is not empty ("") and not null.static booleanisNotEmptyTrimmed(java.lang.String str)Checks if a trimmed String is not empty ("") and not null.static java.lang.StringreplaceWildcardConfigs(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.Stringtrim(java.lang.String str)Removes control characters (char <= 32) from both ends of this String, handlingnullby returningnull.
-
-
-
Method Detail
-
isEmpty
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- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is empty or null
-
isNotEmpty
public 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- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is not empty and not null
-
isNotEmptyTrimmed
public static boolean isNotEmptyTrimmed(java.lang.String str)
Checks if a trimmed String is not empty ("") and not null.
StringUtils.isNotEmptyTrimmed(null) = false StringUtils.isNotEmptyTrimmed("") = false StringUtils.isNotEmptyTrimmed(" ") = false StringUtils.isNotEmptyTrimmed("bob") = true StringUtils.isNotEmptyTrimmed(" bob ") = true- Parameters:
str- the String to check, may be null- Returns:
trueif the String is not empty and not null
-
trim
public static java.lang.String trim(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String, handling
nullby returningnull.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"- Parameters:
str- the String to be trimmed, may be null- Returns:
- the trimmed string,
nullif null String input
-
getStringOrEmpty
public 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"- Parameters:
inputString- the String to check, may be null- Returns:
- the trimmed inputString or an empty ("") String
-
getStringOrDefault
public 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"- Parameters:
inputString- the String to check, may be nulldef- the default value to return when inputString is null or empty- Returns:
- the trimmed inputString or the provided default value
-
replaceWildcardConfigs
public 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.See example below:
Input Variant Plain string: 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" Input Variant JSON non string attribute: contentWithWildcards: "attribute" : "$${number.replace}" properties: com.google.common.collect.ImmutableMap.of("number.replace", "1234") Output: "attribute" : 1234- Parameters:
contentWithWildcards- the String containing the wildcards to replaceproperties- the properties with the replacement values for the wildcards- Returns:
- the String with replaced wildcard values. Returns the input String when input String or
properties are
null
-
-