public final class PropertyResolverUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static NavigableSet<String> |
FALSE_VALUES
|
static String |
NONE_VALUE |
static NavigableSet<String> |
TRUE_VALUES
|
| Modifier and Type | Method and Description |
|---|---|
static 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 |
getLong(Map<String,?> props,
String name) |
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 |
getObject(Map<String,?> props,
String name) |
static Object |
getObject(PropertyResolver resolver,
String name) |
static Object |
getObject(PropertyResolver resolver,
String name,
Object defaultValue) |
static String |
getString(Map<String,?> props,
String name) |
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 |
isNoneValue(String v) |
static Boolean |
parseBoolean(String value)
|
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. |
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 |
toBoolean(Object value)
Attempts to convert the object into a
Boolean value as follows: |
static boolean |
toBoolean(Object value,
boolean defaultValue) |
static Charset |
toCharset(Object value) |
static <E extends Enum<E>> |
toEnum(Class<E> enumType,
Object value,
boolean failIfNoMatch,
Collection<E> available)
Converts an enumerated configuration value:
|
static Integer |
toInteger(Object value) |
static int |
toInteger(Object value,
int defaultValue) |
static Long |
toLong(Object value)
|
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
|
static PropertyResolver |
toPropertyResolver(Map<String,?> props)
Wraps a
Map into a PropertyResolver so it can be used with these utilities |
static 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 |
updateProperty(Map<String,Object> props,
String name,
Object value) |
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) |
public static final String NONE_VALUE
public static final NavigableSet<String> TRUE_VALUES
public static final NavigableSet<String> FALSE_VALUES
public static boolean isNoneValue(String v)
v - Value to examinetrue if equals to "none" - case insensitivepublic static long getLongProperty(PropertyResolver resolver, String name, long defaultValue)
resolver - The PropertyResolver instance - ignored if nullname - The property namedefaultValue - The default value to return if the specified property does not exist in the
properties mapNumberFormatException - if malformed valuetoLong(Object, long)public static long getLongProperty(Map<String,?> props, String name, long defaultValue)
public static long toLong(Object value, long defaultValue)
long if possible:
null the default is returnedNumber then its Number.longValue() is returnedtoString() is parsed as a longvalue - The resolved value - may be nulldefaultValue - The default to use if null resolved valueNumberFormatException - if malformed valueLong.parseLong(String)public static Long getLong(PropertyResolver resolver, String name)
resolver - The PropertyResolver instance - ignored if nullname - The property nameLong value or null if property not foundNumberFormatException - if malformed valuetoLong(Object)public static Long toLong(Object value)
Long:
null then returns null.Long then it is returned as such.Number then its Number.longValue() is wrapped as a LongtoString() is parsed as a Longvalue - The resolved value - may be nullLong value or null if property not foundNumberFormatException - if malformed valueLong.valueOf(long),
Long.valueOf(String)public static <E extends Enum<E>> E toEnum(Class<E> enumType, Object value, boolean failIfNoMatch, 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 nullfailIfNoMatch - Whether to fail if no matching name foundavailable - The available values to compare the namenull if no match foundIllegalArgumentException - If value is neither null, nor the enumerated type nor a
CharSequenceNoSuchElementException - If no matching string name found and failIfNoMatch is truepublic static Object updateProperty(PropertyResolver resolver, String name, long value)
public static Object updateProperty(Map<String,Object> props, String name, long value)
public static int getIntProperty(PropertyResolver resolver, String name, int defaultValue)
public static int toInteger(Object value, int defaultValue)
public static Integer getInteger(PropertyResolver resolver, String name)
public static Object updateProperty(PropertyResolver resolver, String name, int value)
public static Object updateProperty(Map<String,Object> props, String name, int value)
public static boolean getBooleanProperty(PropertyResolver resolver, String name, boolean defaultValue)
public static boolean getBooleanProperty(Map<String,?> props, String name, boolean defaultValue)
public static boolean toBoolean(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 Boolean getBoolean(PropertyResolver resolver, String name)
public static Boolean toBoolean(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)
UnsupportedOperationExceptionvalue - The value to be convertednull if null or an empty stringUnsupportedOperationException - If value cannot be converted to a boolean - e.g., a number.parseBoolean(String)public static Boolean parseBoolean(String value)
value - The value to parsenull if value is null/emptyIllegalArgumentException - If non-empty string that does not match (case insensitive) either of the
known values for boolean.public static Object updateProperty(PropertyResolver resolver, String name, boolean value)
public static Object updateProperty(Map<String,Object> props, String name, boolean value)
public static String getStringProperty(PropertyResolver resolver, String name, String defaultValue)
resolver - The PropertyResolver to use - ignored if nullname - The property namedefaultValue - The default value to return if property not set or emptynull/empty) or default onepublic static String getStringProperty(Map<String,?> props, String name, String defaultValue)
public static Charset getCharset(PropertyResolver resolver, String name, Charset defaultValue)
public static String getString(PropertyResolver resolver, String name)
public static Object getObject(PropertyResolver resolver, String name)
public static Object getObject(PropertyResolver resolver, String name, Object defaultValue)
public static Object updateProperty(PropertyResolver resolver, String name, 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 Object updateProperty(Map<String,Object> props, String name, Object value)
public static Object resolvePropertyValue(PropertyResolver resolver, 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 nullname - The requested property namenullpublic static Map<String,Object> resolvePropertiesSource(PropertyResolver resolver, String name)
null value for the requested property or
reached top.resolver - The PropertyResolver to start from - ignored if nullname - The requested property nameMap or nullpublic static PropertyResolver toPropertyResolver(Properties props)
public static PropertyResolver toPropertyResolver(Map<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(Map<String,?> props, PropertyResolver parent)
Copyright © 2018–2021 The Apache Software Foundation. All rights reserved.