Class EnumParameter<E extends java.lang.Enum<E>>
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<EnumParameter<E>,E>
-
- elki.utilities.optionhandling.parameters.EnumParameter<E>
-
- Type Parameters:
E
- Enum type
- All Implemented Interfaces:
Parameter<E>
public class EnumParameter<E extends java.lang.Enum<E>> extends AbstractParameter<EnumParameter<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(); }
- Since:
- 0.4.0
- Author:
- Florian Nuecke
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<E>
enumClass
Reference to the actual enum type, for T.valueOf().-
Fields inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
constraints, defaultValue, givenValue, optionalParameter, optionid
-
-
Constructor Summary
Constructors Constructor 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, E defaultValue)
Constructs an enum parameter with the given optionID, constraints and default value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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., anIntParameter
should return<int>
).java.lang.String
getValueAsString()
Get the value as string.boolean
grab(Parameterization config, java.util.function.Consumer<E> consumer)
Get the parameter.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.-
Methods inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
addConstraint, getConstraints, getDefaultValue, getDefaultValueAsString, getOptionID, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setValue, setValueInternal, tookDefaultValue, tryDefaultValue, validate
-
-
-
-
Constructor Detail
-
EnumParameter
public EnumParameter(OptionID optionID, java.lang.Class<E> enumClass, E defaultValue)
Constructs an enum parameter with the given optionID, constraints and default value.- Parameters:
optionID
- the unique id of the parameterdefaultValue
- the default value of the parameter
-
-
Method Detail
-
getSyntax
public java.lang.String getSyntax()
Description copied from interface:Parameter
Returns a string representation of the parameter's type (e.g., anIntParameter
should return<int>
).- Returns:
- a string representation of the parameter's type
-
parseValue
protected E parseValue(java.lang.Object obj) throws ParameterException
Description copied from class:AbstractParameter
Parse a given value into the destination type.- Specified by:
parseValue
in classAbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,E extends java.lang.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 java.lang.String getValueAsString()
Description copied from interface:Parameter
Get the value as string. May returnnull
- Returns:
- Value as string
-
describeValues
public java.lang.StringBuilder describeValues(java.lang.StringBuilder buf)
Description copied from interface:Parameter
Describe the valid values.- Specified by:
describeValues
in interfaceParameter<E extends java.lang.Enum<E>>
- Overrides:
describeValues
in classAbstractParameter<EnumParameter<E extends java.lang.Enum<E>>,E extends java.lang.Enum<E>>
- Parameters:
buf
- Buffer to append to- Returns:
- Buffer
-
getPossibleValues
public java.util.Collection<java.lang.String> getPossibleValues()
Get a list of possible values for this enum parameter.- Returns:
- list of strings representing possible enum values.
-
joinEnumNames
private java.lang.String joinEnumNames(java.lang.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}...
-
grab
public boolean grab(Parameterization config, java.util.function.Consumer<E> consumer)
Get the parameter.- Parameters:
config
- Parameterizationconsumer
- Output consumer- Returns:
true
if valid
-
-