fi.hu.cs.titokone
Class Settings

java.lang.Object
  extended byfi.hu.cs.titokone.Settings

public class Settings
extends java.lang.Object

This class keeps track of the settings. It can parse and save settings file content. It provides support for a standard set of settings, but basically anything can be stored in it. Keys used in this file cannot contain KEY_VALUE_SEPARATOR. Whitespace around KEY_VALUE_SEPARATOR is ignored.


Field Summary
private static java.lang.String COMMENT_MARKER
          This field stores the comment marker to put before any comment lines.
static java.lang.String COMPILE_MODE
           
static java.lang.String DEFAULT_STDIN
           
static java.lang.String DEFAULT_STDOUT
           
static java.lang.String KEY_VALUE_SEPARATOR
          This string separates keys from values in the settings file.
private static java.lang.String LINEBREAK_CHECK_REGEXP
          This pattern matches against 1 or more characters (there is a start of a line in the start of each String, hence ignore the first character), then 1 or more periods where there is at least one start of line (\n\n would match ^^) and then 0 or more other characters.
static java.lang.String MEMORY_SIZE
           
static java.lang.String RUN_MODE
           
private  java.util.HashMap settings
           
static java.lang.String STDIN_PATH
           
static java.lang.String STDOUT_PATH
           
static java.lang.String STDOUT_USE
           
static java.lang.String UI_LANGUAGE
          This is one of the default settings keys of values that can be stored here.
 
Constructor Summary
Settings()
          This constructor sets up a settings class with no values.
Settings(java.lang.String settingsFileContent)
          This constructor sets up a settings class with default values.
 
Method Summary
private  void doSetValue(java.lang.String key, java.lang.Object value)
          This method sets a key to a given object value.
 int getIntValue(java.lang.String key)
          This method returns the value of a certain key.
 java.lang.String[] getKeys()
          This method returns all the keys defined here.
 java.lang.String getStrValue(java.lang.String key)
          This method returns the value of a certain key.
private  void parseSettingsFile(java.lang.String fileContent)
          This method parses the fileContent string and sets up the settings HashMap values accordingly.
 void setValue(java.lang.String key, int value)
          This method sets a key to a certain integer value.
 void setValue(java.lang.String key, java.lang.String value)
          This method sets a key to a certain string value.
 java.lang.String toString()
          This method transforms this settings class into a format which can be parsed by parseSettingsFile.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

settings

private java.util.HashMap settings

KEY_VALUE_SEPARATOR

public static final java.lang.String KEY_VALUE_SEPARATOR
This string separates keys from values in the settings file. It cannot be included in the key strings.

See Also:
Constant Field Values

COMMENT_MARKER

private static final java.lang.String COMMENT_MARKER
This field stores the comment marker to put before any comment lines.

See Also:
Constant Field Values

LINEBREAK_CHECK_REGEXP

private static final java.lang.String LINEBREAK_CHECK_REGEXP
This pattern matches against 1 or more characters (there is a start of a line in the start of each String, hence ignore the first character), then 1 or more periods where there is at least one start of line (\n\n would match ^^) and then 0 or more other characters. We assume here that since Pattern.MULTILINE mode is on by default now, it will be on in other places as well.


UI_LANGUAGE

public static final java.lang.String UI_LANGUAGE
This is one of the default settings keys of values that can be stored here.

See Also:
Constant Field Values

RUN_MODE

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

COMPILE_MODE

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

DEFAULT_STDIN

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

STDIN_PATH

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

DEFAULT_STDOUT

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

STDOUT_USE

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

STDOUT_PATH

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

MEMORY_SIZE

public static final java.lang.String MEMORY_SIZE
See Also:
Constant Field Values
Constructor Detail

Settings

public Settings(java.lang.String settingsFileContent)
         throws java.text.ParseException
This constructor sets up a settings class with default values. The settingsFileContent is parsed with the help fo the parseSettingsFile() method.

Parameters:
settingsFileContent - A String containing what has been in a settings file for parsing.
Throws:
java.text.ParseException - If the settings text was not syntactically correct.

Settings

public Settings()
This constructor sets up a settings class with no values.

Method Detail

setValue

public void setValue(java.lang.String key,
                     java.lang.String value)
This method sets a key to a certain string value.

Parameters:
key - The key to point to the value.
value - The value to be stored.
Throws:
java.lang.IllegalArgumentException - If the given key contains KEY_VALUE_SEPARATOR or the value contains a linebreak in the middle (in the end it does not count), or if either are null.

setValue

public void setValue(java.lang.String key,
                     int value)
This method sets a key to a certain integer value.

Parameters:
key - The key to point to the value.
value - The value to be stored.

doSetValue

private void doSetValue(java.lang.String key,
                        java.lang.Object value)
This method sets a key to a given object value. It checks the key's validity, but assumes that the Object is representable as a valid string.

Parameters:
key - The possibly invalid key to point to the value.
value - The value to be stored.
Throws:
java.lang.IllegalArgumentException - If the key contains KEY_VALUE_SEPARATOR or is null.

getIntValue

public int getIntValue(java.lang.String key)
This method returns the value of a certain key. It will try to cast it to an integer before returning.

Parameters:
key - The key pointing to the value to be returned.
Returns:
The value the key points to, cast to an int.
Throws:
java.lang.ClassCastException - If the value was not an int.
java.lang.NullPointerException - If there was no value stored by that key (or if the value stored was null for some reason). The problem is that int cannot be null, while String in getStrValue can.

getStrValue

public java.lang.String getStrValue(java.lang.String key)
This method returns the value of a certain key. It will try to cast it to a string before returning.

Parameters:
key - The key pointing to the value to be returned.
Returns:
The value the key points to, cast to a String, or null if there was no such value.
Throws:
java.lang.ClassCastException - If the value was not a String.

getKeys

public java.lang.String[] getKeys()
This method returns all the keys defined here.


toString

public java.lang.String toString()
This method transforms this settings class into a format which can be parsed by parseSettingsFile.

Returns:
String containing the non-fixed data in this class.

parseSettingsFile

private void parseSettingsFile(java.lang.String fileContent)
                        throws java.text.ParseException
This method parses the fileContent string and sets up the settings HashMap values accordingly. It will try to cast number strings to integers.

Parameters:
fileContent - A String containing what has been in a settings file for parsing.
Throws:
java.text.ParseException - If the settings text was not syntactically correct.