Class StringUtils


  • public class StringUtils
    extends Object
    Common methods for working with strings.
    Since:
    0.1.0
    Author:
    oswaldo.bapvic.jr (Oswaldo Junior)
    • 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; null returns null
        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 ("") or null, 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 be null
        defaultSupplier - a string supplier function to be executed only if the original string is empty or null
        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