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 Classm_BaseClassthe base class.protected booleanm_Multipleindicates whether the option can appear multiple times (for array properties).protected Stringm_Variablethe variable placeholder.protected booleanm_VariableModifiedwhether the variable got updated and needs propagating.protected Booleanm_VariableReferencesObjectwhether the variable references a global actor or storage.-
Fields inherited from class adams.core.option.AbstractOption
m_Commandline, m_Constraint, m_Debug, m_DefaultValue, m_MinUserMode, m_OutputDefaultValue, m_Owner, m_Property, TOOLTIP_SUFFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractArgumentOption(OptionManager owner, String commandline, String property, Object defValue)Initializes the option.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcleanUp()Cleans up data structures, frees up memory.protected abstract booleancompareValues(Object value, Object defValue)Compares the two values.ClassgetBaseClass()Returns the base class of this option.StringgetVariable()Returns the variable placeholder, if any.StringgetVariableName()Returns the variable name (without the surrounding "@{" and "}"), if any.booleanhasBaseClass()Returns whether a base class could be determined.booleanisDefaultValue()Compares the current value against the default value.protected booleanisDefaultValue(Object value)Compares the given value against the default value.booleanisMultiple()Returns true if the option can appear multiple times (for array properties).booleanisVariableAttached()Whether a variable has been attached to the option.booleanisVariableModified()Returns whether the variable got updated in the meantime and needs propagating.booleanisVariableReferencingObject()Returns whether the variable points to a global actor or storage.StringsetVariable(String value)Sets the variable placeholder to use, or null to disable.String[]toArray()Returns the current value of the option as string array.StringtoString()Returns the commandline option and the property as string.abstract StringtoString(Object obj)Returns a string representation of the specified object.StringupdateVariable()Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.StringupdateVariable(boolean silent)Updates the variable, i.e., retrieves the value for the variable and calls the read-method of this option to set it.StringupdateVariable(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 ObjectvalueOf(String s)Turns the string into the appropriate object.voidvariableChanged(VariableChangeEvent e)Gets triggered when a variable changed (added, modified, removed).-
Methods inherited from class adams.core.option.AbstractOption
dontOutputDefaultValue, getCommandline, getConstraint, getCurrentValue, getDebug, getDefaultValue, getDescriptor, getMinUserMode, getOptionHandler, getOutputDefaultValue, getOwner, getProperty, getReadMethod, getToolTipMethod, getWriteMethod, hasConstraint, isValid, noConstraint, setConstraint, setCurrentValue, setMinUserMode, setOutputDefaultValue
-
-
-
-
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)
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 used
-
-
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:
variableChangedin 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:
cleanUpin interfaceCleanUpHandler- Overrides:
cleanUpin classAbstractOption
-
-