Package org.wildstang.framework.config
Class Config
java.lang.Object
org.wildstang.framework.config.Config
This class represents the config parameters. It is a map of key/value pairs.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleangetBoolean(String p_key, boolean p_default) Gets the boolean corresponding to a key in the config, with default.doubleGets the double corresponding to a key in the config, with default.intGets the int corresponding to a key in the config, with default.protected String[]getKeyValuePair(String p_line) Splits the input String on an equals (=) character, and returns the two parts as an array of two Strings.Gets the String corresponding to a key in the config, with default.Gets the value corresponding to a key in the config.Gets the value corresponding to a key in the config, with default.protected voidload(BufferedReader p_reader) Load in a config from file.protected BooleanparseBoolean(String p_valueStr) Converts a String containing a boolean to a Boolean.protected DoubleparseDouble(String p_valueStr) Converts a String containing a double to a Double.protected IntegerConverts a String containing a int to a Int.protected ObjectparseValue(String p_valueStr) Parses the value from a String.intsize()Returns the size of the total config map.protected StringstripComments(String p_line) Removes any part of a line following a hash character - '#'.
-
Constructor Details
-
Config
public Config()
-
-
Method Details
-
load
Load in a config from file.- Parameters:
p_reader- BufferedReader on a config file.
-
stripComments
Removes any part of a line following a hash character - '#'. Returns any part of the line that comes before that character, which will be an empty string if the line starts with a '#'. If a null string is passed in, a NullPointerException is thrown. The String is trimmed before being returned to remove any whitespace on either end.- Parameters:
p_line- a String representing a line of text- Returns:
- the String, minus any present # character, and any characters that follow it, if any. May return an empty String, but will never return null.
- Throws:
NullPointerException- True if the input String is null.
-
getKeyValuePair
Splits the input String on an equals (=) character, and returns the two parts as an array of two Strings.- Parameters:
p_line- String containing an '='.- Returns:
- Array of p_line split by '='.
- Throws:
NullPointerException- True if the String passed in is null.
-
parseValue
Parses the value from a String. It attempts to parse it into a primitive type, returns as its wrapper class. The order it attempts is: double, int, boolean, String.- Parameters:
p_valueStr- String containing a value.- Returns:
- Value as type object.
-
parseDouble
Converts a String containing a double to a Double.- Parameters:
p_valueStr- String representation of a double.- Returns:
- Parsed Double or null if not a double.
-
parseInt
Converts a String containing a int to a Int.- Parameters:
p_valueStr- String representation of a int.- Returns:
- Parsed Int or null if not a int.
-
parseBoolean
Converts a String containing a boolean to a Boolean.- Parameters:
p_valueStr- String representation of a boolean.- Returns:
- Parsed Boolean or null if not a boolean.
-
getValue
Gets the value corresponding to a key in the config.- Parameters:
p_key- Key to find corresponding value to.- Returns:
- Value corresponding to key.
-
getValue
Gets the value corresponding to a key in the config, with default.- Parameters:
p_key- Key to find corresponding value to.p_default- Default value if p_key doesn't exist.- Returns:
- Value corresponding to key, or default value.
-
getDouble
Gets the double corresponding to a key in the config, with default.- Parameters:
p_key- Key to find corresponding double to.p_default- Default double if p_key doesn't exist.- Returns:
- double corresponding to key, or default double.
-
getInt
Gets the int corresponding to a key in the config, with default.- Parameters:
p_key- Key to find corresponding int to.p_default- Default int if p_key doesn't exist.- Returns:
- int corresponding to key, or default int.
-
getBoolean
Gets the boolean corresponding to a key in the config, with default.- Parameters:
p_key- Key to find corresponding boolean to.p_default- Default boolean if p_key doesn't exist.- Returns:
- boolean corresponding to key, or default boolean.
-
getString
Gets the String corresponding to a key in the config, with default.- Parameters:
p_key- Key to find corresponding String to.p_default- Default String if p_key doesn't exist.- Returns:
- String corresponding to key, or default String.
-
size
public int size()Returns the size of the total config map.- Returns:
- Size of config map.
-