Package adams.core.option
Class EnumOption
- java.lang.Object
-
- adams.core.option.AbstractOption
-
- adams.core.option.AbstractArgumentOption
-
- adams.core.option.EnumOption
-
- All Implemented Interfaces:
CleanUpHandler
,VariableChangeListener
,Serializable
public class EnumOption extends AbstractArgumentOption
Option class for enums. Enums get automatically registered with the GenericObjectEditor.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected EnumWithCustomDisplay
m_CustomDisplayInstance
an instance of an enum with a custom display, used for parsing.-
Fields inherited from class adams.core.option.AbstractArgumentOption
m_BaseClass, m_Multiple, m_Variable, m_VariableModified, m_VariableReferencesObject
-
Fields inherited from class adams.core.option.AbstractOption
m_Commandline, m_Debug, m_DefaultValue, m_MinUserMode, m_OutputDefaultValue, m_Owner, m_Property, TOOLTIP_SUFFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EnumOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, UserMode minUserMode)
Initializes the option.protected
EnumOption(OptionManager owner, String commandline, String property, Object defValue, UserMode minUserMode)
Initializes the option.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addArgumentInfo(StringBuilder buffer)
Adds additional information about the argument, e.g., the class.void
cleanUp()
Cleans up data structures, frees up memory.protected boolean
compareValues(Object value, Object defValue)
Compares the two values.protected EnumWithCustomDisplay
getCustomDisplayInstance()
Tries to instantiate an instance of the enumeration type.static EnumWithCustomDisplay
getEnumInstance(Class cls)
Tries to instantiate an instance of the enumeration type.String
toString(Object obj)
Returns a string representation of the specified object.Object
valueOf(String s)
Turns the string into the appropriate object.-
Methods inherited from class adams.core.option.AbstractArgumentOption
getBaseClass, getVariable, getVariableName, hasBaseClass, isDefaultValue, isDefaultValue, isMultiple, isVariableAttached, isVariableModified, isVariableReferencingObject, setVariable, toArray, toString, updateVariable, updateVariable, updateVariable, variableChanged
-
Methods inherited from class adams.core.option.AbstractOption
getCommandline, getCurrentValue, getDebug, getDefaultValue, getDescriptor, getMinUserMode, getOptionHandler, getOutputDefaultValue, getOwner, getProperty, getReadMethod, getToolTipMethod, getWriteMethod, setCurrentValue
-
-
-
-
Field Detail
-
m_CustomDisplayInstance
protected EnumWithCustomDisplay m_CustomDisplayInstance
an instance of an enum with a custom display, used for parsing.
-
-
Constructor Detail
-
EnumOption
protected EnumOption(OptionManager owner, String commandline, String property, Object defValue, UserMode minUserMode)
Initializes the option. Will always output the default value.- Parameters:
owner
- the owner of this optioncommandline
- the commandline string to identify the optionproperty
- the name of bean propertydefValue
- the default value, if null then the owner's current state is usedminUserMode
- the minimum user mode before showing this option
-
EnumOption
protected EnumOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, UserMode minUserMode)
Initializes the option.- Parameters:
owner
- the owner of this optioncommandline
- the commandline string to identify the optionproperty
- the name of bean propertydefValue
- the default value, if null then the owner's current state is usedoutputDefValue
- whether to output the default value or notminUserMode
- the minimum user mode before showing this option
-
-
Method Detail
-
compareValues
protected boolean compareValues(Object value, Object defValue)
Compares the two values.- Specified by:
compareValues
in classAbstractArgumentOption
- Parameters:
value
- the value to compare against the default valuedefValue
- the default value to compare against- Returns:
- true if both are equal
-
getCustomDisplayInstance
protected EnumWithCustomDisplay getCustomDisplayInstance()
Tries to instantiate an instance of the enumeration type.- Returns:
- the instance or null if failed to instantiate
- See Also:
m_CustomDisplayInstance
-
getEnumInstance
public static EnumWithCustomDisplay getEnumInstance(Class cls)
Tries to instantiate an instance of the enumeration type.- Parameters:
cls
- the enum class- Returns:
- the instance or null if failed to instantiate
-
valueOf
public Object valueOf(String s) throws Exception
Turns the string into the appropriate object.- Specified by:
valueOf
in classAbstractArgumentOption
- Parameters:
s
- the string to parse- Returns:
- the generated object
- Throws:
Exception
- if parsing of string fails
-
toString
public String toString(Object obj)
Returns a string representation of the specified object.- Specified by:
toString
in classAbstractArgumentOption
- Parameters:
obj
- the object to turn into a string- Returns:
- the string representation
-
addArgumentInfo
protected void addArgumentInfo(StringBuilder buffer)
Adds additional information about the argument, e.g., the class.- Parameters:
buffer
- the buffer to add the information to
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractArgumentOption
-
-