laser.util.argument
Class ClassOption

java.lang.Object
  extended by laser.util.argument.Argument
      extended by laser.util.argument.Option
          extended by laser.util.argument.ClassOption
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ClassOption
extends Option

The ClassOption class defines a user-defined option of type Class.

Author:
Jamieson M. Cobleigh (laser-software@cs.umass.edu)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class laser.util.argument.Option
DEFAULT_PREFIX, DEFAULT_SUFFIX, NOT_REPEATABLE_CHAR, REPEATABLE_CHAR
 
Fields inherited from class laser.util.argument.Argument
FIRST, HELP_DEFAULT, HELP_PREFIX, REPEATABLE_DEFAULT, TYPE_PREFIX, TYPE_SUFFIX
 
Constructor Summary
ClassOption(java.lang.String name, java.lang.Class defaultValue)
          Creates a new ClassOption with a given name and default value.
ClassOption(java.lang.String name, java.lang.Class supertype, java.lang.Class defaultValue)
          Creates a new ClassOption with a given name, supertype, and default value.
ClassOption(java.lang.String name, java.lang.String helpMessage, java.lang.Class supertype, java.lang.Class defaultValue)
          Creates a new ClassOption with a given name, help message, supertype, and default value.
 
Method Summary
 void check()
          Checks whether or not the user correctly specified a value for this argument.
protected  void checkValue(java.lang.Object value)
          Checks to make sure the the given value is well-formed.
 java.lang.Object clone()
          Clones this Object.
protected  java.lang.Object fromStringValue(java.lang.String value)
          Parses a String value into an Object appropriate for the type
 java.lang.Object getClassInstance()
          Creates an instance of the class named in this option
 java.lang.Class getClassValue()
          Gets the value of this ClassOption
 java.lang.Class getClassValue(int i)
          Gets the i-th value of this ClassOption
protected  java.lang.String getDefaultString()
          Gets the default string which describes the default value of this Option.
 java.lang.Class getType()
          Gets the type of this Option.
 void setValue(java.lang.Class value)
          Sets the value of this ClassOption to the specified value.
protected  java.lang.String toStringValue(java.lang.Object value)
          Returns the String value of the given Object value.
 
Methods inherited from class laser.util.argument.Option
getDefault, getHelp, getRepeatableChar, getValue, numberOfValues
 
Methods inherited from class laser.util.argument.Argument
clear, equals, getHelpMessage, getName, getValue, getValues, initialize, isRepeatable, numberOfActualValues, parseValue, save, setValue, toString, toStringValue
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassOption

public ClassOption(java.lang.String name,
                   java.lang.String helpMessage,
                   java.lang.Class supertype,
                   java.lang.Class defaultValue)
Creates a new ClassOption with a given name, help message, supertype, and default value.

Parameters:
name - the name of the option
helpMessage - the help message to be displayed
supertype - the name of the class that must be a supertype of the class stored in the option
defaultValue - the default value for the option

ClassOption

public ClassOption(java.lang.String name,
                   java.lang.Class supertype,
                   java.lang.Class defaultValue)
Creates a new ClassOption with a given name, supertype, and default value.

Parameters:
name - the name of the option
supertype - the name of the class that must be a supertype of the class stored in the option
defaultValue - the default value for the option
See Also:
laser.util.argument.Argument.HELP_DEFAULT

ClassOption

public ClassOption(java.lang.String name,
                   java.lang.Class defaultValue)
Creates a new ClassOption with a given name and default value.

Parameters:
name - the name of the option
defaultValue - the default value for the option
See Also:
laser.util.argument.Argument.HELP_DEFAULT
Method Detail

getType

public java.lang.Class getType()
Gets the type of this Option.

Specified by:
getType in class Argument
Returns:
The type description

getDefaultString

protected java.lang.String getDefaultString()
Gets the default string which describes the default value of this Option.

Specified by:
getDefaultString in class Option
Returns:
The default string description

fromStringValue

protected java.lang.Object fromStringValue(java.lang.String value)
                                    throws ArgumentFormatException
Parses a String value into an Object appropriate for the type

Specified by:
fromStringValue in class Argument
Parameters:
value - the value
Returns:
the parsed Object
Throws:
ArgumentFormatException - if the value is malformed
See Also:
laser.util.argument.Argument.toStringValue(Object)

toStringValue

protected java.lang.String toStringValue(java.lang.Object value)
Returns the String value of the given Object value.

Overrides:
toStringValue in class Argument
Parameters:
value - The Object value
Returns:
The String value
See Also:
laser.util.argument.Argument.fromStringValue(String)

checkValue

protected void checkValue(java.lang.Object value)
                   throws ArgumentFormatException
Checks to make sure the the given value is well-formed.

Overrides:
checkValue in class Argument
Parameters:
value - The new value
Throws:
ArgumentFormatException - if the argument is not well-formed

setValue

public void setValue(java.lang.Class value)
              throws ArgumentFormatException,
                     ArgumentNotRepeatableException
Sets the value of this ClassOption to the specified value.

Parameters:
value - The value for this ClassOption
Throws:
ArgumentFormatException - if the value is incorrectly formatted
ArgumentNotRepeatableException - if the user attempted to set the value of a single-valued argument multiple times

getClassValue

public java.lang.Class getClassValue()
Gets the value of this ClassOption

Returns:
the value of this ClassOption

getClassValue

public java.lang.Class getClassValue(int i)
Gets the i-th value of this ClassOption

Parameters:
i - the value to get
Returns:
the i-th value of this ClassOption

getClassInstance

public java.lang.Object getClassInstance()
                                  throws ArgumentException
Creates an instance of the class named in this option

Returns:
an instance of the class named in this option
Throws:
ArgumentException - if an error occurs

check

public void check()
           throws ArgumentFormatException
Checks whether or not the user correctly specified a value for this argument.

Specified by:
check in class Argument
Throws:
ArgumentFormatException

clone

public java.lang.Object clone()
Clones this Object.

Specified by:
clone in class Argument
Returns:
The clone