java.lang.Object com.realtime.crossfire.jxclient.settings.Settings
public class Settings
Maintains a set of key/value pairs. The values are stored in a flat file.
Field Summary | |
---|---|
private java.io.File |
file
The file for loading/saving values. |
private boolean |
noSave
Flag to inhibit saving. |
private java.util.Map<java.lang.String,java.lang.String> |
values
The stored values. |
Constructor Summary | |
---|---|
Settings(java.io.File file)
Create a new instance. |
Method Summary | |
---|---|
boolean |
getBoolean(java.lang.String key,
boolean defaultValue)
Return the boolean associated with the specified key at a node, or defaultValue if there is no association for this key. |
int |
getInt(java.lang.String key,
int defaultValue)
Return the integer associated with the specified key at a node, or defaultValue if there is no association for this key. |
long |
getLong(java.lang.String key,
long defaultValue)
Return the long associated with the specified key at a node, or defaultValue if there is no association for this key. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Return the string associated with the specified key at a node, or defaultValue if there is no association for this key. |
private void |
loadValues()
Load the values from the backing file. |
void |
putBoolean(java.lang.String key,
boolean value)
Store a key/value pair. |
void |
putInt(java.lang.String key,
int value)
Store a key/value pair. |
void |
putLong(java.lang.String key,
long value)
Store a key/value pair. |
void |
putString(java.lang.String key,
java.lang.String value)
Store a key/value pair. |
void |
remove(java.lang.String key)
Remove a key. |
private static void |
saveNode(java.io.BufferedWriter writer,
java.util.Map<java.lang.String,java.lang.String> node)
Save one node. |
private void |
saveValues()
Save the values to the backing file. |
private void |
setChanged()
This function is called whenever the contents of values has
changed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@NotNull private final java.io.File file
private boolean noSave
@NotNull private final java.util.Map<java.lang.String,java.lang.String> values
Constructor Detail |
---|
public Settings(@NotNull java.io.File file)
file
- The file for loading/saving values.Method Detail |
---|
public boolean getBoolean(@NotNull java.lang.String key, boolean defaultValue)
defaultValue
if there is no association for this key.
key
- Key to get value for.defaultValue
- the defaultValue
public int getInt(@NotNull java.lang.String key, int defaultValue)
defaultValue
if there is no association for this key.
key
- Key to get value for.defaultValue
- the defaultValue
public long getLong(@NotNull java.lang.String key, long defaultValue)
defaultValue
if there is no association for this key.
key
- Key to get value for.defaultValue
- the defaultValue
public java.lang.String getString(@NotNull java.lang.String key, @NotNull java.lang.String defaultValue)
defaultValue
if there is no association for this key.
key
- Key to get value for.defaultValue
- the defaultValue
private void loadValues()
public void putBoolean(@NotNull java.lang.String key, boolean value)
key
- The key to store.value
- The value to store.public void putInt(@NotNull java.lang.String key, int value)
key
- The key to store.value
- The value to store.public void putLong(@NotNull java.lang.String key, long value)
key
- The key to store.value
- The value to store.public void putString(@NotNull java.lang.String key, @NotNull java.lang.String value)
key
- The key to store.value
- The value to store.public void remove(@NotNull java.lang.String key)
key
- The key to remove.private static void saveNode(@NotNull java.io.BufferedWriter writer, @NotNull java.util.Map<java.lang.String,java.lang.String> node) throws java.io.IOException
writer
- The Writer
to write to.node
- The node to save.
java.io.IOException
- if the node cannot be savedprivate void saveValues() throws java.io.IOException
java.io.IOException
- if the values cannot be savedprivate void setChanged()
values
has
changed.