public class Settings
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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,Entry> |
values
The stored values.
|
Constructor and Description |
---|
Settings(java.io.File file)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean(SettingsEntry<java.lang.Boolean> key)
Returns the boolean associated with the specified key at a node or
defaultValue if there is no association for this key. |
int |
getInt(SettingsEntry<java.lang.Integer> key)
Returns the integer associated with the specified key at a node or
defaultValue if there is no association for this key. |
long |
getLong(SettingsEntry<java.lang.Long> key)
Returns the long associated with the specified key at a node or
defaultValue if there is no association for this key. |
java.lang.String |
getString(SettingsEntry<?> key)
Returns the string associated with the specified key at a node, or
defaultValue if there is no association for this key. |
private void |
loadValues()
Loads the values from the backing file.
|
private void |
loadValues(java.io.LineNumberReader lnr)
Loads the values.
|
void |
putBoolean(SettingsEntry<java.lang.Boolean> key,
boolean value)
Stores a key/value pair.
|
void |
putInt(SettingsEntry<java.lang.Integer> key,
int value)
Stores a key/value pair.
|
void |
putLong(SettingsEntry<java.lang.Long> key,
long value)
Stores a key/value pair.
|
void |
putString(SettingsEntry<?> key,
java.lang.String value)
Stores a key/value pair.
|
void |
remove(java.lang.String key)
Removes a key.
|
private static void |
saveNode(java.io.BufferedWriter writer,
java.util.Map<java.lang.String,Entry> node)
Saves one node.
|
private void |
saveValues()
Saves the values to the backing file.
|
private void |
setChanged()
This function is called whenever the contents of
values has
changed. |
@NotNull private final java.io.File file
private boolean noSave
@NotNull private final java.util.Map<java.lang.String,Entry> values
public Settings(@NotNull java.io.File file)
file
- the file for loading/saving valuespublic boolean getBoolean(@NotNull SettingsEntry<java.lang.Boolean> key)
defaultValue
if there is no association for this key.key
- the key to get the value forpublic int getInt(@NotNull SettingsEntry<java.lang.Integer> key)
defaultValue
if there is no association for this key.key
- the key to get the value forpublic long getLong(@NotNull SettingsEntry<java.lang.Long> key)
defaultValue
if there is no association for this key.key
- the key to get the value for@NotNull public java.lang.String getString(@NotNull SettingsEntry<?> key)
defaultValue
if there is no association for this key.key
- the key to get the value forprivate void loadValues()
private void loadValues(@NotNull java.io.LineNumberReader lnr) throws java.io.IOException
lnr
- the line number reader fromjava.io.IOException
- if an I/O error occurspublic void putBoolean(@NotNull SettingsEntry<java.lang.Boolean> key, boolean value)
key
- the key to storevalue
- the value to storepublic void putInt(@NotNull SettingsEntry<java.lang.Integer> key, int value)
key
- the key to storevalue
- the value to storepublic void putLong(@NotNull SettingsEntry<java.lang.Long> key, long value)
key
- the key to storevalue
- the value to storepublic void putString(@NotNull SettingsEntry<?> key, @NotNull java.lang.String value)
key
- the key to storevalue
- the value to storepublic void remove(@NotNull java.lang.String key)
key
- the key to removeprivate static void saveNode(@NotNull java.io.BufferedWriter writer, @NotNull java.util.Map<java.lang.String,Entry> node) throws java.io.IOException
writer
- the Writer
to write tonode
- the node to savejava.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.