common.cmdline
Class AbstractOption

java.lang.Object
  extended by common.cmdline.AbstractOption
All Implemented Interfaces:
Option
Direct Known Subclasses:
BooleanOption, DoubleOption, IntOption, PropertiesOption, StringListOption, StringOption

public abstract class AbstractOption
extends java.lang.Object
implements Option

Abstract implementation of the Option interface that takes care of some bookkeeping and error checking.


Field Summary
protected static int DOC_OFFSET
          Offset for documentation strings in usage strings.
protected  java.util.List longForms
          List of String objects that are long forms of this option.
protected  boolean occurred
          True if recordOccurrence has already been called on this option.
protected  java.util.List shortForms
          List of Character objects that are short forms of this option.
 
Constructor Summary
AbstractOption(java.lang.String shortForm, java.lang.String longForm)
          Creates an option.
 
Method Summary
 java.util.List getLongForms()
          Returns the long forms of this option.
 java.util.List getShortForms()
          Returns the short (single-character) forms of this option.
 void recordOccurrence(java.lang.String form, java.lang.String valueStr)
          This default implementation prints a warning if this option has already been occurred.
 java.lang.String toString()
           
 boolean wasPresent()
          Returns true if any form of this option occurred on the command line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface common.cmdline.Option
expectsValue, getUsageString
 

Field Detail

DOC_OFFSET

protected static final int DOC_OFFSET
Offset for documentation strings in usage strings. Implementations of getUsageString should pad their return values with spaces so that the documentation string begins at this offset.

See Also:
Constant Field Values

shortForms

protected java.util.List shortForms
List of Character objects that are short forms of this option.


longForms

protected java.util.List longForms
List of String objects that are long forms of this option.


occurred

protected boolean occurred
True if recordOccurrence has already been called on this option.

Constructor Detail

AbstractOption

public AbstractOption(java.lang.String shortForm,
                      java.lang.String longForm)
Creates an option.

Parameters:
shortForm - single-character form of the option, or null if the option has no single-character form
longForm - long form of the option, or null if the option has no long form
Throws:
java.lang.IllegalArgumentException - if shortForm is a string of length other than 1
java.lang.IllegalArgumentException - if longForm is an empty string
java.lang.IllegalArgumentException - if both shortForm and longForm are null
Method Detail

getShortForms

public java.util.List getShortForms()
Description copied from interface: Option
Returns the short (single-character) forms of this option.

Specified by:
getShortForms in interface Option
Returns:
List of Character objects

getLongForms

public java.util.List getLongForms()
Description copied from interface: Option
Returns the long forms of this option.

Specified by:
getLongForms in interface Option
Returns:
List of String objects

recordOccurrence

public void recordOccurrence(java.lang.String form,
                             java.lang.String valueStr)
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
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.

wasPresent

public boolean wasPresent()
Returns true if any form of this option occurred on the command line.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object