laser.util.argument
Class Argument

java.lang.Object
  extended by laser.util.argument.Argument
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Option, Parameter

public abstract class Argument
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

The Argument class defines a user-defined argument. An argument maps a string name to 0 or more values.

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

Field Summary
static int FIRST
          This is the index of the first value
static java.lang.String HELP_DEFAULT
          The default setting for helpMessage_
static java.lang.String HELP_PREFIX
          The help prefix
static boolean REPEATABLE_DEFAULT
          The default setting for isRepeatable_
static java.lang.String TYPE_PREFIX
          The help type prefix
static java.lang.String TYPE_SUFFIX
          The help type suffix
 
Constructor Summary
protected Argument(java.lang.String name)
          Creates a new Argument with the given name.
protected Argument(java.lang.String name, boolean isRepeatable, java.lang.String helpMessage)
          Creates a new Argument with the given name.
 
Method Summary
abstract  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.
 void clear()
          Clears this Argument.
abstract  java.lang.Object clone()
          Clones this Object.
 boolean equals(java.lang.Object obj2)
          Returns true if this Object is equal to the given Object and false otherwise.
protected abstract  java.lang.Object fromStringValue(java.lang.String value)
          Converts from a String into an Object of the appropriate type.
 java.lang.String getHelp()
          Gets the help for this Argument.
 java.lang.String getHelpMessage()
          Gets the help message to report to the user upon request.
 java.lang.String getName()
          Gets the name of this Argument.
abstract  char getRepeatableChar()
          Gets the repeatable character.
abstract  java.lang.Class getType()
          Gets the type of this Argument.
 java.lang.Object getValue()
          Gets the first value of this Argument.
 java.lang.Object getValue(int index)
          Gets the value of this Argument at the specified index.
protected  java.util.List getValues()
          Gets the values of this Argument.
 void initialize(Argument value)
          Initializes the argument with the specified value.
 boolean isRepeatable()
          Returns whether or not this Argument is repeatable.
 int numberOfActualValues()
          Gets the number of actual values for this Argument.
 int numberOfValues()
          Gets the number of values for this Argument.
 void parseValue(java.lang.String values)
          Parses the given string to get the values for this Argument.
protected  java.lang.String save()
          Saves this Argument.
protected  void setValue(java.lang.Object value)
          Sets the value of this Argument to the specified value.
 java.lang.String toString()
          Returns a string representation of this Argument.
 java.lang.String toStringValue(boolean actualValues)
          Gets the String representation of the values of this Argument.
protected  java.lang.String toStringValue(java.lang.Object value)
          Converts from the given Object into a String.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HELP_PREFIX

public static final java.lang.String HELP_PREFIX
The help prefix

See Also:
Constant Field Values

TYPE_PREFIX

public static final java.lang.String TYPE_PREFIX
The help type prefix

See Also:
Constant Field Values

TYPE_SUFFIX

public static final java.lang.String TYPE_SUFFIX
The help type suffix

See Also:
Constant Field Values

FIRST

public static final int FIRST
This is the index of the first value

See Also:
Constant Field Values

REPEATABLE_DEFAULT

public static final boolean REPEATABLE_DEFAULT
The default setting for isRepeatable_

See Also:
Constant Field Values

HELP_DEFAULT

public static final java.lang.String HELP_DEFAULT
The default setting for helpMessage_

See Also:
Constant Field Values
Constructor Detail

Argument

protected Argument(java.lang.String name,
                   boolean isRepeatable,
                   java.lang.String helpMessage)
Creates a new Argument with the given name. It will be multi-valued if isRepeatable is true and single-valued otherwise. The help message will be made available to the user upon request.

Parameters:
name - The name for the option
isRepeatable - If true then this option is multi-valued otherwise it is single-valued
helpMessage - The help message to report to the user upon request

Argument

protected Argument(java.lang.String name)
Creates a new Argument with the given name. It will have the default setting for isRepeatable and helpMessage.

Parameters:
name - The name for the option
See Also:
Argument.REPEATABLE_DEFAULT, Argument.HELP_DEFAULT
Method Detail

getName

public java.lang.String getName()
Gets the name of this Argument.

Returns:
The name of this Argument

parseValue

public final void parseValue(java.lang.String values)
                      throws ArgumentFormatException,
                             ArgumentNotRepeatableException
Parses the given string to get the values for this Argument.

Parameters:
values - The string to be parsed
Throws:
ArgumentFormatException
ArgumentNotRepeatableException
See Also:
laser.util.argument.Argument.toStringValue(boolean)

fromStringValue

protected abstract java.lang.Object fromStringValue(java.lang.String value)
                                             throws ArgumentFormatException
Converts from a String into an Object of the appropriate type.

Parameters:
value - The String value
Returns:
The Object value
Throws:
ArgumentFormatException - if the value is malformed
See Also:
laser.util.argument.Argument.toStringValue(Object)

toStringValue

public final java.lang.String toStringValue(boolean actualValues)
Gets the String representation of the values of this Argument.

Parameters:
actualValues - The actual values if true and the values if false
Returns:
The String representation of the values
See Also:
laser.util.argument.Argument.numberOfActualValues, laser.util.argument.Argument.numberOfValues, laser.util.argument.Argument.parseValue(String)

toStringValue

protected java.lang.String toStringValue(java.lang.Object value)
Converts from the given Object into a String.

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.

Parameters:
value - The new value
Throws:
ArgumentFormatException - if the argument is not well-formed

setValue

protected void setValue(java.lang.Object value)
                 throws ArgumentFormatException,
                        ArgumentNotRepeatableException
Sets the value of this Argument to the specified value.

Parameters:
value - The value for this Argument
Throws:
ArgumentFormatException
ArgumentNotRepeatableException

numberOfActualValues

public int numberOfActualValues()
Gets the number of actual values for this Argument.

NOTE: This is simply the number of values added so far.

Returns:
The number of actual values

numberOfValues

public int numberOfValues()
Gets the number of values for this Argument.

Returns:
The number of values

getValue

public java.lang.Object getValue()
Gets the first value of this Argument.

Returns:
The first value

getValue

public java.lang.Object getValue(int index)
Gets the value of this Argument at the specified index.

Parameters:
index - The index of the value
Returns:
The value at index

isRepeatable

public boolean isRepeatable()
Returns whether or not this Argument is repeatable. If true then this Argument is multi-valued otherwise it is single-valued.


getRepeatableChar

public abstract char getRepeatableChar()
Gets the repeatable character.

Returns:
The repeatable character

getHelpMessage

public java.lang.String getHelpMessage()
Gets the help message to report to the user upon request.

Returns:
The help message

getType

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

Returns:
The type description

check

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

Throws:
ArgumentFormatException

clear

public void clear()
Clears this Argument.


getHelp

public java.lang.String getHelp()
Gets the help for this Argument.

Returns:
The help

getValues

protected java.util.List getValues()
Gets the values of this Argument.

Returns:
The values

initialize

public void initialize(Argument value)
                throws ArgumentFormatException,
                       ArgumentNotRepeatableException
Initializes the argument with the specified value.

NOTE: If value is this Argument, then this is a no-op.

Parameters:
value - The specified value
Throws:
ArgumentFormatException - if the user incorrectly specified any of the arguments
ArgumentNotRepeatableException - if the user specified a single-valued argument more than once

save

protected java.lang.String save()
Saves this Argument.


clone

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

Overrides:
clone in class java.lang.Object
Returns:
The clone

equals

public boolean equals(java.lang.Object obj2)
Returns true if this Object is equal to the given Object and false otherwise.

Overrides:
equals in class java.lang.Object
Parameters:
obj2 - The Object to be compared
Returns:
True if this Object and the given Object are equal and false otherwise

toString

public java.lang.String toString()
Returns a string representation of this Argument.

Overrides:
toString in class java.lang.Object
Returns:
A string representation