public final class PropertyResolverUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.NavigableSet<java.lang.String> |
FALSE_VALUES
|
static java.lang.String |
NONE_VALUE |
static java.util.NavigableSet<java.lang.String> |
TRUE_VALUES
|
Modifier | Constructor and Description |
---|---|
private |
PropertyResolverUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Boolean |
getBoolean(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.Boolean |
getBoolean(PropertyResolver resolver,
java.lang.String name) |
static boolean |
getBooleanProperty(java.util.Map<java.lang.String,?> props,
java.lang.String name,
boolean defaultValue) |
static boolean |
getBooleanProperty(PropertyResolver resolver,
java.lang.String name,
boolean defaultValue) |
static java.nio.charset.Charset |
getCharset(java.util.Map<java.lang.String,?> props,
java.lang.String name,
java.nio.charset.Charset defaultValue) |
static java.nio.charset.Charset |
getCharset(PropertyResolver resolver,
java.lang.String name,
java.nio.charset.Charset defaultValue) |
static java.lang.Integer |
getInteger(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.Integer |
getInteger(PropertyResolver resolver,
java.lang.String name) |
static int |
getIntProperty(java.util.Map<java.lang.String,?> props,
java.lang.String name,
int defaultValue) |
static int |
getIntProperty(PropertyResolver resolver,
java.lang.String name,
int defaultValue) |
static java.lang.Long |
getLong(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.Long |
getLong(PropertyResolver resolver,
java.lang.String name) |
static long |
getLongProperty(java.util.Map<java.lang.String,?> props,
java.lang.String name,
long defaultValue) |
static long |
getLongProperty(PropertyResolver resolver,
java.lang.String name,
long defaultValue) |
static java.lang.Object |
getObject(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.Object |
getObject(PropertyResolver resolver,
java.lang.String name) |
static java.lang.Object |
getObject(PropertyResolver resolver,
java.lang.String name,
java.lang.Object defaultValue) |
static java.lang.String |
getString(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.String |
getString(PropertyResolver resolver,
java.lang.String name) |
static java.lang.String |
getStringProperty(java.util.Map<java.lang.String,?> props,
java.lang.String name,
java.lang.String defaultValue) |
static java.lang.String |
getStringProperty(PropertyResolver resolver,
java.lang.String name,
java.lang.String defaultValue) |
static boolean |
isNoneValue(java.lang.String v) |
static java.lang.Boolean |
parseBoolean(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-
null value for the requested property or
reached top. |
static java.lang.Object |
resolvePropertyValue(java.util.Map<java.lang.String,?> props,
java.lang.String name) |
static java.lang.Object |
resolvePropertyValue(PropertyResolver resolver,
java.lang.String name)
Unwinds the resolvers hierarchy until found one with a non-
null value for the requested property or
reached top. |
static java.lang.Boolean |
toBoolean(java.lang.Object value)
Attempts to convert the object into a
Boolean value as follows: |
static boolean |
toBoolean(java.lang.Object value,
boolean defaultValue) |
static java.nio.charset.Charset |
toCharset(java.lang.Object value) |
static <E extends java.lang.Enum<E>> |
toEnum(java.lang.Class<E> enumType,
java.lang.Object value,
boolean failIfNoMatch,
java.util.Collection<E> available)
Converts an enumerated configuration value:
|
static java.lang.Integer |
toInteger(java.lang.Object value) |
static int |
toInteger(java.lang.Object value,
int defaultValue) |
static java.lang.Long |
toLong(java.lang.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
|
static long |
toLong(java.lang.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
|
static PropertyResolver |
toPropertyResolver(java.util.Map<java.lang.String,?> props)
Wraps a
Map into a PropertyResolver so it can be used with these utilities |
static PropertyResolver |
toPropertyResolver(java.util.Map<java.lang.String,?> props,
PropertyResolver parent) |
static PropertyResolver |
toPropertyResolver(java.util.Properties props) |
static java.lang.Object |
updateProperty(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String name,
boolean value) |
static java.lang.Object |
updateProperty(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String name,
int value) |
static java.lang.Object |
updateProperty(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String name,
long value) |
static java.lang.Object |
updateProperty(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String name,
java.lang.Object value) |
static java.lang.Object |
updateProperty(PropertyResolver resolver,
java.lang.String name,
boolean value) |
static java.lang.Object |
updateProperty(PropertyResolver resolver,
java.lang.String name,
int value) |
static java.lang.Object |
updateProperty(PropertyResolver resolver,
java.lang.String name,
long value) |
static java.lang.Object |
updateProperty(PropertyResolver resolver,
java.lang.String name,
java.lang.Object value) |
public static final java.lang.String NONE_VALUE
public static final java.util.NavigableSet<java.lang.String> TRUE_VALUES
public static final java.util.NavigableSet<java.lang.String> FALSE_VALUES
public static boolean isNoneValue(java.lang.String v)
v
- Value to examinetrue
if equals to "none" - case insensitivepublic static long getLongProperty(PropertyResolver resolver, java.lang.String name, long defaultValue)
resolver
- The PropertyResolver
instance - ignored if null
name
- The property namedefaultValue
- The default value to return if the specified property does not exist in the
properties mapjava.lang.NumberFormatException
- if malformed valuetoLong(Object, long)
public static long getLongProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, long defaultValue)
public static long toLong(java.lang.Object value, long defaultValue)
long
if possible:
null
the default is returnedNumber
then its Number.longValue()
is returnedtoString()
is parsed as a long
value
- The resolved value - may be null
defaultValue
- The default to use if null
resolved valuejava.lang.NumberFormatException
- if malformed valueLong.parseLong(String)
public static java.lang.Long getLong(PropertyResolver resolver, java.lang.String name)
resolver
- The PropertyResolver
instance - ignored if null
name
- The property nameLong
value or null
if property not foundjava.lang.NumberFormatException
- if malformed valuetoLong(Object)
public static java.lang.Long getLong(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Long toLong(java.lang.Object value)
Long
:
null
then returns null
.Long
then it is returned as such.Number
then its Number.longValue()
is wrapped as a Long
toString()
is parsed as a Long
value
- The resolved value - may be null
Long
value or null
if property not foundjava.lang.NumberFormatException
- if malformed valueLong.valueOf(long)
,
Long.valueOf(String)
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)
null
then return null
CharSequence
then convert it to a string and look for a matching enumerated value name
- case insensitive.E
- Type of enumerated valueenumType
- The enumerated class typevalue
- The configured value - ignored if null
failIfNoMatch
- Whether to fail if no matching name foundavailable
- The available values to compare the namenull
if no match foundjava.lang.IllegalArgumentException
- If value is neither null
, nor the enumerated type nor a
CharSequence
java.util.NoSuchElementException
- If no matching string name found and failIfNoMatch is true
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, long value)
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, long value)
public static int getIntProperty(PropertyResolver resolver, java.lang.String name, int defaultValue)
public static int getIntProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, int defaultValue)
public static int toInteger(java.lang.Object value, int defaultValue)
public static java.lang.Integer getInteger(PropertyResolver resolver, java.lang.String name)
public static java.lang.Integer getInteger(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Integer toInteger(java.lang.Object value)
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, int value)
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, int value)
public static boolean getBooleanProperty(PropertyResolver resolver, java.lang.String name, boolean defaultValue)
public static boolean getBooleanProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, boolean defaultValue)
public static boolean toBoolean(java.lang.Object value, boolean defaultValue)
value
- The value to convertdefaultValue
- The default value to return if value is null
or and empty string, then returns the
default value.toBoolean(Object)
public static java.lang.Boolean getBoolean(PropertyResolver resolver, java.lang.String name)
public static java.lang.Boolean getBoolean(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Boolean toBoolean(java.lang.Object value)
Attempts to convert the object into a Boolean
value as follows:
null
or an empty string then return null
.
Boolean
then return as-is
CharSequence
then invoke parseBoolean(String)
UnsupportedOperationException
value
- The value to be convertednull
if null
or an empty stringjava.lang.UnsupportedOperationException
- If value cannot be converted to a boolean - e.g., a number.parseBoolean(String)
public static java.lang.Boolean parseBoolean(java.lang.String value)
value
- The value to parsenull
if value is null
/emptyjava.lang.IllegalArgumentException
- If non-empty string that does not match (case insensitive) either of the
known values for boolean.public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, boolean value)
public static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, boolean value)
public static java.lang.String getStringProperty(PropertyResolver resolver, java.lang.String name, java.lang.String defaultValue)
resolver
- The PropertyResolver
to use - ignored if null
name
- The property namedefaultValue
- The default value to return if property not set or emptynull
/empty) or default onepublic static java.lang.String getStringProperty(java.util.Map<java.lang.String,?> props, java.lang.String name, java.lang.String defaultValue)
public static java.nio.charset.Charset getCharset(PropertyResolver resolver, java.lang.String name, java.nio.charset.Charset defaultValue)
public static java.nio.charset.Charset getCharset(java.util.Map<java.lang.String,?> props, java.lang.String name, java.nio.charset.Charset defaultValue)
public static java.nio.charset.Charset toCharset(java.lang.Object value)
public static java.lang.String getString(PropertyResolver resolver, java.lang.String name)
public static java.lang.String getString(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Object getObject(PropertyResolver resolver, java.lang.String name)
public static java.lang.Object getObject(PropertyResolver resolver, java.lang.String name, java.lang.Object defaultValue)
public static java.lang.Object getObject(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Object resolvePropertyValue(java.util.Map<java.lang.String,?> props, java.lang.String name)
public static java.lang.Object updateProperty(PropertyResolver resolver, java.lang.String name, java.lang.Object value)
resolver
- The PropertyResolver
instancename
- The property namevalue
- The new value - if null
or an empty CharSequence
the property is removednull
if nonepublic static java.lang.Object updateProperty(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String name, java.lang.Object value)
public static java.lang.Object resolvePropertyValue(PropertyResolver resolver, java.lang.String name)
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 consultedresolver
- The PropertyResolver
to start from - ignored if null
name
- The requested property namenull
public static java.util.Map<java.lang.String,java.lang.Object> resolvePropertiesSource(PropertyResolver resolver, java.lang.String name)
null
value for the requested property or
reached top.resolver
- The PropertyResolver
to start from - ignored if null
name
- The requested property nameMap
or null
public static PropertyResolver toPropertyResolver(java.util.Properties props)
public static PropertyResolver toPropertyResolver(java.util.Map<java.lang.String,?> props)
Map
into a PropertyResolver
so it can be used with these utilitiesprops
- The properties map - may be null
/empty if no properties are updatedpublic static PropertyResolver toPropertyResolver(java.util.Map<java.lang.String,?> props, PropertyResolver parent)