public class Configuration extends Object
Note: This class is not guaranteed to be thread-safe.
| Constructor and Description |
|---|
Configuration()
Creates and initializes a Configuration instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all key/value pairs of the configuration.
|
boolean |
contains(String key)
Tests if the configuration contains a value for a given key.
|
int |
getCount()
Returns the number of key/value pairs of this SmartInspect
configuration.
|
void |
loadFromFile(String fileName)
Loads the configuration from a file.
|
boolean |
readBoolean(String key,
boolean defaultValue)
Returns either the value converted to a boolean for the given key if an
element with the given key exists or defaultValue otherwise.
|
Color |
readColor(String key,
Color defaultValue)
Returns a Color value of an element for a given key.
|
int |
readInteger(String key,
int defaultValue)
Returns an int value of an element for a given key.
|
String |
readKey(int index)
Returns a key of this SmartInspect configuration for a given index.
|
Level |
readLevel(String key,
Level defaultValue)
Returns a Level value of an element for a given key.
|
String |
readString(String key,
String defaultValue)
Returns a String value of an element for a given key.
|
public Configuration()
public void loadFromFile(String fileName) throws IOException
This method loads key/value pairs separated with a '=' character from a file. Empty, unrecognized lines or lines beginning with a ';' character are ignored.
fileName - The name of the file to load the configuration from.IOException - If an I/O error occurred while trying to load the configuration or if the specified file does not exist.NullPointerException - If the fileName argument is null.public boolean contains(String key)
key - The key to test for.public void clear()
public int getCount()
public String readString(String key, String defaultValue)
key - The key whose value to return.defaultValue - The value to return if the given key is unknown.NullPointerException - If the key argument is null.public boolean readBoolean(String key, boolean defaultValue)
key - The key whose value to return.defaultValue - The value to return if the given key is unknown.NullPointerException - If the key argument is null.public int readInteger(String key, int defaultValue)
key - The key whose value to return.defaultValue - The value to return if the given key is unknown.This method returns the defaultValue argument if either the supplied key is unknown or the found value is not a valid int. Only non-negative int values are recognized as valid.
NullPointerException - If the key argument is null.public Level readLevel(String key, Level defaultValue)
key - The key whose value to return.defaultValue - The value to return if the given key is unknown.NullPointerException - If the key argument is null.public Color readColor(String key, Color defaultValue)
This method requires the element value to be specified as a hexadecimal string. To indicate that the element value represents a hexadecimal string, the element value must begin with "0x", "&H" or "$". A '0' nibble is appended if the hexadecimal string has an odd length.
The hexadecimal value must represent a three or four byte integer value. The hexadecimal values are handled as follows:
A stands for the alpha channel and R, G, and B represent the red, green and blue channels, respectively. If the value is not given as hexadecimal value with a length of 6 or 8 characters excluding the hexadecimal prefix identifier or if the value does not have a valid hexadecimal format, this method returns defaultValue.
key - The key whose value to return.defaultValue - The value to return if the given key is unknown or if the found value has an invalid format.NullPointerException - if the key argument is null.public String readKey(int index)
To find out the total number of key/value pairs in this SmartInspect configuration,
use getCount(). To get the value for a given key, use readString(String key, String defaultValue).
index - The index in this SmartInspect configuration.IndexOutOfBoundsException - if the index argument is not a valid
index of this SmartInspect configuration.Copyright © 2023. All rights reserved.