E
- Enum typepublic class EnumParameter<E extends java.lang.Enum<E>> extends AbstractParameter<EnumParameter<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 java.lang.Class<E> |
enumClass
Reference to the actual enum type, for T.valueOf().
|
constraints, defaultValue, givenValue, optionalParameter, optionid, shortDescription
Constructor and Description |
---|
EnumParameter(OptionID optionID,
java.lang.Class<E> enumClass)
Constructs an enum parameter with the given optionID, constraints and
default value.
|
EnumParameter(OptionID optionID,
java.lang.Class<E> enumClass,
boolean optional)
Constructs an enum parameter with the given optionID, constraints and
default value.
|
EnumParameter(OptionID optionID,
java.lang.Class<E> enumClass,
E defaultValue)
Constructs an enum parameter with the given optionID, constraints and
default value.
|
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuilder |
describeValues(java.lang.StringBuilder buf)
Describe the valid values.
|
java.util.Collection<java.lang.String> |
getPossibleValues()
Get a list of possible values for this enum parameter.
|
java.lang.String |
getSyntax()
Returns a string representation of the parameter's type (e.g. an
IntParameter
should return <int> ). |
java.lang.String |
getValueAsString()
Get the value as string.
|
private java.lang.String |
joinEnumNames(java.lang.String separator)
Utility method for merging possible values into a string for informational
messages.
|
protected E |
parseValue(java.lang.Object obj)
Parse a given value into the destination type.
|
addConstraint, getConstraints, getDefaultValue, getDefaultValueAsString, getOptionID, getShortDescription, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setShortDescription, setValue, setValueInternal, tookDefaultValue, tryDefaultValue, validate
public EnumParameter(OptionID optionID, java.lang.Class<E> enumClass, E defaultValue)
optionID
- the unique id of the parameterdefaultValue
- the default value of the parameterpublic EnumParameter(OptionID optionID, java.lang.Class<E> enumClass, boolean optional)
optionID
- the unique id of the parameteroptional
- Flag to signal an optional parameter.public java.lang.String getSyntax()
Parameter
IntParameter
should return <int>
).protected E parseValue(java.lang.Object obj) throws ParameterException
AbstractParameter
parseValue
in class AbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,E extends java.lang.Enum<E>>
obj
- Object to parse (may be a string representation!)ParameterException
- when the object cannot be parsed.public java.lang.String getValueAsString()
Parameter
null
getValueAsString
in interface Parameter<E extends java.lang.Enum<E>>
getValueAsString
in class AbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,E extends java.lang.Enum<E>>
public java.lang.StringBuilder describeValues(java.lang.StringBuilder buf)
Parameter
describeValues
in interface Parameter<E extends java.lang.Enum<E>>
describeValues
in class AbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,E extends java.lang.Enum<E>>
buf
- Buffer to append topublic java.util.Collection<java.lang.String> getPossibleValues()
private java.lang.String joinEnumNames(java.lang.String separator)
separator
- char sequence to use as a separator for enum values.{VAL1}{separator}{VAL2}{separator}...
Copyright © 2019 ELKI Development Team. License information.