Class ConfigurationHelper


  • public final class ConfigurationHelper
    extends Object
    Collection of helper methods for dealing with configuration settings.
    • Method Detail

      • getString

        public static String getString​(String name,
                                       Map values)
        Get the config value as a String
        Parameters:
        name - The config setting name.
        values - The map of config values
        Returns:
        The value, or null if not found
      • getString

        public static String getString​(String name,
                                       Map values,
                                       String defaultValue)
        Get the config value as a String
        Parameters:
        name - The config setting name.
        values - The map of config values
        defaultValue - The default value to use if not found
        Returns:
        The value.
      • getString

        public static String getString​(String name,
                                       Map<?,​?> values,
                                       Supplier<String> defaultValueSupplier)
        Get the config value as a String
        Parameters:
        name - The config setting name.
        values - The map of config values
        Returns:
        The value, or null if not found
      • getString

        public static String getString​(String name,
                                       Map values,
                                       String defaultValue,
                                       String... otherSupportedValues)
        Get the config value as a String.
        Parameters:
        name - The config setting name.
        values - The map of config parameters.
        defaultValue - The default value to use if not found.
        otherSupportedValues - List of other supported values. Does not need to contain the default one.
        Returns:
        The value.
        Throws:
        ConfigurationException - Unsupported value provided.
      • getBoolean

        public static boolean getBoolean​(String name,
                                         Map values)
        Get the config value as a boolean (default of false)
        Parameters:
        name - The config setting name.
        values - The map of config values
        Returns:
        The value.
      • getBoolean

        public static boolean getBoolean​(String name,
                                         Map values,
                                         boolean defaultValue)
        Get the config value as a boolean.
        Parameters:
        name - The config setting name.
        values - The map of config values
        defaultValue - The default value to use if not found
        Returns:
        The value.
      • toBoolean

        public static Boolean toBoolean​(Object value,
                                        boolean defaultValue)
      • getBooleanWrapper

        public static Boolean getBooleanWrapper​(String name,
                                                Map values,
                                                Boolean defaultValue)
        Get the config value as a boolean (default of false)
        Parameters:
        name - The config setting name.
        values - The map of config values
        Returns:
        The value.
      • getInt

        public static int getInt​(String name,
                                 Map values,
                                 int defaultValue)
        Get the config value as an int
        Parameters:
        name - The config setting name.
        values - The map of config values
        defaultValue - The default value to use if not found
        Returns:
        The value.
      • getInteger

        public static Integer getInteger​(String name,
                                         Map values)
        Get the config value as an Integer
        Parameters:
        name - The config setting name.
        values - The map of config values
        Returns:
        The value, or null if not found
      • getLong

        public static long getLong​(String name,
                                   Map values,
                                   int defaultValue)
      • clone

        public static Map clone​(Map<?,​?> configurationValues)
        Make a clone of the configuration values.
        Parameters:
        configurationValues - The config values to clone
        Returns:
        The clone
      • maskOut

        public static Properties maskOut​(Properties props,
                                         String key)
        replace a property by a starred version
        Parameters:
        props - properties to check
        key - property to mask
        Returns:
        cloned and masked properties
      • extractPropertyValue

        public static String extractPropertyValue​(String propertyName,
                                                  Properties properties)
        Extract a property value by name from the given properties object.

        Both null and empty string are viewed as the same, and return null.

        Parameters:
        propertyName - The name of the property for which to extract value
        properties - The properties object
        Returns:
        The property value; may be null.
      • extractPropertyValue

        public static String extractPropertyValue​(String propertyName,
                                                  Map properties)
        Extract a property value by name from the given properties object.

        Both null and empty string are viewed as the same, and return null.

        Parameters:
        propertyName - The name of the property for which to extract value
        properties - The properties object
        Returns:
        The property value; may be null.
      • toMap

        public static Map toMap​(String propertyName,
                                String delim,
                                Properties properties)
        Constructs a map from a property value.

        The exact behavior here is largely dependant upon what is passed in as the delimiter.

        Parameters:
        propertyName - The name of the property for which to retrieve value
        delim - The string defining tokens used as both entry and key/value delimiters.
        properties - The properties object
        Returns:
        The resulting map; never null, though perhaps empty.
        See Also:
        extractPropertyValue(String, Properties)
      • toMap

        public static Map toMap​(String propertyName,
                                String delim,
                                Map properties)
        Constructs a map from a property value.

        The exact behavior here is largely dependant upon what is passed in as the delimiter.

        Parameters:
        propertyName - The name of the property for which to retrieve value
        delim - The string defining tokens used as both entry and key/value delimiters.
        properties - The properties object
        Returns:
        The resulting map; never null, though perhaps empty.
        See Also:
        extractPropertyValue(String, Properties)
      • toStringArray

        public static String[] toStringArray​(String stringForm,
                                             String delim)
        Convert a string to an array of strings. The assumption is that the individual array elements are delimited in the source stringForm param by the delim param.
        Parameters:
        stringForm - The string form of the string array.
        delim - The delimiter used to separate individual array elements.
        Returns:
        The array; never null, though may be empty.
      • resolvePlaceHolders

        public static void resolvePlaceHolders​(Map<?,​?> configurationValues)
        Handles interpolation processing for all entries in a properties object.
        Parameters:
        configurationValues - The configuration map.
      • resolvePlaceHolder

        public static String resolvePlaceHolder​(String property)
        Handles interpolation processing for a single property.
        Parameters:
        property - The property value to be processed for interpolation.
        Returns:
        The (possibly) interpolated property value.
      • getPreferredSqlTypeCodeForBoolean

        public static int getPreferredSqlTypeCodeForBoolean​(StandardServiceRegistry serviceRegistry)
      • getPreferredSqlTypeCodeForDuration

        public static int getPreferredSqlTypeCodeForDuration​(StandardServiceRegistry serviceRegistry)
      • getPreferredSqlTypeCodeForUuid

        public static int getPreferredSqlTypeCodeForUuid​(StandardServiceRegistry serviceRegistry)
      • getPreferredSqlTypeCodeForInstant

        public static int getPreferredSqlTypeCodeForInstant​(StandardServiceRegistry serviceRegistry)
      • getPreferredSqlTypeCodeForArray

        public static int getPreferredSqlTypeCodeForArray​(StandardServiceRegistry serviceRegistry)