E
- Enum typepublic class EnumParameter<E extends Enum<E>> extends Parameter<Enum<E>,E>
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(); }
Modifier and Type | Field and Description |
---|---|
protected Class<E> |
enumClass
Reference to the actual enum type, for T.valueOf().
|
constraints, defaultValue, givenValue, optionalParameter, optionid, shortDescription
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
addConstraint, getDefaultValue, getDefaultValueAsString, getFullDescription, getGivenValue, getName, getOptionID, getShortDescription, getValue, getValuesDescription, hasDefaultValue, hasValuesDescription, isDefined, isOptional, isValid, setDefaultValue, setOptional, setShortDescription, setValue, setValueInternal, tookDefaultValue, tryDefaultValue, useDefaultValue, validate
public EnumParameter(OptionID optionID, Class<E> enumClass, E defaultValue)
optionID
- the unique id of the parameterdefaultValue
- the default value of the parameterpublic EnumParameter(OptionID optionID, Class<E> enumClass, boolean optional)
optionID
- the unique id of the parameteroptional
- Flag to signal an optional parameter.public String getSyntax()
Parameter
IntParameter
should return <int>
).protected E parseValue(Object obj) throws ParameterException
Parameter
parseValue
in class Parameter<Enum<E extends Enum<E>>,E extends Enum<E>>
obj
- Object to parse (may be a string representation!)ParameterException
- when the object cannot be parsed.public String getValueAsString()
Parameter
null
public Collection<String> getPossibleValues()