com.mcdermottroe.exemplar.ui
Class Options

java.lang.Object
  extended by com.mcdermottroe.exemplar.ui.Options

public final class Options
extends Object

A class to allow for the global tracking of options selected via any of the UI modules.

Since:
0.1

Field Summary
private static boolean debug
          Special case for the debug option to prevent infinite looping in assertions.
private static Map<String,Option<?>> options
          The map containing all of the options.
private static boolean uiFinished
          Whether or not the UI has finished setting the options.
 
Constructor Summary
private Options()
          Private constructor to make sure that nobody can instantiate this class.
 
Method Summary
static boolean allMandatoryOptionsSet()
          Check that all of the mandatory options have been set.
static String describeDefault(String optionName)
          Format the current value of the Option as a human readable String.
private static Option<?> get(String optionName)
          Get the value associated with a particular option.
static Boolean getBoolean(String optionName)
          Convenience routine for getting the value of an Option which is known to be a Boolean.
static String getDescription(String optionName)
          Get the description registered for the given option.
static Map<String,String> getEnumDescriptions(String optionName)
          Get the descriptions of the valid values for a given Enum.
static Integer getInteger(String optionName)
          Convenience routine for getting the value of an Option which is known to be a Integer.
static Set<String> getOptionNames()
          Get the names of all the options.
static String getString(String optionName)
          Convenience routine for getting the value of an Option which is known to be a String.
private static void init()
          Initialisation routine to get the options Map synced up with the .properties file which defines the legal options and their values.
static boolean isArgument(String optionName)
          Check if the named option is an Argument, in other words, it takes one value only.
static boolean isDebugSet()
          Find out if debugging functionality is activated.
static boolean isEnum(String optionName)
          Check if the named option is an Enum, in other words, it takes one or more values all of which must be from a specific set of values.
static boolean isInitialised()
          Check if the options store has been initialised.
static boolean isLegal(String optionName)
          Determine whether or not a given option name is legal.
static boolean isMandatory(String optionName)
          Convenience routine for finding out if an Option is mandatory or not.
static boolean isMultiValue(String optionName)
          Convenience routine for finding out if an Option is a multi-value type or not.
static boolean isSet(String enumName, String enumValue)
          Convenience routine for testing whether or not a particular value in an Enum is set.
static boolean isSwitch(String optionName)
          Check if the named option is a Switch, in other words, it takes no value.
static void reset()
          Reset the options back to the default.
static void set(String optionName, String optionValue)
          Set the value of a particular option in the stash.
static void setUIFinished()
          Allow a UI to notify other parts of the program that it has finished setting all the options that it's going to set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

options

private static Map<String,Option<?>> options
The map containing all of the options.


uiFinished

private static boolean uiFinished
Whether or not the UI has finished setting the options.


debug

private static boolean debug
Special case for the debug option to prevent infinite looping in assertions.

Constructor Detail

Options

private Options()
Private constructor to make sure that nobody can instantiate this class.

Method Detail

init

private static void init()
Initialisation routine to get the options Map synced up with the .properties file which defines the legal options and their values. To avoid having to throw exceptions for nearly every method this routine guarantees that the options stash will be initialised, however it does NOT guarantee that there will be anything in it.


reset

public static void reset()
Reset the options back to the default.


setUIFinished

public static void setUIFinished()
Allow a UI to notify other parts of the program that it has finished setting all the options that it's going to set.


isDebugSet

public static boolean isDebugSet()
Find out if debugging functionality is activated.

Returns:
True if debugging is active, false otherwise.

isInitialised

public static boolean isInitialised()
Check if the options store has been initialised.

Returns:
True if the options store has been initialised, false otherwise.

getOptionNames

public static Set<String> getOptionNames()
Get the names of all the options.

Returns:
A Set of String representaions of the option names

get

private static Option<?> get(String optionName)
Get the value associated with a particular option.

Parameters:
optionName - The name of the option to return the value for.
Returns:
The value associated with the given option name.

set

public static void set(String optionName,
                       String optionValue)
Set the value of a particular option in the stash.

Parameters:
optionName - The name of the option to set.
optionValue - The value of the option to set.

isLegal

public static boolean isLegal(String optionName)
Determine whether or not a given option name is legal.

Parameters:
optionName - The name of the option to check
Returns:
True if the option name is legal, false otherwise.

isMandatory

public static boolean isMandatory(String optionName)
Convenience routine for finding out if an Option is mandatory or not.

Parameters:
optionName - The name of the option to check.
Returns:
True if the Option is mandatory, false otherwise.

isMultiValue

public static boolean isMultiValue(String optionName)
Convenience routine for finding out if an Option is a multi-value type or not.

Parameters:
optionName - The name of the Option to check.
Returns:
True if the Option is a multi-value, false otherwise.

getDescription

public static String getDescription(String optionName)
Get the description registered for the given option.

Parameters:
optionName - The name of the option the description of which to fetch.
Returns:
The description of the given option.

getEnumDescriptions

public static Map<String,String> getEnumDescriptions(String optionName)
Get the descriptions of the valid values for a given Enum.

Parameters:
optionName - The name of the Enum.
Returns:
A Map where the keys are the names of the allowed Enum values and the values are the descriptions of those values. Returns null if the option requested is not an Enum.

describeDefault

public static String describeDefault(String optionName)
Format the current value of the Option as a human readable String.

Parameters:
optionName - The name of the Option the value of which to describe.
Returns:
A human readable representation of the requested object.

getString

public static String getString(String optionName)
Convenience routine for getting the value of an Option which is known to be a String.

Parameters:
optionName - The name of the Option to fetch.
Returns:
A String if the option holds a String, returns null otherwise.

getBoolean

public static Boolean getBoolean(String optionName)
Convenience routine for getting the value of an Option which is known to be a Boolean.

Parameters:
optionName - The name of the Option to fetch.
Returns:
A Boolean if the option holds a Boolean, null otherwise.

getInteger

public static Integer getInteger(String optionName)
Convenience routine for getting the value of an Option which is known to be a Integer.

Parameters:
optionName - The name of the Option to fetch.
Returns:
A Integer if the option holds a Integer, null otherwise.

isSet

public static boolean isSet(String enumName,
                            String enumValue)
Convenience routine for testing whether or not a particular value in an Enum is set.

Parameters:
enumName - The name of the Enum
enumValue - The value to query
Returns:
true if the value is present in the set of values for that Enum, false if it is not, throws an exception for all other conditions.

allMandatoryOptionsSet

public static boolean allMandatoryOptionsSet()
Check that all of the mandatory options have been set.

Returns:
True if all of the mandatory options have been given a value, false otherwise.

isArgument

public static boolean isArgument(String optionName)
Check if the named option is an Argument, in other words, it takes one value only.

Parameters:
optionName - The name of the option to check.
Returns:
True if the option is an Argument, false otherwise.

isEnum

public static boolean isEnum(String optionName)
Check if the named option is an Enum, in other words, it takes one or more values all of which must be from a specific set of values.

Parameters:
optionName - The name of the option to check.
Returns:
True if the option is an Enum, false otherwise.

isSwitch

public static boolean isSwitch(String optionName)
Check if the named option is a Switch, in other words, it takes no value. The presence of the option indicates "true" and the absence "false".

Parameters:
optionName - The name of the option to check.
Returns:
True if the option is a Switch, false otherwise.