Package net.obvj.confectory.util
Class StringUtils
- java.lang.Object
-
- net.obvj.confectory.util.StringUtils
-
public class StringUtils extends Object
Common methods for working with strings.- Since:
- 0.1.0
- Author:
- oswaldo.bapvic.jr (Oswaldo Junior)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdefaultIfEmpty(String string, Supplier<String> defaultSupplier)Returns either the passed in string, or if the string is empty ("") ornull, the value returned by the specified supplier.static StringexpandEnvironmentVariables(String string)Replaces all the occurrences of system environment variables placed between"${"and"}"with their matching values from the given source string.
-
-
-
Method Detail
-
expandEnvironmentVariables
public static String expandEnvironmentVariables(String string)
Replaces all the occurrences of system environment variables placed between"${"and"}"with their matching values from the given source string.For example:
StringUtils.expandEnvironmentVariables("${TMPDIR}/file1") = "/tmp/file1"- Parameters:
string- the string to be expanded;nullreturnsnull- Returns:
- the expanded string
-
defaultIfEmpty
public static String defaultIfEmpty(String string, Supplier<String> defaultSupplier)
Returns either the passed in string, or if the string is empty ("") ornull, the value returned by the specified supplier.For example:
StringUtils.defaultIfEmpty(null,() -> "default") = "default" StringUtils.defaultIfEmpty("", () -> "default") = "default" StringUtils.defaultIfEmpty("a", () -> "default") = "a"- Parameters:
string- the string to check; may benulldefaultSupplier- a string supplier function to be executed only if the original string is empty ornull- Returns:
- the passed in string, or the value returned by the specified supplier
- Throws:
NullPointerException- if the passed in supplier is null- Since:
- 2.5.0
-
-