Class EnvironmentVariable


  • public class EnvironmentVariable
    extends java.lang.Object
    EnvironmentVariable assists with resolving environment variables and provides some utility behavior for detecting presence, resolving values, and performing simple value translation/mapping.
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns:
        the base name of the environment variable
      • getNameFile

        public java.lang.String getNameFile()
        Returns:
        the _FILE suffix name of the environment variable (will attempt to resolve first)
      • getValue

        @Nullable
        public @Nullable java.lang.String getValue()
        Returns:
        substituted (if applicable) value of the resolved env var, or default if defined, otherwise null
      • isFoundInEnv

        public boolean isFoundInEnv()
        Checks if env var was found in environment. Use this to check if the environment variable was defined with any value. If you also want to determine if the fallback value was applied due to an expected pattern mismatch, use isDefaultValueUsed().
        Returns:
        true if environment variable was found in the environment and matches an applied pattern (if applicable)
      • isDefaultValueUsed

        public boolean isDefaultValueUsed()
        Checks if a fallback default value was applied during environment variable resolution due to either a missing environment variable or an expected pattern mis-match.
        Returns:
        true if fallback default was applied
      • newEnvVar

        public static EnvironmentVariable.Builder newEnvVar​(java.lang.String envKey)
        Create an EnvironmentVariable builder with environment variable name `envKey`
        Parameters:
        envKey - name of the environment variable to be resolved
        Returns:
        a Builder for EnvironmentVariable
      • newEnvVars

        public static EnvironmentVariable.BulkBuilder newEnvVars​(java.util.regex.Pattern envKeyPattern)
        Create an EnvironmentVariable bulk builder to retrieve all env vars matching a RegEx Pattern
        Parameters:
        envKeyPattern - RegEx Pattern object that will be used to match available Env Vars
        Returns:
        a BulkBuilder for EnvironmentVariable