universe.common
Class Config

java.lang.Object
  |
  +--universe.common.Config

public class Config
extends java.lang.Object


Field Summary
private static char CNUL
           
static java.lang.String CONFIG_HEADER
           
static java.lang.String DEFAULT_FILE_NAME
           
private static java.io.File file
           
private static java.util.Properties prop
           
private static java.lang.String SNUL
           
 
Constructor Summary
private Config()
           
 
Method Summary
static boolean getBoolean(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static boolean getBoolean(java.lang.String key, boolean defaultValue)
          Searches for the value with the specified key in the Config file.
static java.awt.Color getColor(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static java.awt.Color getColor(java.lang.String key, java.awt.Color defaultValue)
          Searches for the value with the specified key in the Config file.
static double getDouble(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static double getDouble(java.lang.String key, double defaultValue)
          Searches for the value with the specified key in the Config file.
static java.io.File getFile(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static java.io.File getFile(java.lang.String key, java.io.File defaultValue)
          Searches for the value with the specified key in the Config file.
static float getFloat(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static float getFloat(java.lang.String key, float defaultValue)
          Searches for the value with the specified key in the Config file.
static float[] getFloatArray(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static float[] getFloatArray(java.lang.String key, float[] defaultValue)
          Searches for the value with the specified key in the Config file.
static int getInt(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static int getInt(java.lang.String key, int defaultValue)
          Searches for the value with the specified key in the Config file.
static int[] getIntArray(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static int[] getIntArray(java.lang.String key, int[] defaultValue)
          Searches for the value with the specified key in the Config file.
static long getLong(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static long getLong(java.lang.String key, long defaultValue)
          Searches for the value with the specified key in the Config file.
private static java.lang.String getProperty(java.lang.String key)
          Ensures keys are case-consistant when written.
static java.lang.String getString(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
          Searches for the value with the specified key in the Config file.
static java.lang.String[] getStringArray(java.lang.String key)
          Searches for the value with the specified key in the Config file.
static java.lang.String[] getStringArray(java.lang.String key, java.lang.String[] defaultValue)
          Searches for the value with the specified key in the Config file.
private static java.io.File getUserFile()
          The predefined location of the user config file.
static void init()
          Initializes the Config singleton and loads all keys from the user/default configuration files into memory.
static void load()
          load() Loads all keys from disk, preferentially using the user configuration file before trying the default configuration file.
private static java.lang.String[] parseArray(java.lang.String line)
          Helps parse int/float arrays
static void putBoolean(java.lang.String key, boolean value)
          Stores a value into memory.
static void putColor(java.lang.String key, java.awt.Color value)
          Stores a value into memory.
static void putDouble(java.lang.String key, double value)
          Stores a value into memory.
static void putFile(java.lang.String key, java.io.File value)
          Stores a value into memory.
static void putFloat(java.lang.String key, float value)
          Stores a value into memory.
static void putFloatArray(java.lang.String key, float[] array)
          Stores a value into memory.
static void putInt(java.lang.String key, int value)
          Stores a value into memory.
static void putIntArray(java.lang.String key, int[] array)
          Stores a value into memory.
static void putLong(java.lang.String key, long value)
          Stores a value into memory.
private static void putProperty(java.lang.String key, java.lang.String property)
          Ensures keys are case-consistant when written.
static void putString(java.lang.String key, java.lang.String value)
          Stores a value into memory.
static void putStringArray(java.lang.String key, java.lang.String[] array)
          Stores a value into memory.
private static java.util.Properties readDefaultProperties()
          Read in default Properties file from .jar file These values will over-ride the default values as specified in get() methods with a default value.
private static java.util.Properties readUserProperties()
          Read in user Properties file from disk
static void reset()
          Resets user configuration data with default configuration data.
static void save()
          Saves all keys to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_HEADER

public static final java.lang.String CONFIG_HEADER
See Also:
Constant Field Values

DEFAULT_FILE_NAME

public static final java.lang.String DEFAULT_FILE_NAME
See Also:
Constant Field Values

CNUL

private static final char CNUL
See Also:
Constant Field Values

SNUL

private static final java.lang.String SNUL
See Also:
Constant Field Values

prop

private static java.util.Properties prop

file

private static java.io.File file
Constructor Detail

Config

private Config()
Method Detail

init

public static void init()
Initializes the Config singleton and loads all keys from the user/default configuration files into memory.


load

public static void load()
load() Loads all keys from disk, preferentially using the user configuration file before trying the default configuration file. All keys are loaded when the init() method is called.


save

public static void save()
Saves all keys to disk. Keys are never serialized unless save() is called.


reset

public static void reset()
Resets user configuration data with default configuration data. Default configuration data is the "Universe.config" file located inside UniverseData.jar


putInt

public static void putInt(java.lang.String key,
                          int value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putLong

public static void putLong(java.lang.String key,
                           long value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putFloat

public static void putFloat(java.lang.String key,
                            float value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putDouble

public static void putDouble(java.lang.String key,
                             double value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putBoolean

public static void putBoolean(java.lang.String key,
                              boolean value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putString

public static void putString(java.lang.String key,
                             java.lang.String value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putColor

public static void putColor(java.lang.String key,
                            java.awt.Color value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putFile

public static void putFile(java.lang.String key,
                           java.io.File value)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
value - The corresponding value for this key

putIntArray

public static void putIntArray(java.lang.String key,
                               int[] array)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
array - The corresponding value for this key

putFloatArray

public static void putFloatArray(java.lang.String key,
                                 float[] array)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
array - The corresponding value for this key

putStringArray

public static void putStringArray(java.lang.String key,
                                  java.lang.String[] array)
Stores a value into memory. Remember, data is not serialized until save() is called.

Parameters:
key - The key for this data item
array - The corresponding value for this key

getString

public static java.lang.String getString(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns null if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getString

public static java.lang.String getString(java.lang.String key,
                                         java.lang.String defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getFile

public static java.io.File getFile(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns null if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getFile

public static java.io.File getFile(java.lang.String key,
                                   java.io.File defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getColor

public static java.awt.Color getColor(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns null if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getColor

public static java.awt.Color getColor(java.lang.String key,
                                      java.awt.Color defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getIntArray

public static int[] getIntArray(java.lang.String key,
                                int[] defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getFloatArray

public static float[] getFloatArray(java.lang.String key,
                                    float[] defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getStringArray

public static java.lang.String[] getStringArray(java.lang.String key,
                                                java.lang.String[] defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getIntArray

public static int[] getIntArray(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns a zero-length array if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getFloatArray

public static float[] getFloatArray(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns a zero-length array if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getStringArray

public static java.lang.String[] getStringArray(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns a zero-length array if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getBoolean

public static boolean getBoolean(java.lang.String key,
                                 boolean defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getBoolean

public static boolean getBoolean(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns false if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getInt

public static int getInt(java.lang.String key,
                         int defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getInt

public static int getInt(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns 0 if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getLong

public static long getLong(java.lang.String key,
                           long defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getLong

public static long getLong(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns 0 if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getFloat

public static float getFloat(java.lang.String key,
                             float defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getFloat

public static float getFloat(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns 0.0 if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

getDouble

public static double getDouble(java.lang.String key,
                               double defaultValue)
Searches for the value with the specified key in the Config file. If key is not found or data corresponding to key is of the incorrect type, defaultValue is returned.

Parameters:
key - The key for this data item
defaultValue - The value to return if key or data is bad
Returns:
The corresponding value for this key

getDouble

public static double getDouble(java.lang.String key)
Searches for the value with the specified key in the Config file. Returns 0.0 if key could not be found or is of the incorrect data type.

Parameters:
key - The key for this data item
Returns:
The corresponding value for this key

putProperty

private static void putProperty(java.lang.String key,
                                java.lang.String property)
Ensures keys are case-consistant when written. Since we are using a Property object, which extends Hashtable, the putProperty() is already synchronized.


getProperty

private static java.lang.String getProperty(java.lang.String key)
Ensures keys are case-consistant when written. Since we are using a Property object, which extends Hashtable, the getProperty()is already synchronized.


parseArray

private static java.lang.String[] parseArray(java.lang.String line)
Helps parse int/float arrays


getUserFile

private static java.io.File getUserFile()
The predefined location of the user config file.


readUserProperties

private static java.util.Properties readUserProperties()
Read in user Properties file from disk


readDefaultProperties

private static java.util.Properties readDefaultProperties()
Read in default Properties file from .jar file These values will over-ride the default values as specified in get() methods with a default value.



Copyright © 2001 Universe Dev Team All Rights Reserved.