public class PropertiesUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PropertiesUtils.Property |
Modifier and Type | Method and Description |
---|---|
static java.util.Map<java.lang.String,java.lang.String> |
asMap(java.util.Properties properties)
Tired of Properties not behaving like
Map<String,String> s? This method will solve that problem for you. |
static java.util.Properties |
asProperties(java.lang.String... args)
Create a Properties object from the passed in String arguments.
|
static java.lang.String |
asString(java.util.Properties props)
Convert from Properties to String.
|
static void |
checkProperties(java.util.Properties properties,
java.util.Properties defaults)
Checks to make sure that all properties specified in
properties
are known to the program by checking that each simply overrides
a default value. |
static java.util.Properties |
extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix)
Build a
Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix . |
static java.util.Properties |
extractPrefixedProperties(java.util.Properties properties,
java.lang.String prefix,
boolean keepPrefix)
Build a
Properties object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix . |
static java.util.Properties |
extractSelectedProperties(java.util.Properties properties,
java.util.Set<java.lang.String> keptProperties)
Build a
Properties object containing key-value pairs from
the given properties whose keys are in a list to keep. |
static java.util.Properties |
fromString(java.lang.String str)
Convert from String to Properties.
|
static <E> E |
get(java.util.Properties props,
java.lang.String key,
E defaultValue,
java.lang.reflect.Type type)
Get the value of a property and automatically cast it to a specific type.
|
static boolean |
getBool(java.util.Properties props,
java.lang.String key)
Load a boolean property.
|
static boolean |
getBool(java.util.Properties props,
java.lang.String key,
boolean defaultValue)
Load a boolean property.
|
static java.lang.String |
getDirPath(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property as a path to a directory.
|
static double |
getDouble(java.util.Properties props,
java.lang.String key)
Load a double property.
|
static double |
getDouble(java.util.Properties props,
java.lang.String key,
double defaultValue)
Load a double property.
|
static double[] |
getDoubleArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of doubles from Properties.
|
static int |
getInt(java.util.Properties props,
java.lang.String key)
Load an integer property.
|
static int |
getInt(java.util.Properties props,
java.lang.String key,
int defaultValue)
Load an integer property.
|
static int[] |
getIntArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of integers from Properties.
|
static long |
getLong(java.util.Properties props,
java.lang.String key,
long defaultValue)
Load an integer property as a long.
|
static java.lang.String |
getSignature(java.lang.String name,
java.util.Properties properties) |
static java.lang.String |
getSignature(java.lang.String name,
java.util.Properties properties,
PropertiesUtils.Property[] supportedProperties) |
static java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getSortedEntries(java.util.Properties properties) |
static java.lang.String |
getString(java.util.Properties props,
java.lang.String key,
java.lang.String defaultValue)
Get the value of a property.
|
static java.lang.String[] |
getStringArray(java.util.Properties props,
java.lang.String key)
Loads a comma-separated list of strings from Properties.
|
static java.lang.String[] |
getStringArray(java.util.Properties props,
java.lang.String key,
java.lang.String[] defaults) |
static boolean |
hasProperty(java.util.Properties props,
java.lang.String key)
Returns true iff the given Properties contains a property with the given
key (name), and its value is not "false" or "no" or "off".
|
static boolean |
hasPropertyPrefix(java.util.Properties props,
java.lang.String prefix) |
static java.util.Properties |
noClobberWriteProperties(java.util.Properties bp,
java.util.Properties ovp) |
static java.util.Properties |
overWriteProperties(java.util.Properties bp,
java.util.Properties ovp) |
static void |
printProperties(java.lang.String message,
java.util.Properties properties) |
static void |
printProperties(java.lang.String message,
java.util.Properties properties,
java.io.PrintStream stream) |
static java.lang.String |
propsAsJsonString(java.util.Properties props)
Convert the given properties to a json string
|
public static boolean hasProperty(java.util.Properties props, java.lang.String key)
props
- Properties objectkey
- The key to testpublic static boolean hasPropertyPrefix(java.util.Properties props, java.lang.String prefix)
public static java.util.Properties asProperties(java.lang.String... args)
args
- An even-length list of alternately key and valuepublic static java.lang.String asString(java.util.Properties props)
public static java.util.Properties fromString(java.lang.String str)
public static void printProperties(java.lang.String message, java.util.Properties properties, java.io.PrintStream stream)
public static void printProperties(java.lang.String message, java.util.Properties properties)
public static java.util.Map<java.lang.String,java.lang.String> asMap(java.util.Properties properties)
Map<String,String>
s? This method will solve that problem for you.public static java.util.List<java.util.Map.Entry<java.lang.String,java.lang.String>> getSortedEntries(java.util.Properties properties)
public static void checkProperties(java.util.Properties properties, java.util.Properties defaults)
properties
are known to the program by checking that each simply overrides
a default value.properties
- Current propertiesdefaults
- Default properties which lists all known keyspublic static java.util.Properties extractPrefixedProperties(java.util.Properties properties, java.lang.String prefix)
Properties
object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix
. The keys in the returned object will be stripped
of their common prefix.properties
- Key-value data from which to extract pairsprefix
- Key-value pairs where the key has this prefix will
be retained in the returned Properties
objectproperties
where the key was prefixed by
prefix
. This prefix is removed from all keys in
the returned structure.public static java.util.Properties extractPrefixedProperties(java.util.Properties properties, java.lang.String prefix, boolean keepPrefix)
Properties
object containing key-value pairs from
the given data where the keys are prefixed with the given
prefix
. The keys in the returned object will be stripped
of their common prefix.properties
- Key-value data from which to extract pairsprefix
- Key-value pairs where the key has this prefix will
be retained in the returned Properties
objectkeepPrefix
- whether the prefix should be kept in the keyproperties
where the key was prefixed by
prefix
. If keepPrefix is false, the prefix is removed from all keys in
the returned structure.public static java.util.Properties extractSelectedProperties(java.util.Properties properties, java.util.Set<java.lang.String> keptProperties)
Properties
object containing key-value pairs from
the given properties whose keys are in a list to keep.properties
- Key-value data from which to extract pairskeptProperties
- Key names to keep (by exact match).properties
where the key was in keptPropertiespublic static <E> E get(java.util.Properties props, java.lang.String key, E defaultValue, java.lang.reflect.Type type)
public static java.lang.String getDirPath(java.util.Properties props, java.lang.String key, java.lang.String defaultValue)
public static java.lang.String getString(java.util.Properties props, java.lang.String key, java.lang.String defaultValue)
public static int getInt(java.util.Properties props, java.lang.String key)
public static int getInt(java.util.Properties props, java.lang.String key, int defaultValue)
public static long getLong(java.util.Properties props, java.lang.String key, long defaultValue)
public static double getDouble(java.util.Properties props, java.lang.String key)
public static double getDouble(java.util.Properties props, java.lang.String key, double defaultValue)
public static boolean getBool(java.util.Properties props, java.lang.String key)
public static boolean getBool(java.util.Properties props, java.lang.String key, boolean defaultValue)
public static int[] getIntArray(java.util.Properties props, java.lang.String key)
public static double[] getDoubleArray(java.util.Properties props, java.lang.String key)
public static java.lang.String[] getStringArray(java.util.Properties props, java.lang.String key)
public static java.lang.String[] getStringArray(java.util.Properties props, java.lang.String key, java.lang.String[] defaults)
public static java.util.Properties overWriteProperties(java.util.Properties bp, java.util.Properties ovp)
public static java.util.Properties noClobberWriteProperties(java.util.Properties bp, java.util.Properties ovp)
public static java.lang.String getSignature(java.lang.String name, java.util.Properties properties, PropertiesUtils.Property[] supportedProperties)
public static java.lang.String getSignature(java.lang.String name, java.util.Properties properties)
public static java.lang.String propsAsJsonString(java.util.Properties props)