Package jcckit.util
Class ConfigParameters
java.lang.Object
jcckit.util.ConfigParameters
Read-only class for hierarchically organized key-value pairs.
The key is always a string. The following value types are
supported:
- String
- boolean
- int
- double
- double[]
- Color
- ConfigParameters
In accordance with the Strategy design pattern the retrieval of
a key-value pair is delegated to an instance of
ConfigData
.
-
Constructor Summary
ConstructorDescriptionConfigParameters
(ConfigData configData) Creates an instance from the specified ConfigData object. -
Method Summary
Modifier and TypeMethodDescriptionReturns the string value associated with the specified key.Returns the string value associated with the specified key or defaultValue if undefined.boolean
getBoolean
(String key) Returns the boolean associated with the specified key.boolean
getBoolean
(String key, boolean defaultValue) Returns the boolean associated with the specified key.Returns the color associated with the specified key.Returns the color associated with the specified key or the specified default value if no key-value pair exists for the specified key.double
Returns the double associated with the specified key.double
Returns the double associated with the specified key or defaultValue if no key-value pair exists for the specified key.double[]
getDoubleArray
(String key) Returns the array of doubles associated with the specified key.double[]
getDoubleArray
(String key, double[] defaultValue) Returns the array of doubles associated with the specified key or defaultValue if no key-value pair exists for the specified key.getFullKey
(String key) Returns the full key.int
Returns the integer associated with the specified key.int
Returns the integer associated with the specified key or defaultValue if no key-value pair exists for the specified key.Returns the child node associated with the specified key.
-
Constructor Details
-
ConfigParameters
Creates an instance from the specified ConfigData object.
-
-
Method Details
-
getFullKey
Returns the full key.- Returns:
- the path concatenated with key.
- See Also:
-
get
Returns the string value associated with the specified key.- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the corresponding value. Will always be not null.
- Throws:
IllegalArgumentException
- if no value exists for key. The exception message is the full key.
-
get
Returns the string value associated with the specified key or defaultValue if undefined.- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- the corresponding value or defaultValue.
-
getBoolean
Returns the boolean associated with the specified key.- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- true if the value is "true" otherwise false.
- Throws:
IllegalArgumentException
- if no value exists for key. The exception message is the full key.NumberFormatException
- if the value is neither "true" nor "false".
-
getBoolean
Returns the boolean associated with the specified key.- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- true if the value is "true" otherwise false.
- Throws:
NumberFormatException
- if the value is neither "true" nor "false".
-
getInt
Returns the integer associated with the specified key. The value can be either- a decimal number (starting with a non-zero digit),
- a hexadecimal number (starting with 0x), or
- an octal number (starting with zero).
- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the integer value.
- Throws:
IllegalArgumentException
- if no value exists for key. The exception message is the full key.NumberFormatException
- if the value is not a number. The exception message contains the full key and the invalid value.
-
getInt
Returns the integer associated with the specified key or defaultValue if no key-value pair exists for the specified key. The value can be either- a decimal number (starting with a non-zero digit),
- a hexadecimal number (starting with 0x), or
- an octal number (starting with zero).
- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- the integer value.
- Throws:
NumberFormatException
- if the value exists but is not a number. The exception message contains the full key and the invalid value.
-
getDouble
Returns the double associated with the specified key.- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the double value.
- Throws:
IllegalArgumentException
- if no value exists for key. The exception message is the full key.NumberFormatException
- if the value is not a valid number. The exception message contains the full key and the invalid value.
-
getDouble
Returns the double associated with the specified key or defaultValue if no key-value pair exists for the specified key.- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- the double value.
- Throws:
NumberFormatException
- if the value exists but is not a valid number. The exception message contains the full key and the invalid value.
-
getDoubleArray
Returns the array of doubles associated with the specified key. The numbers are separated by whitespaces.- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the array of double values.
- Throws:
IllegalArgumentException
- if no value exists for key. The exception message is the full key.NumberFormatException
- if the value exists but is not a sequence of number. The exception message contains the full key and the invalid value.
-
getDoubleArray
Returns the array of doubles associated with the specified key or defaultValue if no key-value pair exists for the specified key. The numbers are separated by whitespaces.- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- the array of double values.
- Throws:
NumberFormatException
- if the value exists but is not a sequence of number. The exception message contains the full key and the invalid value.
-
getColor
Returns the color associated with the specified key. The color is coded as- a decimal number (starting with a non-zero digit),
- a hexadecimal number (starting with 0x), or
- an octal number (starting with zero).
- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the color.
- Throws:
NumberFormatException
- if the value exists but is not a number. The exception message contains the full key and the invalid value.
-
getColor
Returns the color associated with the specified key or the specified default value if no key-value pair exists for the specified key. The color is coded as- a decimal number (starting with a non-zero digit),
- a hexadecimal number (starting with 0x), or
- an octal number (starting with zero).
- Parameters:
key
- The (relative) key. null is not allowed.defaultValue
- The default value. Can be null.- Returns:
- the color or null if the value is an empty string.
- Throws:
NumberFormatException
- if the value exists but is not a number. The exception message contains the full key and the invalid value.
-
getNode
Returns the child node associated with the specified key. This method returns in any case a non-null result.- Parameters:
key
- The (relative) key. null is not allowed.- Returns:
- the corresponding child node which may be empty.
-