Package org.apache.sshd.common
Class PropertyResolverUtils
java.lang.Object
org.apache.sshd.common.PropertyResolverUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final NavigableSet
<String> static final String
static final NavigableSet
<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
getBoolean
(Map<String, ?> props, String name) static Boolean
getBoolean
(PropertyResolver resolver, String name) static boolean
getBooleanProperty
(Map<String, ?> props, String name, boolean defaultValue) static boolean
getBooleanProperty
(PropertyResolver resolver, String name, boolean defaultValue) static Charset
getCharset
(Map<String, ?> props, String name, Charset defaultValue) static Charset
getCharset
(PropertyResolver resolver, String name, Charset defaultValue) static Integer
getInteger
(Map<String, ?> props, String name) static Integer
getInteger
(PropertyResolver resolver, String name) static int
getIntProperty
(Map<String, ?> props, String name, int defaultValue) static int
getIntProperty
(PropertyResolver resolver, String name, int defaultValue) static Long
static Long
getLong
(PropertyResolver resolver, String name) static long
getLongProperty
(Map<String, ?> props, String name, long defaultValue) static long
getLongProperty
(PropertyResolver resolver, String name, long defaultValue) static Object
static Object
getObject
(PropertyResolver resolver, String name) static Object
getObject
(PropertyResolver resolver, String name, Object defaultValue) static String
static String
getString
(PropertyResolver resolver, String name) static String
getStringProperty
(Map<String, ?> props, String name, String defaultValue) static String
getStringProperty
(PropertyResolver resolver, String name, String defaultValue) static boolean
static Boolean
parseBoolean
(String value) resolvePropertiesSource
(PropertyResolver resolver, String name) Unwinds the resolvers hierarchy until found one with a non-null
value for the requested property or reached top.static Object
resolvePropertyValue
(Map<String, ?> props, String name) 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.static Boolean
Attempts to convert the object into aBoolean
value as follows:static boolean
static Charset
static <E extends Enum<E>>
EtoEnum
(Class<E> enumType, Object value, boolean failIfNoMatch, Collection<E> available) Converts an enumerated configuration value:static Integer
static int
static Long
static long
Converts a generic object value to along
if possible: If value isnull
the default is returned If value is aNumber
then itsNumber.longValue()
is returned Otherwise, the value'stoString()
is parsed as along
static PropertyResolver
toPropertyResolver
(Map<String, ?> props) Wraps aMap
into aPropertyResolver
so it can be used with these utilitiesstatic PropertyResolver
toPropertyResolver
(Map<String, ?> props, PropertyResolver parent) static PropertyResolver
toPropertyResolver
(Properties props) static Object
updateProperty
(Map<String, Object> props, String name, boolean value) static Object
updateProperty
(Map<String, Object> props, String name, int value) static Object
updateProperty
(Map<String, Object> props, String name, long value) static Object
static Object
updateProperty
(PropertyResolver resolver, String name, boolean value) static Object
updateProperty
(PropertyResolver resolver, String name, int value) static Object
updateProperty
(PropertyResolver resolver, String name, long value) static Object
updateProperty
(PropertyResolver resolver, String name, Object value)
-
Field Details
-
NONE_VALUE
- See Also:
-
TRUE_VALUES
-
FALSE_VALUES
-
-
Constructor Details
-
PropertyResolverUtils
private PropertyResolverUtils()
-
-
Method Details
-
isNoneValue
- Parameters:
v
- Value to examine- Returns:
true
if equals to "none" - case insensitive
-
getLongProperty
- Parameters:
resolver
- ThePropertyResolver
instance - ignored ifnull
name
- The property namedefaultValue
- 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
-
toLong
Converts a generic object value to along
if possible:- If value is
null
the default is returned - If value is a
Number
then itsNumber.longValue()
is returned - Otherwise, the value's
toString()
is parsed as along
- Parameters:
value
- The resolved value - may benull
defaultValue
- The default to use ifnull
resolved value- Returns:
- The resolved value
- Throws:
NumberFormatException
- if malformed value- See Also:
- If value is
-
getLong
- Parameters:
resolver
- ThePropertyResolver
instance - ignored ifnull
name
- The property name- Returns:
- The
Long
value ornull
if property not found - Throws:
NumberFormatException
- if malformed value- See Also:
-
getLong
-
toLong
Converts a generic object into aLong
:- If the value is
null
then returnsnull
. - If the value is already a
Long
then it is returned as such. - If value is a
Number
then itsNumber.longValue()
is wrapped as aLong
- Otherwise, the value's
toString()
is parsed as aLong
- Parameters:
value
- The resolved value - may benull
- Returns:
- The
Long
value ornull
if property not found - Throws:
NumberFormatException
- if malformed value- See Also:
- If the value is
-
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 returnnull
- 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 typevalue
- The configured value - ignored ifnull
failIfNoMatch
- Whether to fail if no matching name foundavailable
- The available values to compare the name- Returns:
- The matching enumerated value -
null
if no match found - Throws:
IllegalArgumentException
- If value is neithernull
, nor the enumerated type nor aCharSequence
NoSuchElementException
- If no matching string name found and failIfNoMatch istrue
- If value is
-
updateProperty
-
updateProperty
-
getIntProperty
-
getIntProperty
-
toInteger
-
getInteger
-
getInteger
-
toInteger
-
updateProperty
-
updateProperty
-
getBooleanProperty
public static boolean getBooleanProperty(PropertyResolver resolver, String name, boolean defaultValue) -
getBooleanProperty
-
toBoolean
- Parameters:
value
- The value to convertdefaultValue
- The default value to return if value isnull
or and empty string, then returns the default value.- Returns:
- The resolved value
- See Also:
-
getBoolean
-
getBoolean
-
toBoolean
Attempts to convert the object into a
Boolean
value as follows:- If
null
or an empty string then returnnull
. - If already a
Boolean
then return as-is - If a
CharSequence
then invokeparseBoolean(String)
- Otherwise, throws an
UnsupportedOperationException
- Parameters:
value
- The value to be converted- Returns:
- The result -
null
ifnull
or an empty string - Throws:
UnsupportedOperationException
- If value cannot be converted to a boolean - e.g., a number.- See Also:
- If
-
parseBoolean
- Parameters:
value
- The value to parse- Returns:
- The result -
null
if value isnull
/empty - Throws:
IllegalArgumentException
- If non-empty string that does not match (case insensitive) either of the known values for boolean.
-
updateProperty
-
updateProperty
-
getStringProperty
- Parameters:
resolver
- ThePropertyResolver
to use - ignored ifnull
name
- The property namedefaultValue
- The default value to return if property not set or empty- Returns:
- The set value (if not
null
/empty) or default one
-
getStringProperty
-
getCharset
-
getCharset
-
toCharset
-
getString
-
getString
-
getObject
-
getObject
-
getObject
-
resolvePropertyValue
-
updateProperty
- Parameters:
resolver
- ThePropertyResolver
instancename
- The property namevalue
- The new value - ifnull
or an emptyCharSequence
the property is removed- Returns:
- The previous value -
null
if none
-
updateProperty
-
resolvePropertyValue
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
- ThePropertyResolver
to start from - ignored ifnull
name
- The requested property name- Returns:
- The found value or
null
-
resolvePropertiesSource
Unwinds the resolvers hierarchy until found one with a non-null
value for the requested property or reached top.- Parameters:
resolver
- ThePropertyResolver
to start from - ignored ifnull
name
- The requested property name- Returns:
- The found properties
Map
ornull
-
toPropertyResolver
-
toPropertyResolver
Wraps aMap
into aPropertyResolver
so it can be used with these utilities- Parameters:
props
- The properties map - may benull
/empty if no properties are updated- Returns:
- The resolver wrapper
-
toPropertyResolver
-