com.realtime.crossfire.jxclient.settings
Class Settings

java.lang.Object
  extended by com.realtime.crossfire.jxclient.settings.Settings

public class Settings
extends java.lang.Object

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

file

@NotNull
private final java.io.File file
The file for loading/saving values.


noSave

private boolean noSave
Flag to inhibit saving.


values

@NotNull
private final java.util.Map<java.lang.String,java.lang.String> values
The stored values. Maps key name to value.

Constructor Detail

Settings

public Settings(@NotNull
                java.io.File file)
Create a new instance.

Parameters:
file - The file for loading/saving values.
Method Detail

getBoolean

public boolean getBoolean(@NotNull
                          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.

Parameters:
key - Key to get value for.
defaultValue - the defaultValue
Returns:
The value.

getInt

public int getInt(@NotNull
                  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.

Parameters:
key - Key to get value for.
defaultValue - the defaultValue
Returns:
The value.

getLong

public long getLong(@NotNull
                    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.

Parameters:
key - Key to get value for.
defaultValue - the defaultValue
Returns:
The value.

getString

public java.lang.String getString(@NotNull
                                  java.lang.String key,
                                  @NotNull
                                  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.

Parameters:
key - Key to get value for.
defaultValue - the defaultValue
Returns:
The value.

loadValues

private void loadValues()
Load the values from the backing file.


putBoolean

public void putBoolean(@NotNull
                       java.lang.String key,
                       boolean value)
Store a key/value pair.

Parameters:
key - The key to store.
value - The value to store.

putInt

public void putInt(@NotNull
                   java.lang.String key,
                   int value)
Store a key/value pair.

Parameters:
key - The key to store.
value - The value to store.

putLong

public void putLong(@NotNull
                    java.lang.String key,
                    long value)
Store a key/value pair.

Parameters:
key - The key to store.
value - The value to store.

putString

public void putString(@NotNull
                      java.lang.String key,
                      @NotNull
                      java.lang.String value)
Store a key/value pair.

Parameters:
key - The key to store.
value - The value to store.

remove

public void remove(@NotNull
                   java.lang.String key)
Remove a key. Does nothing if the key has no associated value.

Parameters:
key - The key to remove.

saveNode

private static void saveNode(@NotNull
                             java.io.BufferedWriter writer,
                             @NotNull
                             java.util.Map<java.lang.String,java.lang.String> node)
                      throws java.io.IOException
Save one node.

Parameters:
writer - The Writer to write to.
node - The node to save.
Throws:
java.io.IOException - if the node cannot be saved

saveValues

private void saveValues()
                 throws java.io.IOException
Save the values to the backing file.

Throws:
java.io.IOException - if the values cannot be saved

setChanged

private void setChanged()
This function is called whenever the contents of values has changed.