Top Fields Constructors Methods
org.apache.sshd.common

public final Class PropertyResolverUtils

extends Object
Class Inheritance
Imports
java.nio.charset.Charset, java.util.Collection, .Collections, .Map, .NavigableSet, .NoSuchElementException, .Objects, .Properties, java.util.concurrent.ConcurrentHashMap, org.apache.sshd.common.util.GenericUtils, .MapEntryUtils, .ValidateUtils

Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
public static final NavigableSet<String>
FALSE_VALUES

Case insensitive NavigableSet of values considered false by parseBoolean(String)

public static final String
public static final NavigableSet<String>
TRUE_VALUES

Case insensitive NavigableSet of values considered true by parseBoolean(String)

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Boolean
public static Boolean
getBoolean(Map<String, ?> props, String name)

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

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

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

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

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

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

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

public static Long

Returns:

The Long value or null if property not found
getLong
(PropertyResolver
The PropertyResolver instance - ignored if null
resolver
,
String
The property name
name
)

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

public static long

Returns:

The resolved property
getLongProperty
(PropertyResolver
The PropertyResolver instance - ignored if null
resolver
,
String
The property name
name
,
long
The default value to return if the specified property does not exist in the properties map
defaultValue
)

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

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

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

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

public static String

Returns:

The set value (if not null/empty) or default one
getStringProperty
(PropertyResolver
The PropertyResolver to use - ignored if null
resolver
,
String
The property name
name
,
String
The default value to return if property not set or empty
defaultValue
)

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

public static boolean

Returns:

true if equals to none - case insensitive
isNoneValue
(String
Value to examine
v
)

public static Boolean

Returns:

The result - null if value is null/empty
parseBoolean
(String
The value to parse
value
)

Converts a string to a Boolean value by looking for it in either the TRUE_VALUES or FALSE_VALUES

public static Map<String, Object>

Returns:

The found properties Map or null
resolvePropertiesSource
(PropertyResolver
The PropertyResolver to start from - ignored if null
resolver
,
String
The requested property name
name
)

Unwinds the resolvers hierarchy until found one with a non-null value for the requested property or reached top.

public static Object
public static Object

Returns:

The found value or null
resolvePropertyValue
(PropertyResolver
The PropertyResolver to start from - ignored if null
resolver
,
String
The requested property name
name
)

Unwinds the resolvers hierarchy until found one with a non-null value for the requested property or reached top.

public static boolean

Returns:

The resolved value
toBoolean
(Object
The value to convert
value
,
boolean
The default value to return if value is null or and empty string, then returns the default value.
defaultValue
)

public static Boolean

Returns:

The result - null if null or an empty string
toBoolean
(Object
The value to be converted
value
)

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

public static Charset
public static <
Type of enumerated value
E extends Enum<E>
>
E

Returns:

The matching enumerated value - null if no match found
toEnum
(Class<E>
The enumerated class type
enumType
,
Object
The configured value - ignored if null
value
,
boolean
Whether to fail if no matching name found
failIfNoMatch
,
Collection<E>
The available values to compare the name
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. >
public static int
toInteger(Object value, int defaultValue)

public static Integer
public static long

Returns:

The resolved value
toLong
(Object
The resolved value - may be null
value
,
long
The default to use if null resolved value
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
public static Long

Returns:

The Long value or null if property not found
toLong
(Object
The resolved value - may be null
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
public static PropertyResolver
public static PropertyResolver

Returns:

The resolver wrapper
toPropertyResolver
(Map<String, ?>
The properties map - may be null/empty if no properties are updated
props
)

Wraps a Map into a PropertyResolver so it can be used with these utilities

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

public static Object
updateProperty(Map<String, Object> props, String name, long value)

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

public static Object
updateProperty(Map<String, Object> props, String name, int value)

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

public static Object
updateProperty(Map<String, Object> props, String name, boolean value)

public static Object

Returns:

The previous value - null if none
updateProperty
(PropertyResolver
The PropertyResolver instance
resolver
,
String
The property name
name
,
Object
The new value - if null or an empty CharSequence the property is removed
value
)

public static Object
updateProperty(Map<String, Object> props, String name, Object value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

FALSE_VALUESback to summary
public static final NavigableSet<String> FALSE_VALUES

Case insensitive NavigableSet of values considered false by parseBoolean(String)

NONE_VALUEback to summary
public static final String NONE_VALUE
TRUE_VALUESback to summary
public static final NavigableSet<String> TRUE_VALUES

Case insensitive NavigableSet of values considered true by parseBoolean(String)

Constructor Detail

PropertyResolverUtilsback to summary
private PropertyResolverUtils()

Method Detail

getBooleanback to summary
public static Boolean getBoolean(PropertyResolver resolver, String name)
getBooleanback to summary
public static Boolean getBoolean(Map<String, ?> props, String name)
getBooleanPropertyback to summary
public static boolean getBooleanProperty(PropertyResolver resolver, String name, boolean defaultValue)
getBooleanPropertyback to summary
public static boolean getBooleanProperty(Map<String, ?> props, String name, boolean defaultValue)
getCharsetback to summary
public static Charset getCharset(PropertyResolver resolver, String name, Charset defaultValue)
getCharsetback to summary
public static Charset getCharset(Map<String, ?> props, String name, Charset defaultValue)
getIntegerback to summary
public static Integer getInteger(PropertyResolver resolver, String name)
getIntegerback to summary
public static Integer getInteger(Map<String, ?> props, String name)
getIntPropertyback to summary
public static int getIntProperty(PropertyResolver resolver, String name, int defaultValue)
getIntPropertyback to summary
public static int getIntProperty(Map<String, ?> props, String name, int defaultValue)
getLongback to summary
public static Long getLong(PropertyResolver resolver, String name)
Parameters
resolver:PropertyResolver

The PropertyResolver instance - ignored if null

name:String

The property name

Returns:Long

The Long value or null if property not found

Exceptions
NumberFormatException:
if malformed value
See Also
toLong(Object)
getLongback to summary
public static Long getLong(Map<String, ?> props, String name)
getLongPropertyback to summary
public static long getLongProperty(PropertyResolver resolver, String name, long defaultValue)
Parameters
resolver:PropertyResolver

The PropertyResolver instance - ignored if null

name:String

The property name

defaultValue:long

The default value to return if the specified property does not exist in the properties map

Returns:long

The resolved property

Exceptions
NumberFormatException:
if malformed value
See Also
toLong(Object, long)
getLongPropertyback to summary
public static long getLongProperty(Map<String, ?> props, String name, long defaultValue)
getObjectback to summary
public static Object getObject(PropertyResolver resolver, String name)
getObjectback to summary
public static Object getObject(PropertyResolver resolver, String name, Object defaultValue)
getObjectback to summary
public static Object getObject(Map<String, ?> props, String name)
getStringback to summary
public static String getString(PropertyResolver resolver, String name)
getStringback to summary
public static String getString(Map<String, ?> props, String name)
getStringPropertyback to summary
public static String getStringProperty(PropertyResolver resolver, String name, String defaultValue)
Parameters
resolver:PropertyResolver

The PropertyResolver to use - ignored if null

name:String

The property name

defaultValue:String

The default value to return if property not set or empty

Returns:String

The set value (if not null/empty) or default one

getStringPropertyback to summary
public static String getStringProperty(Map<String, ?> props, String name, String defaultValue)
isNoneValueback to summary
public static boolean isNoneValue(String v)
Parameters
v:String

Value to examine

Returns:boolean

true if equals to none - case insensitive

parseBooleanback to summary
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:String

The value to parse

Returns:Boolean

The result - null if value is null/empty

Exceptions
IllegalArgumentException:
If non-empty string that does not match (case insensitive) either of the known values for boolean.
resolvePropertiesSourceback to summary
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:PropertyResolver

The PropertyResolver to start from - ignored if null

name:String

The requested property name

Returns:Map<String, Object>

The found properties Map or null

resolvePropertyValueback to summary
public static Object resolvePropertyValue(Map<String, ?> props, String name)
resolvePropertyValueback to summary
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:PropertyResolver

The PropertyResolver to start from - ignored if null

name:String

The requested property name

Returns:Object

The found value or null

toBooleanback to summary
public static boolean toBoolean(Object value, boolean defaultValue)
Parameters
value:Object

The value to convert

defaultValue:boolean

The default value to return if value is null or and empty string, then returns the default value.

Returns:boolean

The resolved value

See Also
toBoolean(Object)
toBooleanback to summary
public static Boolean toBoolean(Object value)

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

Parameters
value:Object

The value to be converted

Returns:Boolean

The result - null if null or an empty string

Exceptions
UnsupportedOperationException:
If value cannot be converted to a boolean - e.g., a number.
See Also
parseBoolean(String)
toCharsetback to summary
public static Charset toCharset(Object value)
toEnumback to summary
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.
  • >
Parameters
<E>
Type of enumerated value
enumType:Class<E>

The enumerated class type

value:Object

The configured value - ignored if null

failIfNoMatch:boolean

Whether to fail if no matching name found

available:Collection<E>

The available values to compare the name

Returns:E

The matching enumerated value - null if no match found

Exceptions
IllegalArgumentException:
If value is neither null, nor the enumerated type nor a CharSequence
NoSuchElementException:
If no matching string name found and failIfNoMatch is true
toIntegerback to summary
public static int toInteger(Object value, int defaultValue)
toIntegerback to summary
public static Integer toInteger(Object value)
toLongback to summary
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:Object

The resolved value - may be null

defaultValue:long

The default to use if null resolved value

Returns:long

The resolved value

Exceptions
NumberFormatException:
if malformed value
See Also
Long#parseLong(String)
toLongback to summary
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:Object

The resolved value - may be null

Returns:Long

The Long value or null if property not found

Exceptions
NumberFormatException:
if malformed value
See Also
Long#valueOf(long), Long#valueOf(String)
toPropertyResolverback to summary
public static PropertyResolver toPropertyResolver(Properties props)
toPropertyResolverback to summary
public static PropertyResolver toPropertyResolver(Map<String, ?> props)

Wraps a Map into a PropertyResolver so it can be used with these utilities

Parameters
props:Map<String, ?>

The properties map - may be null/empty if no properties are updated

Returns:PropertyResolver

The resolver wrapper

toPropertyResolverback to summary
public static PropertyResolver toPropertyResolver(Map<String, ?> props, PropertyResolver parent)
updatePropertyback to summary
public static Object updateProperty(PropertyResolver resolver, String name, long value)
updatePropertyback to summary
public static Object updateProperty(Map<String, Object> props, String name, long value)
updatePropertyback to summary
public static Object updateProperty(PropertyResolver resolver, String name, int value)
updatePropertyback to summary
public static Object updateProperty(Map<String, Object> props, String name, int value)
updatePropertyback to summary
public static Object updateProperty(PropertyResolver resolver, String name, boolean value)
updatePropertyback to summary
public static Object updateProperty(Map<String, Object> props, String name, boolean value)
updatePropertyback to summary
public static Object updateProperty(PropertyResolver resolver, String name, Object value)
Parameters
resolver:PropertyResolver

The PropertyResolver instance

name:String

The property name

value:Object

The new value - if null or an empty CharSequence the property is removed

Returns:Object

The previous value - null if none

updatePropertyback to summary
public static Object updateProperty(Map<String, Object> props, String name, Object value)