|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjd.util.Config
Config represents a set of key-value pairs. Each key and its corresponding value is a string. Config has several methods to access the value and convert it to another simple type (e.g. integer, double, Date, ...). The value of a key can be another config object thus allowing arbitrary nested levels.
A Config object can be loaded from and saved to a file.
Constructor Summary | |
Config()
|
Method Summary | |
boolean |
containsKey(String key)
Test if the given string is a key of this Config. |
String |
get(String key)
Get the value of a key. |
String |
get(String key,
String defaultValue)
Get the value of a key. |
boolean |
getBoolean(String key)
Return true if the value to which the key is mapped is "true", false otherwise. |
boolean |
getBoolean(String key,
boolean defaultValue)
Return true if the value to which the key is mapped is "true", false otherwise. |
File |
getDirectory(String key)
Return the value of a key as a File. |
double |
getDouble(String key)
Return the value of a key as a double. |
double |
getDouble(String key,
double defaultValue)
Return the value of a key as a double. |
File |
getFile(String parameter)
Return the value of a key as a File. |
File |
getFile(String parameter,
File defaultFile)
Return the value of a key as a File. |
int |
getInt(String key)
Return the value of a key as an integer. |
int |
getInt(String key,
int defaultValue)
Return the value of a key as an integer. |
String[] |
getItemList(String keyPrefix)
|
void |
getItemList(String keyPrefix,
Vector v)
|
String[] |
getList(String key,
String delimiter)
Return the value of a key splitted into an string array. |
void |
getList(String key,
String delimiter,
Vector list)
Return the value of a key splitted into an string array. |
long |
getLong(String key)
Return the value of a key as a long. |
long |
getLong(String key,
long defaultValue)
Return the value to which the key is mapped as a long. |
String |
getPath(String key)
Return the value to which the key is mapped. |
String |
getPath(String parameter,
boolean startsWithSeparator,
boolean endsWithSeparator)
Return the value to which the key is mapped. |
File |
getSourceFile()
|
Config |
getSubConfig(String key)
Return a sub config. |
Config |
getSubConfig(String key,
boolean createNonExistentKey)
Return a sub config. |
Config |
getSubConfig(String key,
Config defaultConfig)
Return a sub config. |
Enumeration |
keys()
Return an enumeration of all keys. |
void |
read(File file)
Reads the Config values from the file. |
void |
read(InputStream in)
Read the Config values from the Reader. |
void |
read(Reader reader)
Read the Config values from the Reader. |
void |
read(String fileName)
Read the Config from the file. |
void |
read(String name,
ClassLoader loader)
Read the Config from a resource. |
Object |
remove(String key)
Remove a key from the config. |
void |
removeAll()
Remove all values from the config. |
Config |
removeSubConfig(String key)
Remove a subconfig. |
void |
set(String key,
String value)
Map the key to the value. |
void |
setBoolean(String key,
boolean value)
Map the key to the boolean value. |
void |
setDouble(String key,
double value)
Map the key to the double value. |
void |
setFile(String key,
File value)
Set the file value for a key. |
void |
setInt(String key,
int value)
Map the key to the int value. |
void |
setLong(String key,
long value)
Map the key to the long value. |
int |
size()
Return the number of values not counting any subconfigs. |
int |
size(boolean recursive)
Return the number of values. |
Enumeration |
values()
Return an enumeration of all keys. |
void |
write()
Write the Config to the file from that it was previously read. |
void |
write(File file)
Write the Config to the file. |
void |
write(String fileName)
Write the Config to the file. |
void |
write(Writer writer)
Write the Config to the PrintWriter. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Config()
Method Detail |
public String get(String key) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public String get(String key, String defaultValue)
public void set(String key, String value)
public int getInt(String key) throws IllegalArgumentException, NumberFormatException
IllegalArgumentException
- thrown if the key is not mapped to
any value.
NumberFormatException
- thrown if the value cannot be converted to an integerpublic int getInt(String key, int defaultValue) throws NumberFormatException
NumberFormatException
- thrown if the value cannot be converted to an integerpublic void setInt(String key, int value)
public long getLong(String key) throws IllegalArgumentException, NumberFormatException
IllegalArgumentException
- thrown if the key is not mapped to
any value.
NumberFormatException
- thrown if the value cannot be converted to a longpublic long getLong(String key, long defaultValue) throws NumberFormatException
NumberFormatException
- thrown if the value cannot be converted to a longpublic void setLong(String key, long value)
public double getDouble(String key) throws IllegalArgumentException, NumberFormatException
IllegalArgumentException
- thrown if the key is not mapped to
any value.
NumberFormatException
- thrown if the value cannot be converted to a doublepublic double getDouble(String key, double defaultValue) throws NumberFormatException
NumberFormatException
- thrown if the value cannot be converted to a doublepublic void setDouble(String key, double value)
public boolean getBoolean(String key) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public boolean getBoolean(String key, boolean defaultValue)
public void setBoolean(String key, boolean value)
public Config getSubConfig(String key)
public Config getSubConfig(String key, boolean createNonExistentKey)
public Config getSubConfig(String key, Config defaultConfig)
public String[] getList(String key, String delimiter) throws IllegalArgumentException
key
- the keydelimiter
- the delimiter for separating the substrings
IllegalArgumentException
- thrown if the key is not mapped to
any value.public void getList(String key, String delimiter, Vector list)
key
- the keydelimiter
- the delimiter for separating the substringspublic String[] getItemList(String keyPrefix)
public void getItemList(String keyPrefix, Vector v)
public String getPath(String key) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public String getPath(String parameter, boolean startsWithSeparator, boolean endsWithSeparator) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public File getFile(String parameter) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public File getFile(String parameter, File defaultFile)
public void setFile(String key, File value)
public File getDirectory(String key) throws IllegalArgumentException
IllegalArgumentException
- thrown if the key is not mapped to
any value.public int size()
public int size(boolean recursive)
recursive
- recurse into subconfigs?public boolean containsKey(String key)
public Object remove(String key)
key
- the key
public Config removeSubConfig(String key)
public void removeAll()
public Enumeration keys()
public Enumeration values()
public File getSourceFile()
public void read(String fileName) throws IOException
fileName
- the file name
IOException
- thrown if an I/O error occurspublic void read(String name, ClassLoader loader) throws IOException
name
- the resource nameloader
- a class loader or null if the config is a system resource
IOException
- thrown if an I/O error occurspublic void read(File file) throws IOException
IOException
- thrown if an I/O error occurspublic void read(InputStream in) throws IOException
IOException
- thrown if an I/O error occurspublic void read(Reader reader) throws IOException
IOException
- thrown if an I/O error occurspublic void write() throws IOException
IOException
- if a IO Error occurs.public void write(String fileName) throws IOException
IOException
- if a IO Error occurs.public void write(File file) throws IOException
IOException
- if a IO Error occurs.public void write(Writer writer) throws IOException
IOException
- if a IO Error occurs.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |