common.cmdline
Class StringOption

java.lang.Object
  extended by common.cmdline.AbstractOption
      extended by common.cmdline.StringOption
All Implemented Interfaces:
Option

public class StringOption
extends AbstractOption

Option that takes string values. If a string option occurs more than once on a command line, this class prints a warning and ignores all but the last occurrence.


Field Summary
 
Fields inherited from class common.cmdline.AbstractOption
DOC_OFFSET, longForms, occurred, shortForms
 
Constructor Summary
StringOption(java.lang.String shortForm, java.lang.String longForm, java.lang.String def, java.lang.String docStr)
          Creates a string option and registers it with the Parser class.
 
Method Summary
 boolean expectsValue()
          Returns true if this option expects a value on the command line.
 java.lang.String getUsageString()
          Returns a string that documents the option.
 java.lang.String getValue()
          Returns the value specified on the command line for this option, or the default value if the option did not occur.
 void recordOccurrence(java.lang.String form, java.lang.String valueStr)
          This default implementation prints a warning if this option has already been occurred.
 
Methods inherited from class common.cmdline.AbstractOption
getLongForms, getShortForms, toString, wasPresent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringOption

public StringOption(java.lang.String shortForm,
                    java.lang.String longForm,
                    java.lang.String def,
                    java.lang.String docStr)
Creates a string option and registers it with the Parser class.

Parameters:
shortForm - single-character form of this option, or null for an option with no short form
longForm - long form of this option, or null for an option with no long form.
def - default value to return if the option does not occur
docStr - short (preferably less than 40 characters) string specifying what happens when this option is "<s>"
Method Detail

expectsValue

public boolean expectsValue()
Description copied from interface: Option
Returns true if this option expects a value on the command line.


recordOccurrence

public void recordOccurrence(java.lang.String form,
                             java.lang.String valueStr)
Description copied from class: AbstractOption
This default implementation prints a warning if this option has already been occurred. It also sets the occurred member variable to true. However, it does not parse or record the value.

Specified by:
recordOccurrence in interface Option
Overrides:
recordOccurrence in class AbstractOption
Parameters:
form - specifies the particular long or short form of the option that was used
valueStr - the given value, or null if no value was given. The parser will only pass null for this parameter if expectsValue returns false; otherwise, if the value is missing, the parser will not call this method.

getUsageString

public java.lang.String getUsageString()
Description copied from interface: Option
Returns a string that documents the option. This string should fit on one 80-column line.


getValue

public java.lang.String getValue()
Returns the value specified on the command line for this option, or the default value if the option did not occur.