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 Stringstatic final NavigableSet<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BooleangetBoolean(Map<String, ?> props, String name) static BooleangetBoolean(PropertyResolver resolver, String name) static booleangetBooleanProperty(Map<String, ?> props, String name, boolean defaultValue) static booleangetBooleanProperty(PropertyResolver resolver, String name, boolean defaultValue) static CharsetgetCharset(Map<String, ?> props, String name, Charset defaultValue) static CharsetgetCharset(PropertyResolver resolver, String name, Charset defaultValue) static IntegergetInteger(Map<String, ?> props, String name) static IntegergetInteger(PropertyResolver resolver, String name) static intgetIntProperty(Map<String, ?> props, String name, int defaultValue) static intgetIntProperty(PropertyResolver resolver, String name, int defaultValue) static Longstatic LonggetLong(PropertyResolver resolver, String name) static longgetLongProperty(Map<String, ?> props, String name, long defaultValue) static longgetLongProperty(PropertyResolver resolver, String name, long defaultValue) static Objectstatic ObjectgetObject(PropertyResolver resolver, String name) static ObjectgetObject(PropertyResolver resolver, String name, Object defaultValue) static Stringstatic StringgetString(PropertyResolver resolver, String name) static StringgetStringProperty(Map<String, ?> props, String name, String defaultValue) static StringgetStringProperty(PropertyResolver resolver, String name, String defaultValue) static booleanstatic BooleanparseBoolean(String value) resolvePropertiesSource(PropertyResolver resolver, String name) Unwinds the resolvers hierarchy until found one with a non-nullvalue for the requested property or reached top.static ObjectresolvePropertyValue(Map<String, ?> props, String name) static ObjectresolvePropertyValue(PropertyResolver resolver, String name) Unwinds the resolvers hierarchy until found one with a non-nullvalue for the requested property or reached top.static BooleanAttempts to convert the object into aBooleanvalue as follows:static booleanstatic Charsetstatic <E extends Enum<E>>
EtoEnum(Class<E> enumType, Object value, boolean failIfNoMatch, Collection<E> available) Converts an enumerated configuration value:static Integerstatic intstatic Longstatic longConverts a generic object value to alongif possible: If value isnullthe default is returned If value is aNumberthen itsNumber.longValue()is returned Otherwise, the value'stoString()is parsed as alongstatic PropertyResolvertoPropertyResolver(Map<String, ?> props) Wraps aMapinto aPropertyResolverso it can be used with these utilitiesstatic PropertyResolvertoPropertyResolver(Map<String, ?> props, PropertyResolver parent) static PropertyResolvertoPropertyResolver(Properties props) static ObjectupdateProperty(Map<String, Object> props, String name, boolean value) static ObjectupdateProperty(Map<String, Object> props, String name, int value) static ObjectupdateProperty(Map<String, Object> props, String name, long value) static Objectstatic ObjectupdateProperty(PropertyResolver resolver, String name, boolean value) static ObjectupdateProperty(PropertyResolver resolver, String name, int value) static ObjectupdateProperty(PropertyResolver resolver, String name, long value) static ObjectupdateProperty(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:
trueif equals to "none" - case insensitive
-
getLongProperty
- Parameters:
resolver- ThePropertyResolverinstance - ignored ifnullname- 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 alongif possible:- If value is
nullthe default is returned - If value is a
Numberthen itsNumber.longValue()is returned - Otherwise, the value's
toString()is parsed as along
- Parameters:
value- The resolved value - may benulldefaultValue- The default to use ifnullresolved value- Returns:
- The resolved value
- Throws:
NumberFormatException- if malformed value- See Also:
- If value is
-
getLong
- Parameters:
resolver- ThePropertyResolverinstance - ignored ifnullname- The property name- Returns:
- The
Longvalue ornullif property not found - Throws:
NumberFormatException- if malformed value- See Also:
-
getLong
-
toLong
Converts a generic object into aLong:- If the value is
nullthen returnsnull. - If the value is already a
Longthen it is returned as such. - If value is a
Numberthen itsNumber.longValue()is wrapped as aLong - Otherwise, the value's
toString()is parsed as aLong
- Parameters:
value- The resolved value - may benull- Returns:
- The
Longvalue ornullif 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
nullthen returnnull - If value already of the expected type then simply cast and return it.
- If value is a
CharSequencethen 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 ifnullfailIfNoMatch- Whether to fail if no matching name foundavailable- The available values to compare the name- Returns:
- The matching enumerated value -
nullif no match found - Throws:
IllegalArgumentException- If value is neithernull, nor the enumerated type nor aCharSequenceNoSuchElementException- 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 isnullor and empty string, then returns the default value.- Returns:
- The resolved value
- See Also:
-
getBoolean
-
getBoolean
-
toBoolean
Attempts to convert the object into a
Booleanvalue as follows:- If
nullor an empty string then returnnull. - If already a
Booleanthen return as-is - If a
CharSequencethen invokeparseBoolean(String) - Otherwise, throws an
UnsupportedOperationException
- Parameters:
value- The value to be converted- Returns:
- The result -
nullifnullor 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 -
nullif 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- ThePropertyResolverto use - ignored ifnullname- 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- ThePropertyResolverinstancename- The property namevalue- The new value - ifnullor an emptyCharSequencethe property is removed- Returns:
- The previous value -
nullif none
-
updateProperty
-
resolvePropertyValue
Unwinds the resolvers hierarchy until found one with a non-nullvalue 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- ThePropertyResolverto start from - ignored ifnullname- The requested property name- Returns:
- The found value or
null
-
resolvePropertiesSource
Unwinds the resolvers hierarchy until found one with a non-nullvalue for the requested property or reached top.- Parameters:
resolver- ThePropertyResolverto start from - ignored ifnullname- The requested property name- Returns:
- The found properties
Mapornull
-
toPropertyResolver
-
toPropertyResolver
Wraps aMapinto aPropertyResolverso 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
-