public class Parameters extends Object
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.| Modifier and Type | Class and Description |
|---|---|
static class |
Parameters.UndefinedParameterException
Thrown for an undefined Parameter
|
| Modifier and Type | Field and Description |
|---|---|
static File |
iniFile
Holds the filename of the ini-file
|
static Pattern |
INIPATTERN
Holds the pattern used for ini-file-entries
|
static FinalSet<String> |
no
Holds words that count as "no" for boolean parameters
|
static Map<String,String> |
values
Contains the values for the parameters
|
| Constructor and Description |
|---|
Parameters() |
| Modifier and Type | Method and Description |
|---|---|
static void |
add(String key,
String value)
Adds a value to the map and to the ini file, if not yet there
|
static void |
ensureParameters(String... p)
Reports an error message and aborts if the parameters are undefined.
|
static String |
get(String s)
Returns a value for a parameter
|
static String |
get(String s,
String defaultValue)
Returns a value for a parameter, returning a default value by default
|
static boolean |
getBoolean(String s)
Returns a value for a boolean parameter
|
static boolean |
getBoolean(String s,
boolean defaultValue)
Returns a value for a boolean parameter, returning a default value by
default
|
static boolean |
getBooleanArgument(String[] args,
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(String s)
Returns a value for an integer parameter
|
static double |
getDouble(String s,
double defaultValue)
Returns a value for an integer parameter returning the default value if
undefined
|
static File |
getFile(String s)
Returns a value for a file or folder parameter
|
static File |
getFile(String s,
File defaultValue)
Returns a value for a file or folder parameter, returning the default
value if undefined
|
static int |
getInt(String s)
Returns a value for an integer parameter
|
static int |
getInt(String s,
int defaultValue)
Returns a value for an integer parameter returning the default value if
undefined
|
static List<String> |
getList(String s)
Returns a value for a list parameter
|
static String |
getOrRequest(String s,
String description)
Returns a value for a parameter.
|
static String |
getOrRequestAndAdd(String s,
String description)
Returns a value for a parameter.
|
static boolean |
getOrRequestAndAddBoolean(String s,
String description)
Returns a value for a parameter.
|
static File |
getOrRequestAndAddFile(String s,
String description)
Returns a value for a parameter.
|
static int |
getOrRequestAndAddInt(String s,
String description)
Returns a value for a parameter.
|
static boolean |
getOrRequestBoolean(String s,
String description)
Returns a value for a parameter.
|
static File |
getOrRequestFileParameter(String s,
String description)
Returns a value for a parameter.
|
static int |
getOrRequestInteger(String s,
String description)
Returns a value for a parameter.
|
static void |
init(File f)
Initializes the parameters from a file
|
static void |
init(String file)
Initializes the parameters from a file
|
static void |
init(String filename,
File... folders)
Seeks the file in all given folders
|
static boolean |
isDefined(String s)
Tells whether a parameter is defined
|
static void |
main(String[] args)
Test routine
|
static Set<String> |
parameters()
Returns all defined parameters
|
static String |
remove(String parameter)
Removes a value from the mapping (NOT: from the file)
|
static void |
reset()
Deletes all current values
|
public static File iniFile
public static Pattern INIPATTERN
public static File getFile(String s) throws Parameters.UndefinedParameterException
public static File getFile(String s, File defaultValue) throws Parameters.UndefinedParameterException
public static int getInt(String s) throws Parameters.UndefinedParameterException
public static int getInt(String s, int defaultValue) throws Parameters.UndefinedParameterException
public static double getDouble(String s) throws Parameters.UndefinedParameterException
public static double getDouble(String s, double defaultValue) throws Parameters.UndefinedParameterException
public static boolean getBoolean(String s) throws Parameters.UndefinedParameterException
public static boolean getBoolean(String s, boolean defaultValue)
public static List<String> getList(String s) throws Parameters.UndefinedParameterException
public static String get(String s) throws Parameters.UndefinedParameterException
public static String get(String s, String defaultValue)
public static String getOrRequest(String s, String description)
public static String getOrRequestAndAdd(String s, String description) throws IOException
IOExceptionpublic static int getOrRequestAndAddInt(String s, String description) throws IOException
IOExceptionpublic static File getOrRequestAndAddFile(String s, String description) throws IOException
IOExceptionpublic static boolean getOrRequestAndAddBoolean(String s, String description) throws IOException
IOExceptionpublic static File getOrRequestFileParameter(String s, String description)
public static String remove(String parameter)
public static boolean getOrRequestBoolean(String s, String description)
public static int getOrRequestInteger(String s, String description)
public static void add(String key, String value) throws IOException
IOExceptionpublic static void init(File f) throws IOException
IOExceptionpublic static void init(String filename, File... folders) throws IOException
IOExceptionpublic static boolean isDefined(String s)
public static void init(String file) throws IOException
IOExceptionpublic static void ensureParameters(String... p)
public static boolean getBooleanArgument(String[] args, String... argnames)
public static void reset()
public static Database getDatabase() throws Exception
ExceptionCopyright © 2018. All rights reserved.