org.dllearner.core.options
Class ConfigOption<T>

java.lang.Object
  extended by org.dllearner.core.options.ConfigOption<T>
Type Parameters:
T - The type of the config option, e.g. Integer, String etc.
Direct Known Subclasses:
BooleanConfigOption, DoubleConfigOption, IntegerConfigOption, StringConfigOption, StringSetConfigOption, StringTupleListConfigOption, URLConfigOption

public abstract class ConfigOption<T>
extends Object

This class represents a configuration option (without a value for the option). Note: Currently, handling the type of a configuration option is not straightforward to implement, because Java Generics information is erased at runtime. This will be fixed in Java 7, in particular JSR 308, which is due at approx. the beginning of 2009.

Author:
Jens Lehmann

Constructor Summary
ConfigOption(String name, String description)
          Calls this(name, description, null, false, true).
ConfigOption(String name, String description, T defaultValue)
          Calls this(name, description, defaultValue, false, true).
ConfigOption(String name, String description, T defaultValue, boolean mandatory, boolean requiresInit)
          Constructs a component configuration option.
 
Method Summary
abstract  boolean checkType(Object object)
          Checks whether the object has the correct type to be used as a value for this option (this method is necessary, because generic information is erased at runtime in Java).
 String getAllowedValuesDescription()
           
 T getDefaultValue()
           
 String getDefaultValueInJava()
           
 String getDescription()
           
 String getJavaDocString()
           
 SortedSet<String> getJavaImports()
          TODO Method should be removed and a mapping table in ConfigJavaGenerator created instead.
 String getName()
           
abstract  String getValueFormatting(T value)
          Get a formatted value to put into configuration file.
abstract  String getValueTypeAsJavaString()
           
 boolean isMandatory()
          Specifies whether this option is mandatory for the component.
abstract  boolean isValidValue(T value)
          Checks whether the value is valid, e.g. passing 1985 as integer value for an option, which requires values between 0 and 1, is not valid.
 boolean requiresInit()
          Specifies whether setting this option requires that the component or any components depending on this component need to be (re-)initialised.
 void setDefaultValue(T defaultValue)
           
 void setMandatory(boolean mandatory)
           
 void setRequiresInit(boolean requiresInit)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigOption

public ConfigOption(String name,
                    String description)
Calls this(name, description, null, false, true).

Parameters:
name - Name of config option.
description - Explanation of option.

ConfigOption

public ConfigOption(String name,
                    String description,
                    T defaultValue)
Calls this(name, description, defaultValue, false, true).

Parameters:
name - Name of config option.
description - Explanation of option.
defaultValue - Standard value of option.

ConfigOption

public ConfigOption(String name,
                    String description,
                    T defaultValue,
                    boolean mandatory,
                    boolean requiresInit)
Constructs a component configuration option.

Parameters:
name - Name of config option.
description - Explanation of option.
defaultValue - Standard value of option.
mandatory - Specifies whether assigning a value to the option is required.
requiresInit - Says whether init() has to be called again when the option is changed.
Method Detail

getName

public String getName()
Returns:
The name of this option.

getDescription

public String getDescription()
Returns:
The textual description of this option.

getDefaultValue

public T getDefaultValue()
Returns:
the defaultValue

getDefaultValueInJava

public String getDefaultValueInJava()
Returns:
the defaultValue

isMandatory

public boolean isMandatory()
Specifies whether this option is mandatory for the component. (Mandatory means that this component cannot be initialised without setting a value for this option.)

Returns:
True if option is mandatory for component, false otherwise.

requiresInit

public boolean requiresInit()
Specifies whether setting this option requires that the component or any components depending on this component need to be (re-)initialised.

Returns:
True if option requires init, false otherwise.

getJavaImports

public SortedSet<String> getJavaImports()
TODO Method should be removed and a mapping table in ConfigJavaGenerator created instead. gets java imports

Returns:
Java imports.

checkType

public abstract boolean checkType(Object object)
Checks whether the object has the correct type to be used as a value for this option (this method is necessary, because generic information is erased at runtime in Java).

Parameters:
object - The object to check.
Returns:
True of the type is correct, false otherwise.

isValidValue

public abstract boolean isValidValue(T value)
Checks whether the value is valid, e.g. passing 1985 as integer value for an option, which requires values between 0 and 1, is not valid.

Parameters:
value - A value for the option.
Returns:
True if the value is valid and false otherwise.

getValueTypeAsJavaString

public abstract String getValueTypeAsJavaString()

getAllowedValuesDescription

public String getAllowedValuesDescription()

setDefaultValue

public void setDefaultValue(T defaultValue)
Parameters:
defaultValue - the defaultValue to set

setMandatory

public void setMandatory(boolean mandatory)
Parameters:
mandatory - the mandatory to set

setRequiresInit

public void setRequiresInit(boolean requiresInit)
Parameters:
requiresInit - the requiresInit to set

toString

public String toString()
Overrides:
toString in class Object

getJavaDocString

public String getJavaDocString()

getValueFormatting

public abstract String getValueFormatting(T value)
Get a formatted value to put into configuration file.

Parameters:
value - Option value.
Returns:
A string to put into a conf file.


SourceForge.net Logo DL-Learner is licenced under the terms of the GNU General Public License.
Copyright © 2007-2008 Jens Lehmann