Class GestaltBuilder


  • public class GestaltBuilder
    extends java.lang.Object
    Builder to setup and create the Gestalt config class.

    The minimum requirements for building a config is to provide a source. Gestalt gestalt = new GestaltBuilder() .addSource(new FileConfigSource(defaultFile)) .build();

    The builder will automatically add the default config loaders and decoders. You can customise and replace functionality as needed using the appropriate builder methods.

    If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed. If there are any config loaders set, it will not add the default config loaders. So you will need to add the defaults manually if needed.

    The builder can be used to customize and replace any of the functionality of Gestalt.

    • Constructor Detail

      • GestaltBuilder

        public GestaltBuilder()
    • Method Detail

      • addDefaultDecoders

        public GestaltBuilder addDefaultDecoders()
        Adds all default decoders to the builder. Uses the ServiceLoader to find all registered Decoders and adds them
        Returns:
        GestaltBuilder builder
      • addDefaultConfigLoaders

        public GestaltBuilder addDefaultConfigLoaders()
        Add default config loaders to the builder. Uses the ServiceLoader to find all registered Config Loaders and adds them
        Returns:
        GestaltBuilder builder
      • addDefaultPostProcessors

        public GestaltBuilder addDefaultPostProcessors()
        Add default post processors to the builder. Uses the ServiceLoader to find all registered post processors and adds them
        Returns:
        GestaltBuilder builder
      • addDefaultPathMappers

        public GestaltBuilder addDefaultPathMappers()
        Add default post processors to the builder. Uses the ServiceLoader to find all registered post processors and adds them
        Returns:
        GestaltBuilder builder
      • addSource

        @Deprecated(since="0.23.4")
        public GestaltBuilder addSource​(ConfigSource source)
        Deprecated.
        Add a single source to the builder.

        Deprecated prefer the use of addSource with a source builder

        Parameters:
        source - add a single sources
        Returns:
        GestaltBuilder builder
      • addSource

        public GestaltBuilder addSource​(ConfigSourcePackage configSourcePackage)
        Add a single ConfigSourcePackage built with a builder, to gestalt the builder.
        Parameters:
        configSourcePackage - add a single Config source Package
        Returns:
        GestaltBuilder builder
      • setSources

        public GestaltBuilder setSources​(java.util.List<ConfigSourcePackage> configSourcePackage)
        Set a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.
        Parameters:
        configSourcePackage - set a list of ConfigSourcePackage
        Returns:
        GestaltBuilder builder
      • addSources

        public GestaltBuilder addSources​(java.util.List<ConfigSourcePackage> configSourcePackage)
        Add a List of ConfigSourcePackage built with a config source builder, to gestalt the builder.
        Parameters:
        configSourcePackage - add list of Config source Package
        Returns:
        GestaltBuilder builder
      • addReloadStrategy

        @Deprecated(since="0.23.4",
                    forRemoval=true)
        public GestaltBuilder addReloadStrategy​(ConfigReloadStrategy configReloadStrategy)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Add a config reload strategy to the builder.

        Deprecated prefer the use of addSource with a source builder. Use the source builder to add a reload strategy

        Parameters:
        configReloadStrategy - add a config reload strategy.
        Returns:
        GestaltBuilder builder
      • addReloadStrategies

        @Deprecated(since="0.23.4",
                    forRemoval=true)
        public GestaltBuilder addReloadStrategies​(java.util.List<ConfigReloadStrategy> reloadStrategies)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Add a list of config reload strategies to the builder. Deprecated prefer the use of addSource with a source builder. Use the source builder to add a reload strategy
        Parameters:
        reloadStrategies - list of config reload strategies.
        Returns:
        GestaltBuilder builder
      • addCoreReloadListener

        public GestaltBuilder addCoreReloadListener​(CoreReloadListener coreReloadListener)
        Add a Core reload listener to the builder.
        Parameters:
        coreReloadListener - a Core reload listener
        Returns:
        GestaltBuilder builder
      • addCoreReloadListener

        public GestaltBuilder addCoreReloadListener​(java.util.List<CoreReloadListener> coreCoreReloadListeners)
        Add a list of Core reload listener.
        Parameters:
        coreCoreReloadListeners - a list of Core reload listener
        Returns:
        GestaltBuilder builder
      • setConfigLoaderService

        public GestaltBuilder setConfigLoaderService​(ConfigLoaderService configLoaderService)
        Add a config loader service to the builder.
        Parameters:
        configLoaderService - a config loader service
        Returns:
        GestaltBuilder builder
      • setConfigLoaders

        public GestaltBuilder setConfigLoaders​(java.util.List<ConfigLoader> configLoaders)
                                        throws GestaltConfigurationException
        Sets a list of config loader to the builder. Replaces any currently set. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.
        Parameters:
        configLoaders - a list of config loader
        Returns:
        GestaltBuilder builder
        Throws:
        GestaltConfigurationException - if there are no config loaders.
      • addConfigLoaders

        public GestaltBuilder addConfigLoaders​(java.util.List<ConfigLoader> configLoaders)
                                        throws GestaltConfigurationException
        Adds a list of config loader to the builder. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.
        Parameters:
        configLoaders - a list of config loader
        Returns:
        GestaltBuilder builder
        Throws:
        GestaltConfigurationException - if the config loaders are empty
      • addConfigLoader

        public GestaltBuilder addConfigLoader​(ConfigLoader configLoader)
        Add a config loader. If there are any config loaders set, it will not add the defaults. So you will need to add the defaults manually if needed.
        Parameters:
        configLoader - a config loader
        Returns:
        GestaltBuilder builder
      • addPostProcessor

        public GestaltBuilder addPostProcessor​(PostProcessor postProcessor)
        Add a single PostProcessor to the builder.
        Parameters:
        postProcessor - add a single PostProcessor
        Returns:
        GestaltBuilder builder
      • addPathMapper

        public GestaltBuilder addPathMapper​(PathMapper pathMapper)
        Add a single PathMapper to the builder.
        Parameters:
        pathMapper - add a single PathMapper
        Returns:
        GestaltBuilder builder
      • setSentenceLexer

        public GestaltBuilder setSentenceLexer​(SentenceLexer sentenceLexer)
        Set the sentence lexer that will be passed through to the DecoderRegistry.
        Parameters:
        sentenceLexer - for the DecoderRegistry
        Returns:
        GestaltBuilder builder
      • setGestaltConfig

        public GestaltBuilder setGestaltConfig​(GestaltConfig gestaltConfig)
        Set the configuration for Gestalt. Will be overridden by any settings specified in the builder
        Parameters:
        gestaltConfig - configuration for the Gestalt
        Returns:
        GestaltBuilder builder
      • setConfigNodeService

        public GestaltBuilder setConfigNodeService​(ConfigNodeService configNodeService)
        Set the config node service if you want to provide your own. Otherwise a default is provided.
        Parameters:
        configNodeService - a config node service
        Returns:
        GestaltBuilder builder
      • setDecoderService

        public GestaltBuilder setDecoderService​(DecoderService decoderService)
        Set the decoder service if you want to provide your own. Otherwise a default is provided. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.
        Parameters:
        decoderService - decoder service
        Returns:
        GestaltBuilder builder
      • setDecoders

        public GestaltBuilder setDecoders​(java.util.List<Decoder<?>> decoders)
                                   throws GestaltConfigurationException
        Set a list of decoders, replaces the existing decoders. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.
        Parameters:
        decoders - list of decoders
        Returns:
        GestaltBuilder builder
        Throws:
        GestaltConfigurationException - no decoders provided
      • addDecoders

        public GestaltBuilder addDecoders​(java.util.List<Decoder<?>> decoders)
                                   throws GestaltConfigurationException
        Add a list of decoders. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.
        Parameters:
        decoders - list of decoders
        Returns:
        GestaltBuilder builder
        Throws:
        GestaltConfigurationException - no decoders provided
      • addDecoder

        public GestaltBuilder addDecoder​(Decoder decoder)
        Add a decoder. If there are any decoders set, it will not add the default decoders. So you will need to add the defaults manually if needed.
        Parameters:
        decoder - add a decoder
        Returns:
        GestaltBuilder builder
      • setTreatWarningsAsErrors

        public GestaltBuilder setTreatWarningsAsErrors​(boolean warningsAsErrors)
        Treat warnings as errors.
        Parameters:
        warningsAsErrors - treat warnings as errors.
        Returns:
        GestaltBuilder builder
      • isTreatWarningsAsErrors

        public java.lang.Boolean isTreatWarningsAsErrors()
        Get Treat warnings as errors.
        Returns:
        warningsAsErrors
      • setTreatMissingArrayIndexAsError

        public GestaltBuilder setTreatMissingArrayIndexAsError​(java.lang.Boolean treatMissingArrayIndexAsError)
        Treat missing array indexes as errors.
        Parameters:
        treatMissingArrayIndexAsError - treat missing array indexes as errors.
        Returns:
        GestaltBuilder builder
      • setTreatMissingValuesAsErrors

        public GestaltBuilder setTreatMissingValuesAsErrors​(java.lang.Boolean treatMissingValuesAsErrors)
        treat missing object values as errors.
        Parameters:
        treatMissingValuesAsErrors - treat missing object values as errors
        Returns:
        GestaltBuilder builder
      • setTreatNullValuesInClassAsErrors

        public GestaltBuilder setTreatNullValuesInClassAsErrors​(java.lang.Boolean treatNullValuesInClassAsErrors)
        Treat null values in classes after decoding as errors.
        Parameters:
        treatNullValuesInClassAsErrors - treat null values in classes after decoding as errors
        Returns:
        GestaltBuilder builder
      • useCacheDecorator

        public GestaltBuilder useCacheDecorator​(boolean useCacheDecorator)
        Add a cache layer to gestalt.
        Parameters:
        useCacheDecorator - use a cache decorator.
        Returns:
        GestaltBuilder builder
      • setDateDecoderFormat

        public GestaltBuilder setDateDecoderFormat​(java.time.format.DateTimeFormatter dateDecoderFormat)
        Set a date decoder format. Used to decode date times.
        Parameters:
        dateDecoderFormat - a date decoder format
        Returns:
        GestaltBuilder builder
      • getLogLevelForMissingValuesWhenDefaultOrOptional

        public java.lang.System.Logger.Level getLogLevelForMissingValuesWhenDefaultOrOptional()
        Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.
        Returns:
        Log level
      • setLogLevelForMissingValuesWhenDefaultOrOptional

        public GestaltBuilder setLogLevelForMissingValuesWhenDefaultOrOptional​(java.lang.System.Logger.Level logLevelForMissingValuesWhenDefaultOrOptional)
        Provide the log level when we log a message when a config is missing, but we provided a default, or it is Optional.
        Parameters:
        logLevelForMissingValuesWhenDefaultOrOptional - log level
        Returns:
        GestaltBuilder builder
      • setLocalDateTimeFormat

        public GestaltBuilder setLocalDateTimeFormat​(java.time.format.DateTimeFormatter localDateTimeFormat)
        Set a local date time format. Used to decode local date times.
        Parameters:
        localDateTimeFormat - a date decoder format
        Returns:
        GestaltBuilder builder
      • setLocalDateFormat

        public GestaltBuilder setLocalDateFormat​(java.time.format.DateTimeFormatter localDateFormat)
        Set a local date format. Used to decode local date.
        Parameters:
        localDateFormat - a local date decoder format
        Returns:
        GestaltBuilder builder
      • setSubstitutionOpeningToken

        public GestaltBuilder setSubstitutionOpeningToken​(java.lang.String substitutionOpeningToken)
        Set a Token that represents the opening of a string substitution.
        Parameters:
        substitutionOpeningToken - Token that represents the opening of a string substitution.
        Returns:
        GestaltBuilder builder
      • setSubstitutionClosingToken

        public GestaltBuilder setSubstitutionClosingToken​(java.lang.String substitutionClosingToken)
        Token that represents the closing of a string substitution.
        Parameters:
        substitutionClosingToken - a token that represents the closing of a string substitution.
        Returns:
        GestaltBuilder builder
      • getMaxSubstitutionNestedDepth

        public java.lang.Integer getMaxSubstitutionNestedDepth()
        Get the maximum string substitution nested depth. If you have nested or recursive substitutions that go deeper than this it will fail.
        Returns:
        the maximum string substitution nested depth.
      • setMaxSubstitutionNestedDepth

        public GestaltBuilder setMaxSubstitutionNestedDepth​(java.lang.Integer maxSubstitutionNestedDepth)
        Set the maximum string substitution nested depth. If you have nested or recursive substitutions that go deeper than this it will fail.
        Parameters:
        maxSubstitutionNestedDepth - the maximum string substitution nested depth.
        Returns:
        GestaltBuilder builder
      • getSubstitutionRegex

        public java.lang.String getSubstitutionRegex()
        the regex used to parse string substitutions. Must have a named capture group transform, key, and default, where the key is required and the transform and default are optional.
        Returns:
        the string substitution regex
      • setSubstitutionRegex

        public GestaltBuilder setSubstitutionRegex​(java.lang.String substitutionRegex)
        the regex used to parse string substitutions. Must have a named capture group transform, key, and default, where the key is required and the transform and default are optional.
        Parameters:
        substitutionRegex - the string substitution regex
        Returns:
        GestaltBuilder builder
      • getProxyDecoderMode

        public ProxyDecoderMode getProxyDecoderMode()
        Get the mode the for proxy decoder.
        Returns:
        the mode the for proxy decoder
      • setProxyDecoderMode

        public GestaltBuilder setProxyDecoderMode​(ProxyDecoderMode proxyDecoderMode)
        Set the mode the for proxy decoder.
        Parameters:
        proxyDecoderMode - the mode the for proxy decoder
        Returns:
        GestaltBuilder builder
      • getDefaultTags

        public Tags getDefaultTags()
        Get default tags to apply to all calls to get a configuration when tags are not provided.
        Returns:
        default tags
      • setDefaultTags

        public GestaltBuilder setDefaultTags​(Tags defaultTags)
        Set default tags to apply to all calls to get a configuration when tags are not provided.
        Parameters:
        defaultTags - Set of default tags to apply to all calls to get a configuration when tags are not provided.
        Returns:
        GestaltBuilder builder
      • dedupeDecoders

        protected java.util.List<Decoder<?>> dedupeDecoders()
        dedupe decoders and return the deduped list.
        Returns:
        deduped list of decoders.
      • dedupeConfigLoaders

        protected java.util.List<ConfigLoader> dedupeConfigLoaders()
        Dedupe the list of config loaders and return the deduped list.
        Returns:
        a list of deduped config loaders.