Class PropertyResolverUtils

java.lang.Object
org.apache.sshd.common.PropertyResolverUtils

public final class PropertyResolverUtils extends Object
  • Field Details

  • Constructor Details

    • PropertyResolverUtils

      private PropertyResolverUtils()
  • Method Details

    • 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:
    • 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:
    • getLong

      public static Long getLong(PropertyResolver resolver, String name)
      Parameters:
      resolver - The PropertyResolver instance - ignored if null
      name - The property name
      Returns:
      The Long value or null if property not found
      Throws:
      NumberFormatException - if malformed value
      See Also:
    • getLong

      public static Long getLong(Map<String,?> props, String name)
    • toLong

      public static Long toLong(Object value)
      Converts a generic object into a Long:
      • If the value is null then returns null.
      • If the value is already a Long then it is returned as such.
      • If value is a Number then its Number.longValue() is wrapped as a Long
      • Otherwise, the value's toString() is parsed as a Long
      Parameters:
      value - The resolved value - may be null
      Returns:
      The Long value or null if property not found
      Throws:
      NumberFormatException - if malformed value
      See Also:
    • 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
    • updateProperty

      public static Object updateProperty(PropertyResolver resolver, String name, long value)
    • updateProperty

      public static Object updateProperty(Map<String,Object> props, String name, long value)
    • 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)
    • getInteger

      public static Integer getInteger(PropertyResolver resolver, String name)
    • getInteger

      public static Integer getInteger(Map<String,?> props, String name)
    • toInteger

      public static Integer toInteger(Object value)
    • updateProperty

      public static Object updateProperty(PropertyResolver resolver, String name, int value)
    • updateProperty

      public static Object updateProperty(Map<String,Object> props, String name, int value)
    • 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:
    • getBoolean

      public static Boolean getBoolean(PropertyResolver resolver, String name)
    • getBoolean

      public static Boolean getBoolean(Map<String,?> props, String name)
    • toBoolean

      public static Boolean toBoolean(Object value)

      Attempts to convert the object into a Boolean value as follows:


      Parameters:
      value - The value to be converted
      Returns:
      The result - null if null or an empty string
      Throws:
      UnsupportedOperationException - If value cannot be converted to a boolean - e.g., a number.
      See Also:
    • 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.
    • updateProperty

      public static Object updateProperty(PropertyResolver resolver, String name, boolean value)
    • updateProperty

      public static Object updateProperty(Map<String,Object> props, String name, boolean value)
    • 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
    • getStringProperty

      public static String getStringProperty(Map<String,?> props, String name, String defaultValue)
    • getCharset

      public static Charset getCharset(PropertyResolver resolver, String name, Charset defaultValue)
    • getCharset

      public static Charset getCharset(Map<String,?> props, String name, Charset defaultValue)
    • toCharset

      public static Charset toCharset(Object value)
    • getString

      public static String getString(PropertyResolver resolver, String name)
    • getString

      public static String getString(Map<String,?> props, String name)
    • getObject

      public static Object getObject(PropertyResolver resolver, String name)
    • getObject

      public static Object getObject(PropertyResolver resolver, String name, Object defaultValue)
    • getObject

      public static Object getObject(Map<String,?> props, String name)
    • 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
    • updateProperty

      public static Object updateProperty(Map<String,Object> props, String name, Object value)
    • 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(Properties props)
    • 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
    • toPropertyResolver

      public static PropertyResolver toPropertyResolver(Map<String,?> props, PropertyResolver parent)