Class DefaultConfigProperties

  • All Implemented Interfaces:
    ConfigProperties

    public final class DefaultConfigProperties
    extends java.lang.Object
    implements ConfigProperties
    Properties are normalized to The properties for both of these will be normalized to be all lower case, dashses are replaces with periods, and environment variable underscores are replaces with periods.

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.String> config  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DefaultConfigProperties​(DefaultConfigProperties previousProperties, java.util.Map<java.lang.String,​java.lang.String> overrides)  
      private DefaultConfigProperties​(java.util.Map<?,​?> systemProperties, java.util.Map<java.lang.String,​java.lang.String> environmentVariables, java.util.Map<java.lang.String,​java.lang.String> defaultProperties)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static DefaultConfigProperties create​(java.util.Map<java.lang.String,​java.lang.String> defaultProperties)
      Creates a DefaultConfigProperties by merging system properties, environment variables, and the defaultProperties.
      static DefaultConfigProperties createFromMap​(java.util.Map<java.lang.String,​java.lang.String> properties)
      Create a DefaultConfigProperties from the properties, ignoring system properties and environment variables.
      private static java.util.List<java.lang.String> filterBlanksAndNulls​(java.lang.String[] values)  
      java.lang.Boolean getBoolean​(java.lang.String name)
      Returns a boolean-valued configuration property.
      java.lang.Double getDouble​(java.lang.String name)
      Returns a double-valued configuration property.
      java.time.Duration getDuration​(java.lang.String name)
      Returns a duration property from the map, or null if it cannot be found or it has a wrong type.
      private static java.util.concurrent.TimeUnit getDurationUnit​(java.lang.String unitString)
      Returns the TimeUnit associated with a unit string.
      java.lang.Integer getInt​(java.lang.String name)
      Returns an Integer-valued configuration property.
      java.util.List<java.lang.String> getList​(java.lang.String name)
      Returns a list-valued configuration property.
      java.lang.Long getLong​(java.lang.String name)
      Returns a Long-valued configuration property.
      java.util.Map<java.lang.String,​java.lang.String> getMap​(java.lang.String name)
      Returns a Map configuration property.
      static java.util.Set<java.lang.String> getSet​(ConfigProperties config, java.lang.String name)
      Returns ConfigProperties.getList(String) as a Set after validating there are no duplicate entries.
      java.lang.String getString​(java.lang.String name)
      Returns a string-valued configuration property.
      private static java.lang.String getUnitString​(java.lang.String rawValue)
      Fragments the 'units' portion of a config value from the 'value' portion.
      private static ConfigurationException newInvalidPropertyException​(java.lang.String name, java.lang.String value, java.lang.String type)  
      DefaultConfigProperties withOverrides​(java.util.Map<java.lang.String,​java.lang.String> overrides)
      Return a new DefaultConfigProperties by overriding the previousProperties with the overrides.
      • Methods inherited from class java.lang.Object

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

      • config

        private final java.util.Map<java.lang.String,​java.lang.String> config
    • Constructor Detail

      • DefaultConfigProperties

        private DefaultConfigProperties​(java.util.Map<?,​?> systemProperties,
                                        java.util.Map<java.lang.String,​java.lang.String> environmentVariables,
                                        java.util.Map<java.lang.String,​java.lang.String> defaultProperties)
      • DefaultConfigProperties

        private DefaultConfigProperties​(DefaultConfigProperties previousProperties,
                                        java.util.Map<java.lang.String,​java.lang.String> overrides)
    • Method Detail

      • create

        public static DefaultConfigProperties create​(java.util.Map<java.lang.String,​java.lang.String> defaultProperties)
        Creates a DefaultConfigProperties by merging system properties, environment variables, and the defaultProperties.

        Environment variables take priority over defaultProperties. System properties take priority over environment variables.

      • createFromMap

        public static DefaultConfigProperties createFromMap​(java.util.Map<java.lang.String,​java.lang.String> properties)
        Create a DefaultConfigProperties from the properties, ignoring system properties and environment variables.
      • getString

        @Nullable
        public java.lang.String getString​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a string-valued configuration property.
        Specified by:
        getString in interface ConfigProperties
        Returns:
        null if the property has not been configured.
      • getBoolean

        @Nullable
        public java.lang.Boolean getBoolean​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a boolean-valued configuration property. Implementations should use the same rules as Boolean.parseBoolean(String) for handling the values.
        Specified by:
        getBoolean in interface ConfigProperties
        Returns:
        null if the property has not been configured.
      • getInt

        @Nullable
        public java.lang.Integer getInt​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns an Integer-valued configuration property.
        Specified by:
        getInt in interface ConfigProperties
        Returns:
        null if the property has not been configured.
      • getLong

        @Nullable
        public java.lang.Long getLong​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a Long-valued configuration property.
        Specified by:
        getLong in interface ConfigProperties
        Returns:
        null if the property has not been configured.
      • getDouble

        @Nullable
        public java.lang.Double getDouble​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a double-valued configuration property.
        Specified by:
        getDouble in interface ConfigProperties
        Returns:
        null if the property has not been configured.
      • getDuration

        @Nullable
        public java.time.Duration getDuration​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a duration property from the map, or null if it cannot be found or it has a wrong type.

        Durations can be of the form "{number}{unit}", where unit is one of:

        • ms
        • s
        • m
        • h
        • d

        If no unit is specified, milliseconds is the assumed duration unit.

        Specified by:
        getDuration in interface ConfigProperties
        Parameters:
        name - The property name
        Returns:
        the Duration value of the property, null if the property cannot be found.
      • getList

        public java.util.List<java.lang.String> getList​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a list-valued configuration property. The format of the original value must be comma-separated. Empty values will be removed.
        Specified by:
        getList in interface ConfigProperties
        Returns:
        an empty list if the property has not been configured.
      • getMap

        public java.util.Map<java.lang.String,​java.lang.String> getMap​(java.lang.String name)
        Description copied from interface: ConfigProperties
        Returns a Map configuration property. The format of the original value must be comma-separated for each key, with an '=' separating the key and value. For instance, service.name=Greatest Service,host.name=localhost. Empty values will be removed.
        Specified by:
        getMap in interface ConfigProperties
        Returns:
        an empty map if the property has not been configured.
      • newInvalidPropertyException

        private static ConfigurationException newInvalidPropertyException​(java.lang.String name,
                                                                          java.lang.String value,
                                                                          java.lang.String type)
      • filterBlanksAndNulls

        private static java.util.List<java.lang.String> filterBlanksAndNulls​(java.lang.String[] values)
      • getDurationUnit

        private static java.util.concurrent.TimeUnit getDurationUnit​(java.lang.String unitString)
        Returns the TimeUnit associated with a unit string. Defaults to milliseconds.
      • getUnitString

        private static java.lang.String getUnitString​(java.lang.String rawValue)
        Fragments the 'units' portion of a config value from the 'value' portion.

        E.g. "1ms" would return the string "ms".