laser.util.argument
Class Arguments

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

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

The Arguments class supports a collection of Arguments. It provides mappings between Argument names and the Arguments themselves.

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

Field Summary
static java.lang.String ARGUMENT_SEPARATOR
          The argument separator
static java.lang.String ARGUMENTS_HEADER
          The help arguments header
static java.lang.StringBuffer DEFAULT_DESCRIPTION
          The default description
static java.lang.String DEFAULT_NAME
          The default name
static java.lang.String DESCRIPTION_HEADER
          The help description header
static java.lang.String LS
          The platform specific line separator
static java.lang.String NAME_HEADER
          The help name header
static java.lang.String VALUES_SEPARATOR
          The values separator
 
Constructor Summary
Arguments()
          Creates a new Arguments object with the default name and description.
Arguments(java.lang.String name, java.lang.StringBuffer description)
          Creates a new Arguments object with the given name and description.
 
Method Summary
 void check()
          Checks whether or not the user correctly specified the arguments.
 void clear()
          Clears all of the Arguments contained within this Arguments object.
 java.lang.Object clone()
          Clones this Object.
protected  Arguments createArguments(java.lang.String name, java.lang.StringBuffer description)
          Creates a new Arguments object with the given name and description.
 boolean equals(java.lang.Object obj2)
          Returns true if this Object is equal to the given Object and false otherwise.
 Argument getArgument(java.lang.String name)
          Gets the Argument with the specified name if it exists and null otherwise.
 java.util.Iterator getArguments()
          Gets the Arguments within this Arguments object.
 java.lang.StringBuffer getDescription()
          Gets the description of this Arguments object.
 java.lang.String getHelp()
          Returns the help for this Arguments object.
 java.lang.String getName()
          Gets the name of this Arguments object.
 java.util.Iterator getNames()
          Gets the names of the Arguments within this Arguments object.
 void initialize(Arguments values)
          Initializes the arguments with the specified values.
 void load(java.io.File theFile)
          Loads the arguments in from the given File.
 void load(java.io.Reader in)
          Loads the arguments from the given Reader.
 void load(java.lang.String theFile)
          Loads the arguments in from the File with the given name.
 void loadArgument(java.lang.String argumentSpec)
          Parses the given Argument specification and sets the name to the specified value.
 int numberOfArguments()
          Returns the number of Arguments.
 void putArgument(Argument arg)
          Puts the given Argument into this Arguments object.
 void save(java.io.File theFile)
          Saves the arguments to the given File.
 void save(java.lang.String theFile)
          Saves the arguments to the File with the given name.
 void save(java.io.Writer out)
          Saves the arguments to the given Writer.
protected  void saveArgument(Argument argument, java.io.Writer out)
          Saves the given Argument to the specified Writer.
 java.lang.String toString()
          Returns a string representation of this Object.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_HEADER

public static final java.lang.String NAME_HEADER
The help name header

See Also:
Constant Field Values

DESCRIPTION_HEADER

public static final java.lang.String DESCRIPTION_HEADER
The help description header

See Also:
Constant Field Values

ARGUMENTS_HEADER

public static final java.lang.String ARGUMENTS_HEADER
The help arguments header

See Also:
Constant Field Values

ARGUMENT_SEPARATOR

public static final java.lang.String ARGUMENT_SEPARATOR
The argument separator

See Also:
Constant Field Values

VALUES_SEPARATOR

public static final java.lang.String VALUES_SEPARATOR
The values separator

See Also:
Constant Field Values

LS

public static final java.lang.String LS
The platform specific line separator


DEFAULT_NAME

public static final java.lang.String DEFAULT_NAME
The default name

See Also:
Constant Field Values

DEFAULT_DESCRIPTION

public static final java.lang.StringBuffer DEFAULT_DESCRIPTION
The default description

Constructor Detail

Arguments

public Arguments(java.lang.String name,
                 java.lang.StringBuffer description)
Creates a new Arguments object with the given name and description.

Parameters:
name - The tool name
description - The tool description

Arguments

public Arguments()
Creates a new Arguments object with the default name and description.

Method Detail

createArguments

protected Arguments createArguments(java.lang.String name,
                                    java.lang.StringBuffer description)
Creates a new Arguments object with the given name and description. NOTE: This is a factory method.

Returns:
The new Arguments object

getName

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

Returns:
The name

getDescription

public java.lang.StringBuffer getDescription()
Gets the description of this Arguments object.

Returns:
The description

putArgument

public void putArgument(Argument arg)
Puts the given Argument into this Arguments object.

NOTE: If an Argument with the given name already exists, then it is replaced.

Parameters:
arg - The argument to add

getArgument

public Argument getArgument(java.lang.String name)
Gets the Argument with the specified name if it exists and null otherwise.

Parameters:
name - The name of interest
Returns:
The Argument with name or null otherwise

getNames

public java.util.Iterator getNames()
Gets the names of the Arguments within this Arguments object.

Returns:
The names of the Arguments

getArguments

public java.util.Iterator getArguments()
Gets the Arguments within this Arguments object.

Returns:
The Arguments

numberOfArguments

public int numberOfArguments()
Returns the number of Arguments.

Returns:
The number of Arguments

check

public void check()
           throws ArgumentFormatException
Checks whether or not the user correctly specified the arguments.

Throws:
ArgumentFormatException - if the user incorrectly specified any of the arguments

clear

public void clear()
Clears all of the Arguments contained within this Arguments object.


getHelp

public java.lang.String getHelp()
Returns the help for this Arguments object.


initialize

public void initialize(Arguments values)
                throws ArgumentFormatException,
                       ArgumentNotRepeatableException
Initializes the arguments with the specified values.

NOTE: If values is this Arguments, then this is a no-op.

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

loadArgument

public void loadArgument(java.lang.String argumentSpec)
                  throws ArgumentFormatException,
                         ArgumentNotRepeatableException
Parses the given Argument specification and sets the name to the specified value.

Parameters:
argumentSpec - The Argument specification
Throws:
ArgumentFormatException
ArgumentNotRepeatableException

load

public void load(java.io.Reader in)
          throws ArgumentFormatException,
                 ArgumentNotRepeatableException,
                 java.io.IOException
Loads the arguments from the given Reader.

Parameters:
in - The Reader to use as input
Throws:
ArgumentFormatException - if any Argument is incorrectly formatted
ArgumentNotRepeatableException - if any Argument is not repeatable and was set multiple times
java.io.IOException - if an I/O error occurs

load

public void load(java.io.File theFile)
          throws ArgumentFormatException,
                 ArgumentNotRepeatableException,
                 java.io.IOException
Loads the arguments in from the given File.

Parameters:
theFile - The File to use as input
Throws:
ArgumentFormatException - if any Argument is incorrectly formatted
ArgumentNotRepeatableException - if any Argument is not repeatable and was set multiple times
java.io.IOException - if an I/O error occurs

load

public void load(java.lang.String theFile)
          throws ArgumentFormatException,
                 ArgumentNotRepeatableException,
                 java.io.IOException
Loads the arguments in from the File with the given name.

Parameters:
theFile - The name of the File to use as input
Throws:
ArgumentFormatException - if any Argument is incorrectly formatted
ArgumentNotRepeatableException - if any Argument is not repeatable and was set multiple times
java.io.IOException - if an I/O error occurs

saveArgument

protected void saveArgument(Argument argument,
                            java.io.Writer out)
                     throws java.io.IOException
Saves the given Argument to the specified Writer.

Parameters:
argument - The Argument to be saved
out - The Writer to use as output
Throws:
java.io.IOException - if an I/O error occurs

save

public void save(java.io.Writer out)
          throws java.io.IOException
Saves the arguments to the given Writer.

Parameters:
out - The Writer to use as output
Throws:
java.io.IOException - if an I/O error occurs

save

public void save(java.io.File theFile)
          throws java.io.IOException
Saves the arguments to the given File.

Parameters:
theFile - The File of interest
Throws:
java.io.IOException - if an I/O error occurs

save

public void save(java.lang.String theFile)
          throws java.io.IOException
Saves the arguments to the File with the given name.

Parameters:
theFile - The name of the File of interest
Throws:
java.io.IOException - if an I/O error occurs

clone

public 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 Object.

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