Package adams.core.option
Class AbstractArgumentOption
- java.lang.Object
-
- adams.core.option.AbstractOption
-
- adams.core.option.AbstractArgumentOption
-
- All Implemented Interfaces:
CleanUpHandler
,VariableChangeListener
,Serializable
- Direct Known Subclasses:
AbstractNumericOption
,BooleanOption
,ClassOption
,CustomHooksOption
,EnumOption
,StringOption
public abstract class AbstractArgumentOption extends AbstractOption implements VariableChangeListener
The ancestor of all option classes that take an argument.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Class
m_BaseClass
the base class.protected boolean
m_Multiple
indicates whether the option can appear multiple times (for array properties).protected String
m_Variable
the variable placeholder.protected boolean
m_VariableModified
whether the variable got updated and needs propagating.protected Boolean
m_VariableReferencesObject
whether the variable references a global actor or storage.-
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
AbstractArgumentOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, UserMode minUserMode)
Initializes the option.protected
AbstractArgumentOption(OptionManager owner, String commandline, String property, Object defValue, UserMode minUserMode)
Initializes the option.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
cleanUp()
Cleans up data structures, frees up memory.protected abstract boolean
compareValues(Object value, Object defValue)
Compares the two values.Class
getBaseClass()
Returns the base class of this option.String
getVariable()
Returns the variable placeholder, if any.String
getVariableName()
Returns the variable name (without the surrounding "@{" and "}"), if any.boolean
hasBaseClass()
Returns whether a base class could be determined.boolean
isDefaultValue()
Compares the current value against the default value.protected boolean
isDefaultValue(Object value)
Compares the given value against the default value.boolean
isMultiple()
Returns true if the option can appear multiple times (for array properties).boolean
isVariableAttached()
Whether a variable has been attached to the option.boolean
isVariableModified()
Returns whether the variable got updated in the meantime and needs propagating.boolean
isVariableReferencingObject()
Returns whether the variable points to a global actor or storage.String
setVariable(String value)
Sets the variable placeholder to use, or null to disable.String[]
toArray()
Returns the current value of the option as string array.String
toString()
Returns the commandline option and the property as string.abstract String
toString(Object obj)
Returns a string representation of the specified object.String
updateVariable()
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.String
updateVariable(boolean silent)
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.String
updateVariable(boolean silent, Logger log)
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.abstract Object
valueOf(String s)
Turns the string into the appropriate object.void
variableChanged(VariableChangeEvent e)
Gets triggered when a variable changed (added, modified, removed).-
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_BaseClass
protected Class m_BaseClass
the base class.
-
m_Multiple
protected boolean m_Multiple
indicates whether the option can appear multiple times (for array properties).
-
m_Variable
protected String m_Variable
the variable placeholder.
-
m_VariableModified
protected boolean m_VariableModified
whether the variable got updated and needs propagating.
-
m_VariableReferencesObject
protected Boolean m_VariableReferencesObject
whether the variable references a global actor or storage.
-
-
Constructor Detail
-
AbstractArgumentOption
protected AbstractArgumentOption(OptionManager owner, String commandline, String property, Object defValue, UserMode minUserMode)
Initializes the option. Always outputs the default value.- Parameters:
owner
- the owner of this optioncommandline
- the commandline string to identify the option (no leading dash)property
- 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
-
AbstractArgumentOption
protected AbstractArgumentOption(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 option (no leading dash)property
- 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
-
isMultiple
public boolean isMultiple()
Returns true if the option can appear multiple times (for array properties).- Returns:
- true if the option can appear multiple times.
-
hasBaseClass
public boolean hasBaseClass()
Returns whether a base class could be determined.- Returns:
- true if a base class is available
-
getBaseClass
public Class getBaseClass()
Returns the base class of this option. In case of arrays the class of the elements.- Returns:
- the class
-
isVariableAttached
public boolean isVariableAttached()
Whether a variable has been attached to the option.- Returns:
- true if a variable placeholder has been set
-
setVariable
public String setVariable(String value)
Sets the variable placeholder to use, or null to disable.- Parameters:
value
- the variable placeholder- Returns:
- null if successfully set/unset, otherwise error message
-
getVariable
public String getVariable()
Returns the variable placeholder, if any.- Returns:
- the variable placeholder, or null if none set
-
getVariableName
public String getVariableName()
Returns the variable name (without the surrounding "@{" and "}"), if any.- Returns:
- the variable placeholder, or null if none set
-
isVariableModified
public boolean isVariableModified()
Returns whether the variable got updated in the meantime and needs propagating.- Returns:
- true if the variable got updated
-
isVariableReferencingObject
public boolean isVariableReferencingObject()
Returns whether the variable points to a global actor or storage.- Returns:
- true if the variable references a global actor or storage
-
variableChanged
public void variableChanged(VariableChangeEvent e)
Gets triggered when a variable changed (added, modified, removed).- Specified by:
variableChanged
in interfaceVariableChangeListener
- Parameters:
e
- the event
-
updateVariable
public String updateVariable()
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.- Returns:
- null if successfully updated, otherwise error message
-
updateVariable
public String updateVariable(boolean silent)
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.- Parameters:
silent
- whether to suppress error messages in the console- Returns:
- null if successfully updated, otherwise error message
-
updateVariable
public String updateVariable(boolean silent, Logger log)
Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.- Parameters:
silent
- whether to suppress error messages in the consolelog
- the logger to use for errors, can be null- Returns:
- null if successfully updated, otherwise error message
-
valueOf
public abstract Object valueOf(String s) throws Exception
Turns the string into the appropriate object.- Parameters:
s
- the string to parse- Returns:
- the generated object
- Throws:
Exception
- if parsing of string fails
-
toString
public abstract String toString(Object obj)
Returns a string representation of the specified object.- Parameters:
obj
- the object to turn into a string- Returns:
- the string representation
-
compareValues
protected abstract boolean compareValues(Object value, Object defValue)
Compares the two values.- Parameters:
value
- the value to compare against the default valuedefValue
- the default value to compare against- Returns:
- true if both are equal
-
isDefaultValue
public boolean isDefaultValue()
Compares the current value against the default value.- Returns:
- true if the value is the same as the default value
-
isDefaultValue
protected boolean isDefaultValue(Object value)
Compares the given value against the default value.- Parameters:
value
- the value to compare against the default value- Returns:
- true if the value is the same as the default value
-
toArray
public String[] toArray()
Returns the current value of the option as string array.- Returns:
- the array representation of the current value
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractOption
-
-