public final class ConfigUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.util.Set<java.lang.String> |
collectKeys(java.util.Map<java.lang.String,java.lang.Object> map) |
static boolean |
containsKey(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns true if there's a non-null value for the specified key.
|
static boolean |
containsKey(java.util.ResourceBundle config,
java.lang.String key)
Returns true if there's a non-null value for the specified key.
|
static <T> T |
getConfigValue(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key with an optional default value if no match is found.
|
static <T> T |
getConfigValue(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
T defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static <T> T |
getConfigValue(java.util.ResourceBundle config,
java.lang.String key)
Returns the value for the specified key with an optional default value if no match is found.
|
static <T> T |
getConfigValue(java.util.ResourceBundle config,
java.lang.String key,
T defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static boolean |
getConfigValueAsBoolean(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to a boolean.
|
static boolean |
getConfigValueAsBoolean(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
boolean defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static double |
getConfigValueAsDouble(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to a double.
|
static double |
getConfigValueAsDouble(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
double defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static float |
getConfigValueAsFloat(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to a float.
|
static float |
getConfigValueAsFloat(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
float defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static int |
getConfigValueAsInt(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to an int.
|
static int |
getConfigValueAsInt(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
int defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static long |
getConfigValueAsLong(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to a long.
|
static long |
getConfigValueAsLong(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
long defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static java.lang.Number |
getConfigValueAsNumber(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key coerced to a Number.
|
static java.lang.Number |
getConfigValueAsNumber(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
java.lang.Number defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static java.lang.String |
getConfigValueAsString(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns the value for the specified key converted to a String.
|
static java.lang.String |
getConfigValueAsString(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key,
java.lang.String defaultValue)
Returns the value for the specified key with an optional default value if no match is found.
|
static java.lang.String |
getFilenameExtension(java.lang.String path)
Extract the filename extension from the given path,
e.g.
|
static boolean |
isValueDefined(java.util.Map<java.lang.String,java.lang.Object> config,
java.lang.String key)
Returns true if there's a non-null value for the specified key.
|
static boolean |
isValueDefined(java.util.ResourceBundle config,
java.lang.String key)
Returns true if there's a non-null value for the specified key.
|
static java.lang.String |
stripFilenameExtension(java.lang.String path)
Strip the filename extension from the given path,
e.g.
|
static java.util.Properties |
toProperties(java.util.ResourceBundle resourceBundle)
Converts a
ResourceBundle instance into a Properties instance. |
@Nonnull public static java.util.Properties toProperties(@Nonnull java.util.ResourceBundle resourceBundle)
ResourceBundle
instance into a Properties
instance.resourceBundle
- the ResourceBundle
to be converted. Must not be null.Properties
with all key/value pairs from the given ResourceBundle
.public static boolean containsKey(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searchedpublic static boolean containsKey(@Nonnull java.util.ResourceBundle config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searchedpublic static boolean isValueDefined(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searchedpublic static boolean isValueDefined(@Nonnull java.util.ResourceBundle config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched@Nullable public static <T> T getConfigValue(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, @Nullable T defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found@Nullable public static <T> T getConfigValue(@Nonnull java.util.ResourceBundle config, @Nonnull java.lang.String key, @Nullable T defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found@Nullable public static <T> T getConfigValue(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key) throws java.util.MissingResourceException
config
- the configuration object to be searched uponkey
- the key to be searchedjava.util.MissingResourceException
@Nullable public static <T> T getConfigValue(@Nonnull java.util.ResourceBundle config, @Nonnull java.lang.String key) throws java.util.MissingResourceException
config
- the configuration object to be searched uponkey
- the key to be searchedjava.util.MissingResourceException
public static boolean getConfigValueAsBoolean(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searchedfalse
if no match.public static boolean getConfigValueAsBoolean(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, boolean defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is foundpublic static int getConfigValueAsInt(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched0
if no match.public static int getConfigValueAsInt(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, int defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is foundpublic static long getConfigValueAsLong(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched0L
if no match.public static long getConfigValueAsLong(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, long defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is foundpublic static double getConfigValueAsDouble(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched0d
if no match.public static double getConfigValueAsDouble(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, double defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is foundpublic static float getConfigValueAsFloat(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched0f
if no match.public static float getConfigValueAsFloat(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, float defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found@Nullable public static java.lang.Number getConfigValueAsNumber(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searchednull
if no match.@Nullable public static java.lang.Number getConfigValueAsNumber(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, @Nullable java.lang.Number defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is found@Nullable public static java.lang.String getConfigValueAsString(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key)
config
- the configuration object to be searched uponkey
- the key to be searched""
if no match.@Nullable public static java.lang.String getConfigValueAsString(@Nonnull java.util.Map<java.lang.String,java.lang.Object> config, @Nonnull java.lang.String key, @Nullable java.lang.String defaultValue)
config
- the configuration object to be searched uponkey
- the key to be searcheddefaultValue
- the value to send back if no match is foundpublic static java.lang.String getFilenameExtension(java.lang.String path)
path
- the file path (may be null
)null
if nonepublic static java.lang.String stripFilenameExtension(java.lang.String path)
path
- the file path (may be null
)null
if none@Nonnull public static java.util.Set<java.lang.String> collectKeys(@Nonnull java.util.Map<java.lang.String,java.lang.Object> map)