Class PropertyResolverUtils

    • Method Detail

      • isNoneValue

        public static boolean isNoneValue​(String v)
        Parameters:
        v - Value to examine
        Returns:
        true if equals to "none" - case insensitive
      • getLongProperty

        public static long getLongProperty​(PropertyResolver resolver,
                                           String name,
                                           long defaultValue)
        Parameters:
        resolver - The PropertyResolver instance - ignored if null
        name - The property name
        defaultValue - The default value to return if the specified property does not exist in the properties map
        Returns:
        The resolved property
        Throws:
        NumberFormatException - if malformed value
        See Also:
        toLong(Object, long)
      • getLongProperty

        public static long getLongProperty​(Map<String,​?> props,
                                           String name,
                                           long defaultValue)
      • toLong

        public static long toLong​(Object value,
                                  long defaultValue)
        Converts a generic object value to a long if possible:
        • If value is null the default is returned
        • If value is a Number then its Number.longValue() is returned
        • Otherwise, the value's toString() is parsed as a long
        Parameters:
        value - The resolved value - may be null
        defaultValue - The default to use if null resolved value
        Returns:
        The resolved value
        Throws:
        NumberFormatException - if malformed value
        See Also:
        Long.parseLong(String)
      • toEnum

        public static <E extends Enum<E>> E toEnum​(Class<E> enumType,
                                                   Object value,
                                                   boolean failIfNoMatch,
                                                   Collection<E> available)
        Converts an enumerated configuration value:

        • If value is null then return null
        • If value already of the expected type then simply cast and return it.
        • If value is a CharSequence then convert it to a string and look for a matching enumerated value name - case insensitive.
        • >
        Type Parameters:
        E - Type of enumerated value
        Parameters:
        enumType - The enumerated class type
        value - The configured value - ignored if null
        failIfNoMatch - Whether to fail if no matching name found
        available - The available values to compare the name
        Returns:
        The matching enumerated value - null if no match found
        Throws:
        IllegalArgumentException - If value is neither null, nor the enumerated type nor a CharSequence
        NoSuchElementException - If no matching string name found and failIfNoMatch is true
      • getIntProperty

        public static int getIntProperty​(PropertyResolver resolver,
                                         String name,
                                         int defaultValue)
      • getIntProperty

        public static int getIntProperty​(Map<String,​?> props,
                                         String name,
                                         int defaultValue)
      • toInteger

        public static int toInteger​(Object value,
                                    int defaultValue)
      • getBooleanProperty

        public static boolean getBooleanProperty​(PropertyResolver resolver,
                                                 String name,
                                                 boolean defaultValue)
      • getBooleanProperty

        public static boolean getBooleanProperty​(Map<String,​?> props,
                                                 String name,
                                                 boolean defaultValue)
      • toBoolean

        public static boolean toBoolean​(Object value,
                                        boolean defaultValue)
        Parameters:
        value - The value to convert
        defaultValue - The default value to return if value is null or and empty string, then returns the default value.
        Returns:
        The resolved value
        See Also:
        toBoolean(Object)
      • parseBoolean

        public static Boolean parseBoolean​(String value)
        Converts a string to a Boolean value by looking for it in either the TRUE_VALUES or FALSE_VALUES
        Parameters:
        value - The value to parse
        Returns:
        The result - null if value is null/empty
        Throws:
        IllegalArgumentException - If non-empty string that does not match (case insensitive) either of the known values for boolean.
      • getStringProperty

        public static String getStringProperty​(PropertyResolver resolver,
                                               String name,
                                               String defaultValue)
        Parameters:
        resolver - The PropertyResolver to use - ignored if null
        name - The property name
        defaultValue - The default value to return if property not set or empty
        Returns:
        The set value (if not null/empty) or default one
      • resolvePropertyValue

        public static Object resolvePropertyValue​(Map<String,​?> props,
                                                  String name)
      • updateProperty

        public static Object updateProperty​(PropertyResolver resolver,
                                            String name,
                                            Object value)
        Parameters:
        resolver - The PropertyResolver instance
        name - The property name
        value - The new value - if null or an empty CharSequence the property is removed
        Returns:
        The previous value - null if none
      • resolvePropertyValue

        public static Object resolvePropertyValue​(PropertyResolver resolver,
                                                  String name)
        Unwinds the resolvers hierarchy until found one with a non-null value for the requested property or reached top. If still no value found and the key starts with "org.apache.sshd" then the system properties are also consulted
        Parameters:
        resolver - The PropertyResolver to start from - ignored if null
        name - The requested property name
        Returns:
        The found value or null
      • resolvePropertiesSource

        public static Map<String,​Object> resolvePropertiesSource​(PropertyResolver resolver,
                                                                       String name)
        Unwinds the resolvers hierarchy until found one with a non-null value for the requested property or reached top.
        Parameters:
        resolver - The PropertyResolver to start from - ignored if null
        name - The requested property name
        Returns:
        The found properties Map or null
      • toPropertyResolver

        public static PropertyResolver toPropertyResolver​(Map<String,​?> props)
        Wraps a Map into a PropertyResolver so it can be used with these utilities
        Parameters:
        props - The properties map - may be null/empty if no properties are updated
        Returns:
        The resolver wrapper