- java.lang.Object
-
- snaq.util.jclap.Option<E>
-
- Type Parameters:
E- the return type of the option
- Direct Known Subclasses:
BooleanOption,DoubleOption,EnumeratedOption,FloatOption,IntegerOption,LocalDateOption,LongOption,StringOption
public abstract class Option<E> extends Object
Base implementation of a command-line option.- Author:
- Giles Winstanley
-
-
Field Summary
Fields Modifier and Type Field Description protected static ResourceBundleBUNDLEResources for internationalization.protected static LocaleLOCALELocalefor help/error display.protected static intMAX_COUNT_LIMITLimit to maximum number of occurrences required for this option (set to an arbitrary 100).protected static intMIN_COUNT_LIMITLimit to minimum number of occurrences required for this option.
-
Constructor Summary
Constructors Modifier Constructor Description protectedOption(String shortName, String longName, String description, boolean requiresValue, boolean mandatory, boolean allowMany)Creates a newOptioninstance.protectedOption(String shortName, String longName, String description, boolean requiresValue, int minCount, int maxCount)Creates a newOptioninstance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidaddValue(E value)Adds the specified value to the list of those parsed.booleanequals(Object obj)StringgetDescription()StringgetLongName()intgetMaxCount()intgetMinCount()StringgetShortName()abstract Class<E>getType()Returns the class type of value this option can take.List<E>getValues()inthashCode()booleanisAllowMany()booleanisHidden()booleanisMandatory()protected abstract EparseValue(String arg, Locale locale)Parses the argument string for an option value, optionally using the specified locale for reference (e.g.booleanrequiresValue()Option<E>setHidden()Sets the flag to hide this option from the usage message.voidsetMinMaxCounts(int minCount, int maxCount)Sets the minimum/maximum value counts for this option.StringtoString()
-
-
-
Field Detail
-
MIN_COUNT_LIMIT
protected static final int MIN_COUNT_LIMIT
Limit to minimum number of occurrences required for this option.- See Also:
- Constant Field Values
-
MAX_COUNT_LIMIT
protected static final int MAX_COUNT_LIMIT
Limit to maximum number of occurrences required for this option (set to an arbitrary 100).- See Also:
- Constant Field Values
-
LOCALE
protected static final Locale LOCALE
Localefor help/error display.
-
BUNDLE
protected static final ResourceBundle BUNDLE
Resources for internationalization.
-
-
Constructor Detail
-
Option
protected Option(String shortName, String longName, String description, boolean requiresValue, int minCount, int maxCount)
Creates a newOptioninstance.- Parameters:
shortName- short name of the option (must be non-null; e.g. -?)longName- long name of the option (e.g. --help)description- helpful description of the option (printed for usage message)requiresValue- whether this option requires a subsequently-specified valueminCount- minimum number of occurrences required for this optionmaxCount- maximum number of occurrences required for this option
-
Option
protected Option(String shortName, String longName, String description, boolean requiresValue, boolean mandatory, boolean allowMany)
Creates a newOptioninstance.- Parameters:
shortName- short name of the option (must be non-null; e.g. -?)longName- long name of the option (e.g. --help)description- helpful description of the option (printed for usage message)requiresValue- whether this option requires a subsequently-specified valuemandatory- whether this option must be specifiedallowMany- whether this option can take more than one value (i.e. be specified more than once)
-
-
Method Detail
-
getType
public abstract Class<E> getType()
Returns the class type of value this option can take.- Returns:
- Class instance
-
addValue
protected void addValue(E value) throws OptionException
Adds the specified value to the list of those parsed.- Parameters:
value- the value to add to this option- Throws:
OptionException- if a single-value option already has a value
-
parseValue
protected abstract E parseValue(String arg, Locale locale) throws OptionException
Parses the argument string for an option value, optionally using the specified locale for reference (e.g. for date parsing).- Parameters:
arg- string argument from which a value is to be parsedlocale- locale as specified when initializing theCLAParserinstance- Returns:
- Value of the parsed argument string
- Throws:
OptionException- if a problem occurs while parsing the argument string
-
getShortName
public String getShortName()
- Returns:
- short name of this option
-
getLongName
public String getLongName()
- Returns:
- long name of this option
-
getDescription
public String getDescription()
- Returns:
- description text of this option
-
requiresValue
public boolean requiresValue()
- Returns:
- whether this option requires a value
-
getMinCount
public int getMinCount()
- Returns:
- minimum acceptable value count for this option
-
getMaxCount
public int getMaxCount()
- Returns:
- maximum acceptable value count for this option
-
isMandatory
public boolean isMandatory()
- Returns:
- whether this option is mandatory
-
isAllowMany
public boolean isAllowMany()
- Returns:
- whether this option may have multiple values set
-
setMinMaxCounts
public void setMinMaxCounts(int minCount, int maxCount)Sets the minimum/maximum value counts for this option.- Parameters:
minCount- minimum count for the optionmaxCount- maximum count for the option
-
setHidden
public Option<E> setHidden()
Sets the flag to hide this option from the usage message.- Returns:
- reference to option
-
isHidden
public boolean isHidden()
- Returns:
- whether this option is hidden from the usage message
-
-