de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters
Class EnumParameter<E extends Enum<E>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter<Enum<E>,E>
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.EnumParameter<E>
Type Parameters:
E - Enum type

public class EnumParameter<E extends Enum<E>>
extends Parameter<Enum<E>,E>

Parameter class for a parameter specifying an enum type.

Usage:

 // Enum declaration.
 enum MyEnum { VALUE1, VALUE2 };
 // Parameter value holder.
 MyEnum myEnumParameter;
 
 // ...
 
 // Parameterization.
 EnumParameter<MyEnum> param = new EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class);
 // OR
 EnumParameter<MyEnum> param = new EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class, MyEnum.VALUE1);
 // OR
 EnumParameter<MyEnum> param = new EnumParameter<MyEnum>(ENUM_PROPERTY_ID, MyEnum.class, true);
 
 if(config.grab(param)) {
   myEnumParameter = param.getValue();
 }
 
 


Field Summary
protected  Class<E> enumClass
          Reference to the actual enum type, for T.valueOf().
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
constraints, defaultValue, givenValue, optionalParameter, optionid, shortDescription
 
Constructor Summary
EnumParameter(OptionID optionID, Class<E> enumClass)
          Constructs an enum parameter with the given optionID, constraints and default value.
EnumParameter(OptionID optionID, Class<E> enumClass, boolean optional)
          Constructs an enum parameter with the given optionID, constraints and default value.
EnumParameter(OptionID optionID, Class<E> enumClass, E defaultValue)
          Constructs an enum parameter with the given optionID, constraints and default value.
 
Method Summary
 Collection<String> getPossibleValues()
          Get a list of possible values for this enum parameter.
 String getSyntax()
          Returns a string representation of the parameter's type (e.g. an IntParameter should return <int>).
 String getValueAsString()
          Get the value as string.
private  String joinEnumNames(String separator)
          Utility method for merging possible values into a string for informational messages.
protected  E parseValue(Object obj)
          Parse a given value into the destination type.
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter
addConstraint, getDefaultValue, getDefaultValueAsString, getFullDescription, getGivenValue, getName, getOptionID, getShortDescription, getValue, getValuesDescription, hasDefaultValue, hasValuesDescription, isDefined, isOptional, isValid, setDefaultValue, setOptional, setShortDescription, setValue, setValueInternal, tookDefaultValue, tryDefaultValue, useDefaultValue, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enumClass

protected Class<E extends Enum<E>> enumClass
Reference to the actual enum type, for T.valueOf().

Constructor Detail

EnumParameter

public EnumParameter(OptionID optionID,
                     Class<E> enumClass,
                     E defaultValue)
Constructs an enum parameter with the given optionID, constraints and default value.

Parameters:
optionID - the unique id of the parameter
defaultValue - the default value of the parameter

EnumParameter

public EnumParameter(OptionID optionID,
                     Class<E> enumClass,
                     boolean optional)
Constructs an enum parameter with the given optionID, constraints and default value.

Parameters:
optionID - the unique id of the parameter
optional - Flag to signal an optional parameter.

EnumParameter

public EnumParameter(OptionID optionID,
                     Class<E> enumClass)
Constructs an enum parameter with the given optionID, constraints and default value.

Parameters:
optionID - the unique id of the parameter
Method Detail

getSyntax

public String getSyntax()
Description copied from class: Parameter
Returns a string representation of the parameter's type (e.g. an IntParameter should return <int>).

Specified by:
getSyntax in class Parameter<Enum<E extends Enum<E>>,E extends Enum<E>>
Returns:
a string representation of the parameter's type

parseValue

protected E parseValue(Object obj)
                                throws ParameterException
Description copied from class: Parameter
Parse a given value into the destination type.

Specified by:
parseValue in class Parameter<Enum<E extends Enum<E>>,E extends Enum<E>>
Parameters:
obj - Object to parse (may be a string representation!)
Returns:
Parsed object
Throws:
ParameterException - when the object cannot be parsed.

getValueAsString

public String getValueAsString()
Description copied from class: Parameter
Get the value as string. May return null

Specified by:
getValueAsString in class Parameter<Enum<E extends Enum<E>>,E extends Enum<E>>
Returns:
Value as string

getPossibleValues

public Collection<String> getPossibleValues()
Get a list of possible values for this enum parameter.

Returns:
list of strings representing possible enum values.

joinEnumNames

private String joinEnumNames(String separator)
Utility method for merging possible values into a string for informational messages.

Parameters:
separator - char sequence to use as a separator for enum values.
Returns:
{VAL1}{separator}{VAL2}{separator}...

Release 0.4.0 (2011-09-20_1324)