|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavatools.administrative.Parameters
public class Parameters
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). Provides an interface for an ini-File to load parameter settings. Note that this is a static version, i.e. all components share the same parameters. There is also an instantiable NonsharedParameters version. That version can deal with different parameter settings used in parallel. If your work will be shared with others, please consider using the NonsharedParameters, as they allow an easier integration of your component with other components that may want to work on a separate set of parameters (e.g. there might be different database settings etc.). The ini-File loaded may contain parameters of the form
parameterName = value ...It may also contain comments or section headers (i.e. anything that does not match the above pattern). Parameter names are not case sensitive. Initial and terminal spaces are trimmed for both parameter names and values. Boolean parameters accept multiple ways of expressing "true" (namely "on", "true", "yes" and "active").
To avoid passing around object handles, this class does not function as an object! There is only one "static object". Example:
// Read data from my.ini Parameters.init("my.ini"); // Abort with error message if the following parameters are not specified Parameters.ensureParameters( "firstPar - some help text for the first parameter", "secondPar - some help text for the secondparameter"); // Retrieve the value of a parameter String p = Parameters.get("firstPar");You can load parameters from multiple files. These will overlay.
Nested Class Summary | |
---|---|
static class |
Parameters.UndefinedParameterException
Thrown for an undefined Parameter |
Field Summary | |
---|---|
static java.io.File |
iniFile
Holds the filename of the ini-file |
static java.util.regex.Pattern |
INIPATTERN
Holds the pattern used for ini-file-entries |
static FinalSet<java.lang.String> |
no
Holds words that count as "no" for boolean parameters |
static java.util.Map<java.lang.String,java.lang.String> |
values
Contains the values for the parameters |
Constructor Summary | |
---|---|
Parameters()
|
Method Summary | |
---|---|
static void |
add(java.lang.String key,
java.lang.String value)
Adds a value to the map and to the ini file, if not yet there |
static void |
ensureParameters(java.lang.String... p)
Reports an error message and aborts if the parameters are undefined. |
static java.lang.String |
get(java.lang.String s)
Returns a value for a parameter |
static java.lang.String |
get(java.lang.String s,
java.lang.String defaultValue)
Returns a value for a parameter, returning a default value by default |
static boolean |
getBoolean(java.lang.String s)
Returns a value for a boolean parameter |
static boolean |
getBoolean(java.lang.String s,
boolean defaultValue)
Returns a value for a boolean parameter, returning a default value by default |
static boolean |
getBooleanArgument(java.lang.String[] args,
java.lang.String... argnames)
Parses the arguments of the main method and tells whether a parameter is on or off |
static Database |
getDatabase()
Returns the database defined in this ini-file |
static double |
getDouble(java.lang.String s)
Returns a value for an integer parameter |
static double |
getDouble(java.lang.String s,
double defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
static java.io.File |
getFile(java.lang.String s)
Returns a value for a file or folder parameter |
static java.io.File |
getFile(java.lang.String s,
java.io.File defaultValue)
Returns a value for a file or folder parameter, returning the default value if undefined |
static int |
getInt(java.lang.String s)
Returns a value for an integer parameter |
static int |
getInt(java.lang.String s,
int defaultValue)
Returns a value for an integer parameter returning the default value if undefined |
static java.util.List<java.lang.String> |
getList(java.lang.String s)
Returns a value for a list parameter |
static java.lang.String |
getOrRequest(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static java.lang.String |
getOrRequestAndAdd(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static boolean |
getOrRequestAndAddBoolean(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static java.io.File |
getOrRequestAndAddFile(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static int |
getOrRequestAndAddInt(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static boolean |
getOrRequestBoolean(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static java.io.File |
getOrRequestFileParameter(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static int |
getOrRequestInteger(java.lang.String s,
java.lang.String description)
Returns a value for a parameter. |
static void |
init(java.io.File f)
Initializes the parameters from a file |
static void |
init(java.lang.String file)
Initializes the parameters from a file |
static void |
init(java.lang.String filename,
java.io.File... folders)
Seeks the file in all given folders |
static boolean |
isDefined(java.lang.String s)
Tells whether a parameter is defined |
static void |
main(java.lang.String[] args)
Test routine |
static java.util.Set<java.lang.String> |
parameters()
Returns all defined parameters |
static java.lang.String |
remove(java.lang.String parameter)
Removes a value from the mapping (NOT: from the file) |
static void |
reset()
Deletes all current values |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.io.File iniFile
public static java.util.Map<java.lang.String,java.lang.String> values
public static java.util.regex.Pattern INIPATTERN
public static FinalSet<java.lang.String> no
Constructor Detail |
---|
public Parameters()
Method Detail |
---|
public static java.io.File getFile(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static java.io.File getFile(java.lang.String s, java.io.File defaultValue) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static int getInt(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static int getInt(java.lang.String s, int defaultValue) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static double getDouble(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static double getDouble(java.lang.String s, double defaultValue) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static boolean getBoolean(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static boolean getBoolean(java.lang.String s, boolean defaultValue)
public static java.util.List<java.lang.String> getList(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static java.lang.String get(java.lang.String s) throws Parameters.UndefinedParameterException
Parameters.UndefinedParameterException
public static java.lang.String get(java.lang.String s, java.lang.String defaultValue)
public static java.lang.String getOrRequest(java.lang.String s, java.lang.String description)
public static java.lang.String getOrRequestAndAdd(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public static int getOrRequestAndAddInt(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public static java.io.File getOrRequestAndAddFile(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public static boolean getOrRequestAndAddBoolean(java.lang.String s, java.lang.String description) throws java.io.IOException
java.io.IOException
public static java.io.File getOrRequestFileParameter(java.lang.String s, java.lang.String description)
public static java.lang.String remove(java.lang.String parameter)
public static boolean getOrRequestBoolean(java.lang.String s, java.lang.String description)
public static int getOrRequestInteger(java.lang.String s, java.lang.String description)
public static void add(java.lang.String key, java.lang.String value) throws java.io.IOException
java.io.IOException
public static void init(java.io.File f) throws java.io.IOException
java.io.IOException
public static void init(java.lang.String filename, java.io.File... folders) throws java.io.IOException
java.io.IOException
public static boolean isDefined(java.lang.String s)
public static void init(java.lang.String file) throws java.io.IOException
java.io.IOException
public static void ensureParameters(java.lang.String... p)
public static boolean getBooleanArgument(java.lang.String[] args, java.lang.String... argnames)
public static void reset()
public static Database getDatabase() throws java.lang.Exception
java.lang.Exception
public static java.util.Set<java.lang.String> parameters()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |