Class EnvironmentVariable.Builder

  • Enclosing class:
    EnvironmentVariable

    public static class EnvironmentVariable.Builder
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.String key  
    • Constructor Summary

      Constructors 
      Constructor Description
      Builder​(java.lang.String envKey)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      EnvironmentVariable build()
      Create an EnvironmentVariable object matching the composed specifications from the Builder.
      EnvironmentVariable.Builder defaultValue​(java.lang.String defaultValue)
      Sets a default (fallback) value for the EnvironmentVariable object if not found.
      EnvironmentVariable.Builder pattern​(java.util.regex.Pattern expectedPattern)
      Sets a regex pattern to be used for validating the environment variable value.
      EnvironmentVariable.Builder substitution​(java.lang.String originalValue, java.lang.String replacementValue)
      Add an entry to the substitution map that will be used to translate the retrieved value when resolved.
      EnvironmentVariable.Builder substitution​(java.util.regex.Pattern matchingPattern, java.lang.String replacementValue)
      Add a Pattern to the substitution map that will be checked for an _explicit_ match and translate the retrieved value when resolved.
      EnvironmentVariable.Builder transform​(java.util.function.Function<java.lang.String,​java.lang.String> transformFunction)
      Register a Transform Function that will be applied after configured substitutions are performed against the resolved Environment Variable value.
      • Methods inherited from class java.lang.Object

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

      • key

        public final java.lang.String key
    • Constructor Detail

      • Builder

        public Builder​(java.lang.String envKey)
    • Method Detail

      • pattern

        public EnvironmentVariable.Builder pattern​(java.util.regex.Pattern expectedPattern)
        Sets a regex pattern to be used for validating the environment variable value. Default value (if defined) will be used if value does not match expected pattern.
        Parameters:
        expectedPattern - is the RegEx Pattern object that will be tested for match against value
        Returns:
        Builder object with applied pattern
      • defaultValue

        public EnvironmentVariable.Builder defaultValue​(java.lang.String defaultValue)
        Sets a default (fallback) value for the EnvironmentVariable object if not found.
        Parameters:
        defaultValue - is an optional fallback value presented by getValue() if env var not resolved in env.
        Returns:
        Builder object with applied default value
      • substitution

        public EnvironmentVariable.Builder substitution​(java.lang.String originalValue,
                                                        java.lang.String replacementValue)
        Add an entry to the substitution map that will be used to translate the retrieved value when resolved. NOTE: Insertion order of substitutions is not tracked; avoid duplicate substitutions
        Parameters:
        originalValue - is the value to substitute when found
        replacementValue - is the replacement value that will be applied
        Returns:
        Builder object with an updated substitution map.
      • substitution

        public EnvironmentVariable.Builder substitution​(java.util.regex.Pattern matchingPattern,
                                                        java.lang.String replacementValue)
        Add a Pattern to the substitution map that will be checked for an _explicit_ match and translate the retrieved value when resolved. NOTE: Insertion order of substitutions is not tracked; avoid duplicate substitutions
        Parameters:
        matchingPattern - is a RegEx Pattern object that will be used to test for an explicit/full match
        replacementValue - is the replacement value that will be applied
        Returns:
        Builder object with an updated substitution map.
      • transform

        public EnvironmentVariable.Builder transform​(java.util.function.Function<java.lang.String,​java.lang.String> transformFunction)
        Register a Transform Function that will be applied after configured substitutions are performed against the resolved Environment Variable value. Only one transform function can be registered. WARNING: if null values are possible (i.e. no non-null default specified and env variable not found), then this transform function must handle null String input parameter on its own.
        Parameters:
        transformFunction - accepts a String, performs some transformations and returns a String
        Returns:
        Builder object with a registered transform function.
      • build

        public EnvironmentVariable build()
        Create an EnvironmentVariable object matching the composed specifications from the Builder.
        Returns:
        EnvironmentVariable object that has already resolved its value.