be.hogent.tarsos.util
Class Configuration

java.lang.Object
  extended by be.hogent.tarsos.util.Configuration

public final class Configuration
extends java.lang.Object

Utility class to access (read and write) configuration settings. There are utility methods for booleans, doubles and integers. It automatically converts directory separators with the correct file separator for the current operating system.

Author:
Joren Six

Nested Class Summary
static interface Configuration.ConfigChangeListener
          An interface used to send notifications of a changed configurations setting.
 
Method Summary
static void addListener(Configuration.ConfigChangeListener listener)
           
static java.lang.String get(ConfKey key)
          Read the configuration for a certain key.
static boolean getBoolean(ConfKey key)
          Parses a configured string as a boolean.
static java.lang.String getDescription(ConfKey key)
          Read the description name for a certain key.
static double getDouble(ConfKey key)
          Read the configuration for a certain key.
static java.io.File getFile(ConfKey key)
           
static java.lang.String getHumanName(ConfKey key)
          Read the human name for a certain key.
static int getInt(ConfKey key)
          Read the configured Integer for a certain key.
static java.util.List<java.lang.String> getList(ConfKey key)
          Return a list of values stored with a key
static PitchDetectionMode getPitchDetectionMode(ConfKey key)
          Return a configured PitchDetectionMode
static void set(ConfKey key, java.lang.Object value)
          Delegates to either the set(String) method or setList method to store strings or lists respectively.
static void set(ConfKey key, java.lang.String value)
          Set a configuration parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static java.lang.String get(ConfKey key)
Read the configuration for a certain key. If the key can not be found in the UserPreferences the default is loaded from a properties file, written in the UserPreferences, and returned. Otherwise the user configured value is returned.

Parameters:
key - the configuration key
Returns:
if the key is configured, the configured value. Otherwise the default value is returned.

getHumanName

public static java.lang.String getHumanName(ConfKey key)
Read the human name for a certain key.

Parameters:
key - the configuration key
Returns:
The human name for the configuration or null.

getDescription

public static java.lang.String getDescription(ConfKey key)
Read the description name for a certain key.

Parameters:
key - the configuration key
Returns:
The human name for the configuration or null.

getInt

public static int getInt(ConfKey key)
Read the configured Integer for a certain key. If the key can not be found in the UserPreferences the default is loaded from a properties file, written in the UserPreferences, and returned. Otherwise the configured value is returned.

Parameters:
key - The configuration key.
Returns:
if the key is configured, the configured value. Otherwise the default value is returned.
Throws:
java.lang.NumberFormatException - If the configured value can not be parsed to an integer a is thrown.

getDouble

public static double getDouble(ConfKey key)
Read the configuration for a certain key. If the key can not be found in the UserPreferences the default is loaded from a properties file, written in the UserPreferences, and returned. Otherwise the configured value is returned.

Parameters:
key - The configuration key.
Returns:
If the key is configured, the configured value. Otherwise the default value is returned.

getBoolean

public static boolean getBoolean(ConfKey key)
Parses a configured string as a boolean. The boolean returned represents the value true if the configured value is not null and is equal, ignoring case, to the string "true".

Example: Boolean.parseBoolean("True") returns true.
Example: Boolean.parseBoolean("yes") returns false.

Parameters:
key - the name of the configuration parameter
Returns:
true if the configured value is not null and is equal, ignoring case, to the string "true", false otherwise.

getPitchDetectionMode

public static PitchDetectionMode getPitchDetectionMode(ConfKey key)
Return a configured PitchDetectionMode

Parameters:
key - the key of the configured value
Returns:
a PitchDetectionMode if the configured string represents a correct value.

set

public static void set(ConfKey key,
                       java.lang.String value)
Set a configuration parameter. Sanitizes the value automatically: removes whitespace and correct file separators if the configured value is a directory.

Parameters:
key - the key
value - the value

getList

public static java.util.List<java.lang.String> getList(ConfKey key)
Return a list of values stored with a key

Parameters:
key - The key.
Returns:
A list of configured values.

addListener

public static void addListener(Configuration.ConfigChangeListener listener)
Parameters:
listener -

set

public static void set(ConfKey key,
                       java.lang.Object value)
Delegates to either the set(String) method or setList method to store strings or lists respectively.

Parameters:
key -
value -

getFile

public static java.io.File getFile(ConfKey key)