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 Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Map<java.lang.String,​java.lang.String> getEnv()  
      static java.lang.String getEnv​(java.lang.String key)
      Helper method to retrieve environment variable value based on a specified key (name)
      java.lang.String getName()  
      java.lang.String getNameFile()  
      java.lang.String getValue()  
      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.
      boolean isFoundInEnv()
      Checks if env var was found in environment.
      static EnvironmentVariable.Builder newEnvVar​(java.lang.String envKey)
      Create an EnvironmentVariable builder with environment variable name `envKey`
      static EnvironmentVariable.BulkBuilder newEnvVars​(java.util.regex.Pattern envKeyPattern)
      Create an EnvironmentVariable bulk builder to retrieve all env vars matching a RegEx Pattern
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getEnv

        @Nullable
        public static java.lang.String getEnv​(java.lang.String key)
        Helper method to retrieve environment variable value based on a specified key (name)
        Parameters:
        key - the name of the environment variable to retrieve
        Returns:
        The environment variable value as a String, possibly Null
      • getEnv

        public static java.util.Map<java.lang.String,​java.lang.String> getEnv()
      • 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 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