Package adams.core.option
Class AbstractNumericOption<T extends Number>
- java.lang.Object
-
- adams.core.option.AbstractOption
-
- adams.core.option.AbstractArgumentOption
-
- adams.core.option.AbstractNumericOption<T>
-
- Type Parameters:
T
- the type of number
- All Implemented Interfaces:
CleanUpHandler
,VariableChangeListener
,Serializable
- Direct Known Subclasses:
ByteOption
,DoubleOption
,FloatOption
,IntegerOption
,LongOption
,ShortOption
public abstract class AbstractNumericOption<T extends Number> extends AbstractArgumentOption
Handles options with numeric arguments.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected T
m_LowerBound
the lower bound for numeric values.protected T
m_UpperBound
the upper bound for numeric values.-
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
AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, UserMode minUserMode)
Initializes the option.protected
AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, T lower, T upper, UserMode minUserMode)
Initializes the option.protected
AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, UserMode minUserMode)
Initializes the option.protected
AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, T lower, T upper, UserMode minUserMode)
Initializes the option.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected T
checkBounds(T number)
Checks whether the number is within the specified bounds (if any).protected boolean
compareValues(Object value, Object defValue)
Compares the two values.T
getLowerBound()
Returns the lower bound for this option.T
getUpperBound()
Returns the lower bound for this option.boolean
hasLowerBound()
Checks whether a lower bound has been defined for this option.boolean
hasUpperBound()
Checks whether a lower bound has been defined for this option.boolean
isValid(T number)
Checks whether the number is within the specified bounds (if any).String
toString(Object obj)
Returns a string representation of the specified object.T
valueOf(String s)
Turns the string into the appropriate number.-
Methods inherited from class adams.core.option.AbstractArgumentOption
cleanUp, 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
-
-
-
-
Constructor Detail
-
AbstractNumericOption
protected AbstractNumericOption(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 option (no leading dash)property
- the name of bean propertydefValue
- the default value, if null then the owner's current state is used
-
AbstractNumericOption
protected AbstractNumericOption(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 not
-
AbstractNumericOption
protected AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, T lower, T upper, 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 usedlower
- the lower bound (incl; only for numeric values), use null to use unboundedupper
- the upper bound (incl; only for numeric values), use null to use unboundedminUserMode
- the minimum user mode before showing this option
-
AbstractNumericOption
protected AbstractNumericOption(OptionManager owner, String commandline, String property, Object defValue, boolean outputDefValue, T lower, T upper, 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 notlower
- the lower bound (incl; only for numeric values), use null to use unboundedupper
- the upper bound (incl; only for numeric values), use null to use unboundedminUserMode
- the minimum user mode before showing this option
-
-
Method Detail
-
hasLowerBound
public boolean hasLowerBound()
Checks whether a lower bound has been defined for this option.- Returns:
- true if lower bound exists
-
getLowerBound
public T getLowerBound()
Returns the lower bound for this option.- Returns:
- the lower bound, can be null if none defined
-
hasUpperBound
public boolean hasUpperBound()
Checks whether a lower bound has been defined for this option.- Returns:
- true if lower bound exists
-
getUpperBound
public T getUpperBound()
Returns the lower bound for this option.- Returns:
- the lower bound, can be null if none defined
-
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
-
checkBounds
protected T checkBounds(T number)
Checks whether the number is within the specified bounds (if any).- Parameters:
number
- the number to check- Returns:
- the default value for this option, if the bounds were defined and the value was outside
-
isValid
public boolean isValid(T number)
Checks whether the number is within the specified bounds (if any). If not, uses the owner's logger to output a warning message.- Parameters:
number
- the number to check- Returns:
- the default value for this option, if the bounds were defined and the value was outside
-
valueOf
public T valueOf(String s) throws Exception
Turns the string into the appropriate number.- Specified by:
valueOf
in classAbstractArgumentOption
- Parameters:
s
- the string to parse- Returns:
- the generated number
- Throws:
Exception
- if parsing of string fails- See Also:
checkBounds(Number)
-
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
-
-