public class InitUtil
extends java.lang.Object
| Constructor and Description |
|---|
InitUtil(java.lang.String prefix,
java.util.Properties props)
Creates a properties init util.
|
InitUtil(java.lang.String prefix,
java.util.Properties props,
boolean lowercaseNames) |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String[] |
fromCommandLine(java.lang.String[] args,
java.util.Properties props)
Processes command-line arguments by treating those beginning with '-' as properties
of the format -[name]=[value].
|
int |
getIntProperty(java.lang.String propertyName,
int defaultValue)
Gets a property as an integer.
|
int |
getIntProperty(java.lang.String propertyName,
int index,
int defaultValue)
Gets a multi-valued integer property.
|
java.util.Properties |
getProperties()
Gets new properties containing only those that begin with the initialized prefix.
|
java.lang.String |
getProperty(java.lang.String propertyName)
Gets a property.
|
java.lang.String |
getProperty(java.lang.String propertyName,
int index,
java.lang.String defaultValue)
Gets a multi-valued property.
|
java.lang.String |
getProperty(java.lang.String propertyName,
java.lang.String defaultValue)
Gets a property.
|
java.lang.Object |
initClass(java.lang.String propertyName,
java.lang.Class<?> expectedClass)
Create an instance of a class.
|
java.util.List<java.lang.Object> |
initClassList(java.lang.String propertyName,
java.lang.Class<?> expectedClass)
Creates a list of instances of a class.
|
static long |
millisFromTime(java.lang.String time)
Gets a time in milliseconds from a string that allows the units 'ms', 's', 'm', 'h', 'd' at the end.
|
java.util.Map<java.lang.String,java.util.Properties> |
split()
Gets a map of properties vs name where name is supplied as a prefix, e.g.
|
void |
throwPositiveIntRequiredException(java.lang.String propertyName)
Throws initialization exception indicating property is not a positive integer.
|
void |
throwRequiredException(java.lang.String propertyName)
Throws initialization exception indicating property is required.
|
static java.util.Collection<Pair<java.lang.String,java.lang.String>> |
toPairCollection(java.util.Properties props)
Convert properties to a collection of string pairs.
|
public InitUtil(java.lang.String prefix,
java.util.Properties props)
prefix - The prefix appended to all property names.props - The properties.public InitUtil(java.lang.String prefix,
java.util.Properties props,
boolean lowercaseNames)
public java.util.Properties getProperties()
Prefix is removed from key name in returned properties.
public java.util.Map<java.lang.String,java.util.Properties> split()
prefix.[name].property=value.
public final java.lang.String getProperty(java.lang.String propertyName)
propertyName - The property name.public final java.lang.String getProperty(java.lang.String propertyName,
java.lang.String defaultValue)
propertyName - The property name.defaultValue - The default value.public final java.lang.String getProperty(java.lang.String propertyName,
int index,
java.lang.String defaultValue)
Index values are separated by ','. If index exceeds the number of values, the last is returned.
propertyName - The property name.index - The index.defaultValue - The default value. Used only if the property does not exist.public final int getIntProperty(java.lang.String propertyName,
int index,
int defaultValue)
throws InitializationException
Index values are separated by ','. If index exceeds the number of values, the last is returned.
propertyName - The property name.index - The index.defaultValue - The default value. Used only if the property does not exist.InitializationException - if property is not an integer.public final int getIntProperty(java.lang.String propertyName,
int defaultValue)
throws InitializationException
propertyName - The property name.defaultValue - The default value.InitializationException - if property is not an integer.public final java.lang.Object initClass(java.lang.String propertyName,
java.lang.Class<?> expectedClass)
throws InitializationException
propertyName - The property containing the class name.expectedClass - The expected class.InitializationException - if the class could not be found or instantiated.public final java.util.List<java.lang.Object> initClassList(java.lang.String propertyName,
java.lang.Class<?> expectedClass)
throws InitializationException
propertyName - The name of a property containing a space-separated list of classes.expectedClass - The expected class.InitializationException - if class could not be found or instantiated.public final void throwRequiredException(java.lang.String propertyName)
throws InitializationException
propertyName - The property name.InitializationException - if called.public final void throwPositiveIntRequiredException(java.lang.String propertyName)
throws InitializationException
propertyName - The property name.InitializationException - if called.public static java.lang.String[] fromCommandLine(java.lang.String[] args,
java.util.Properties props)
Properties with no specified value (e.g. -debug) are added to the properties with a value of "true".
args - The input arguments.props - The properties to which command line properties are added.public static final long millisFromTime(java.lang.String time)
throws InitializationException
time - The time string.InitializationException - if the time is not an integer.public static final java.util.Collection<Pair<java.lang.String,java.lang.String>> toPairCollection(java.util.Properties props)
props - The properties.