Package org.apache.sshd.common
Class PropertyResolverUtils
- java.lang.Object
-
- org.apache.sshd.common.PropertyResolverUtils
-
public final class PropertyResolverUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.NavigableSet<java.lang.String>FALSE_VALUESstatic java.lang.StringNONE_VALUEstatic java.util.NavigableSet<java.lang.String>TRUE_VALUES
-
Constructor Summary
Constructors Modifier Constructor Description privatePropertyResolverUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.BooleangetBoolean(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.BooleangetBoolean(PropertyResolver resolver, java.lang.String name)static booleangetBooleanProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, boolean defaultValue)static booleangetBooleanProperty(PropertyResolver resolver, java.lang.String name, boolean defaultValue)static java.nio.charset.CharsetgetCharset(java.util.Map<java.lang.String,?> props, java.lang.String name, java.nio.charset.Charset defaultValue)static java.nio.charset.CharsetgetCharset(PropertyResolver resolver, java.lang.String name, java.nio.charset.Charset defaultValue)static java.lang.IntegergetInteger(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.IntegergetInteger(PropertyResolver resolver, java.lang.String name)static intgetIntProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, int defaultValue)static intgetIntProperty(PropertyResolver resolver, java.lang.String name, int defaultValue)static java.lang.LonggetLong(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.LonggetLong(PropertyResolver resolver, java.lang.String name)static longgetLongProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, long defaultValue)static longgetLongProperty(PropertyResolver resolver, java.lang.String name, long defaultValue)static java.lang.ObjectgetObject(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.ObjectgetObject(PropertyResolver resolver, java.lang.String name)static java.lang.ObjectgetObject(PropertyResolver resolver, java.lang.String name, java.lang.Object defaultValue)static java.lang.StringgetString(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.StringgetString(PropertyResolver resolver, java.lang.String name)static java.lang.StringgetStringProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, java.lang.String defaultValue)static java.lang.StringgetStringProperty(PropertyResolver resolver, java.lang.String name, java.lang.String defaultValue)static booleanisNoneValue(java.lang.String v)static java.lang.BooleanparseBoolean(java.lang.String value)static java.util.Map<java.lang.String,java.lang.Object>resolvePropertiesSource(PropertyResolver resolver, java.lang.String name)Unwinds the resolvers hierarchy until found one with a non-nullvalue for the requested property or reached top.static java.lang.ObjectresolvePropertyValue(java.util.Map<java.lang.String,?> props, java.lang.String name)static java.lang.ObjectresolvePropertyValue(PropertyResolver resolver, java.lang.String name)Unwinds the resolvers hierarchy until found one with a non-nullvalue for the requested property or reached top.static java.lang.BooleantoBoolean(java.lang.Object value)Attempts to convert the object into aBooleanvalue as follows:static booleantoBoolean(java.lang.Object value, boolean defaultValue)static java.nio.charset.CharsettoCharset(java.lang.Object value)static <E extends java.lang.Enum<E>>
EtoEnum(java.lang.Class<E> enumType, java.lang.Object value, boolean failIfNoMatch, java.util.Collection<E> available)Converts an enumerated configuration value:static java.lang.IntegertoInteger(java.lang.Object value)static inttoInteger(java.lang.Object value, int defaultValue)static java.lang.LongtoLong(java.lang.Object value)Converts a generic object into aLong: If the value isnullthen returnsnull. If the value is already aLongthen it is returned as such. If value is aNumberthen itsNumber.longValue()is wrapped as aLongOtherwise, the value'stoString()is parsed as aLongstatic longtoLong(java.lang.Object value, long defaultValue)Converts 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(java.util.Map<java.lang.String,?> props)Wraps aMapinto aPropertyResolverso it can be used with these utilitiesstatic PropertyResolvertoPropertyResolver(java.util.Map<java.lang.String,?> props, PropertyResolver parent)static PropertyResolvertoPropertyResolver(java.util.Properties props)static java.lang.ObjectupdateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, boolean value)static java.lang.ObjectupdateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, int value)static java.lang.ObjectupdateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, long value)static java.lang.ObjectupdateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, java.lang.Object value)static java.lang.ObjectupdateProperty(PropertyResolver resolver, java.lang.String name, boolean value)static java.lang.ObjectupdateProperty(PropertyResolver resolver, java.lang.String name, int value)static java.lang.ObjectupdateProperty(PropertyResolver resolver, java.lang.String name, long value)static java.lang.ObjectupdateProperty(PropertyResolver resolver, java.lang.String name, java.lang.Object value)
-
-
-
Field Detail
-
NONE_VALUE
public static final java.lang.String NONE_VALUE
- See Also:
- Constant Field Values
-
TRUE_VALUES
public static final java.util.NavigableSet<java.lang.String> TRUE_VALUES
-
FALSE_VALUES
public static final java.util.NavigableSet<java.lang.String> FALSE_VALUES
-
-
Method Detail
-
isNoneValue
public static boolean isNoneValue(java.lang.String v)
- Parameters:
v- Value to examine- Returns:
trueif equals to "none" - case insensitive
-
getLongProperty
public static long getLongProperty(PropertyResolver resolver, java.lang.String name, long defaultValue)
- 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:
java.lang.NumberFormatException- if malformed value- See Also:
toLong(Object, long)
-
getLongProperty
public static long getLongProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, long defaultValue)
-
toLong
public static long toLong(java.lang.Object value, long defaultValue)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:
java.lang.NumberFormatException- if malformed value- See Also:
Long.parseLong(String)
- If value is
-
getLong
public static java.lang.Long getLong(PropertyResolver resolver, java.lang.String name)
- Parameters:
resolver- ThePropertyResolverinstance - ignored ifnullname- The property name- Returns:
- The
Longvalue ornullif property not found - Throws:
java.lang.NumberFormatException- if malformed value- See Also:
toLong(Object)
-
getLong
public static java.lang.Long getLong(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
toLong
public static java.lang.Long toLong(java.lang.Object value)
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:
java.lang.NumberFormatException- if malformed value- See Also:
Long.valueOf(long),Long.valueOf(String)
- If the value is
-
toEnum
public static <E extends java.lang.Enum<E>> E toEnum(java.lang.Class<E> enumType, java.lang.Object value, boolean failIfNoMatch, java.util.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:
java.lang.IllegalArgumentException- If value is neithernull, nor the enumerated type nor aCharSequencejava.util.NoSuchElementException- If no matching string name found and failIfNoMatch istrue
- If value is
-
updateProperty
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, long value)
-
updateProperty
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, long value)
-
getIntProperty
public static int getIntProperty(PropertyResolver resolver, java.lang.String name, int defaultValue)
-
getIntProperty
public static int getIntProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, int defaultValue)
-
toInteger
public static int toInteger(java.lang.Object value, int defaultValue)
-
getInteger
public static java.lang.Integer getInteger(PropertyResolver resolver, java.lang.String name)
-
getInteger
public static java.lang.Integer getInteger(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
toInteger
public static java.lang.Integer toInteger(java.lang.Object value)
-
updateProperty
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, int value)
-
updateProperty
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, int value)
-
getBooleanProperty
public static boolean getBooleanProperty(PropertyResolver resolver, java.lang.String name, boolean defaultValue)
-
getBooleanProperty
public static boolean getBooleanProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, boolean defaultValue)
-
toBoolean
public static boolean toBoolean(java.lang.Object value, boolean defaultValue)- 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:
toBoolean(Object)
-
getBoolean
public static java.lang.Boolean getBoolean(PropertyResolver resolver, java.lang.String name)
-
getBoolean
public static java.lang.Boolean getBoolean(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
toBoolean
public static java.lang.Boolean toBoolean(java.lang.Object value)
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:
java.lang.UnsupportedOperationException- If value cannot be converted to a boolean - e.g., a number.- See Also:
parseBoolean(String)
- If
-
parseBoolean
public static java.lang.Boolean parseBoolean(java.lang.String value)
- Parameters:
value- The value to parse- Returns:
- The result -
nullif value isnull/empty - Throws:
java.lang.IllegalArgumentException- If non-empty string that does not match (case insensitive) either of the known values for boolean.
-
updateProperty
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, boolean value)
-
updateProperty
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, boolean value)
-
getStringProperty
public static java.lang.String getStringProperty(PropertyResolver resolver, java.lang.String name, java.lang.String defaultValue)
- 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
public static java.lang.String getStringProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, java.lang.String defaultValue)
-
getCharset
public static java.nio.charset.Charset getCharset(PropertyResolver resolver, java.lang.String name, java.nio.charset.Charset defaultValue)
-
getCharset
public static java.nio.charset.Charset getCharset(java.util.Map<java.lang.String,?> props, java.lang.String name, java.nio.charset.Charset defaultValue)
-
toCharset
public static java.nio.charset.Charset toCharset(java.lang.Object value)
-
getString
public static java.lang.String getString(PropertyResolver resolver, java.lang.String name)
-
getString
public static java.lang.String getString(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
getObject
public static java.lang.Object getObject(PropertyResolver resolver, java.lang.String name)
-
getObject
public static java.lang.Object getObject(PropertyResolver resolver, java.lang.String name, java.lang.Object defaultValue)
-
getObject
public static java.lang.Object getObject(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
resolvePropertyValue
public static java.lang.Object resolvePropertyValue(java.util.Map<java.lang.String,?> props, java.lang.String name)
-
updateProperty
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, java.lang.Object value)
- Parameters:
resolver- ThePropertyResolverinstancename- The property namevalue- The new value - ifnullor an emptyCharSequencethe property is removed- Returns:
- The previous value -
nullif none
-
updateProperty
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, java.lang.Object value)
-
resolvePropertyValue
public static java.lang.Object resolvePropertyValue(PropertyResolver resolver, java.lang.String name)
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
public static java.util.Map<java.lang.String,java.lang.Object> resolvePropertiesSource(PropertyResolver resolver, java.lang.String name)
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
public static PropertyResolver toPropertyResolver(java.util.Properties props)
-
toPropertyResolver
public static PropertyResolver toPropertyResolver(java.util.Map<java.lang.String,?> props)
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
public static PropertyResolver toPropertyResolver(java.util.Map<java.lang.String,?> props, PropertyResolver parent)
-
-