getopt-0.3

jrowe.getopt
Class DefaultOption

java.lang.Object
  |
  +--jrowe.getopt.DefaultOption

public class DefaultOption
extends Object
implements Option

This is the default implementation of an Option.

Version:
1.3 MAR 10 2000 Moved from package org.jrowe.getopt to jrowe.getopt.
Author:
Joshua T. Rowe

Fields inherited from interface jrowe.getopt.Option
BOOLEAN_ARG, COUNT_ARG, INTEGER_ARG, LIST_ARG, NESTED_ARG, NO_ARG, NUMERIC_ARG, REAL_ARG, SCALAR_ARG, STRING_ARG
 
Constructor Summary
DefaultOption()
          Creates a new DefaultOption with the default attributes.
 
Method Summary
 void clear()
          Reinitializes this Option to it's default state.
 Object clone()
          Creates and returns a copy of this object.
 Option createNewInstance()
          Creates an Option of the same class as this Option.
 Object getArg()
          Returns the argument for this program option.
 int getArgType()
          Returns the argument type for this program option.
 char getChar()
          Returns the short name of this program option.
 Character getCharacter()
          Returns the short name of this program option.
 int getMaxInstances()
          Returns the maximum instances of this option that must appear if any appear at all.
 int getMinInstances()
          Returns the minimum instances of this option that must appear if any appear at all.
 String getName()
          Gets the long name of this object.
static boolean hasArg(int argType)
          Returns whether the given argument type has an argument or not.
 int incrementInstanceCount()
          Increments the instance count of this Option.
 boolean isArgOptional()
          Returns whether the argument for this Option is optional
 void resetInstanceCount()
          Resets the instance count of this Option.
 void runMethod()
          Invokes the Runnable object that is to be run if this program option is found.
 void runMethod(Object arg)
          Deprecated.  
 void setArg(Object newArg)
          Sets the argument for this program option.
 void setArgOptional(boolean argOptional)
          Sets whether the argument for this Option is optional
 void setArgType(int argType)
          Sets the argument type for this program option.
 void setChar(char c)
          Sets the short name of this program option.
 void setCharacter(Character c)
          Sets the short name of this program option.
 void setErrorMethod(Runnable errorMethod)
           
 void setMaxInstances(int maxInstances)
          Sets the maximum instances of this option that may appear.
 void setMethod(OptionMethod method)
          Sets the Runnable object to invoke if the program option is found.
 void setMinInstances(int minInstances)
          Sets the minimum instances of this option that must appear if any appear at all.
 void setName(String name)
          Sets the long name of this object.
 String toString()
           
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultOption

public DefaultOption()
Creates a new DefaultOption with the default attributes.
Method Detail

clear

public void clear()
Reinitializes this Option to it's default state.
Specified by:
clear in interface Option

setName

public void setName(String name)
Sets the long name of this object.
Specified by:
setName in interface Option
Parameters:
name - the long name

getName

public String getName()
Gets the long name of this object.
Specified by:
getName in interface Option
Returns:
the long name.

setArg

public void setArg(Object newArg)
Sets the argument for this program option.
Specified by:
setArg in interface Option
Parameters:
newArg - the argument for this program option

getArg

public Object getArg()
Returns the argument for this program option.
Specified by:
getArg in interface Option
Returns:
the argument for this program option

setArgType

public void setArgType(int argType)
Sets the argument type for this program option.
Specified by:
setArgType in interface Option
Parameters:
argType - The type of argument this program option takes.
Valid types are:
NO_ARG
SCALAR_ARG
STRING_ARG
LIST_ARG
COUNT_ARG
NUMERIC_ARG
REAL_ARG
INTEGER_ARG
BOOLEAN_ARG

getArgType

public int getArgType()
Returns the argument type for this program option.
Specified by:
getArgType in interface Option
Returns:
the argument type for this program option
See Also:
setArgType(int)

hasArg

public static boolean hasArg(int argType)
Returns whether the given argument type has an argument or not.
Parameters:
argType - the given arg type
Returns:
whether the given argument type has an argument or not.

setArgOptional

public void setArgOptional(boolean argOptional)
Sets whether the argument for this Option is optional
Specified by:
setArgOptional in interface Option
Returns:
argOptional whether the argument for this Option is optional

isArgOptional

public boolean isArgOptional()
Returns whether the argument for this Option is optional
Specified by:
isArgOptional in interface Option
Returns:
whether the argument for this Option is optional

setChar

public void setChar(char c)
Sets the short name of this program option.
Specified by:
setChar in interface Option
Parameters:
c - the short name of this program option

getChar

public char getChar()
Returns the short name of this program option.
Specified by:
getChar in interface Option
Returns:
the short name of this program option

setCharacter

public void setCharacter(Character c)
Sets the short name of this program option.
Specified by:
setCharacter in interface Option
Parameters:
c - the short name of this program option

getCharacter

public Character getCharacter()
Returns the short name of this program option.
Specified by:
getCharacter in interface Option
Returns:
the short name of this program option

setMethod

public void setMethod(OptionMethod method)
Sets the Runnable object to invoke if the program option is found.
Specified by:
setMethod in interface Option
Parameters:
method - the object to invoke

runMethod

public void runMethod()
Invokes the Runnable object that is to be run if this program option is found.
Specified by:
runMethod in interface Option

runMethod

public void runMethod(Object arg)
Deprecated.  

Invokes the Runnable object that is to be run if this program option is found.
Specified by:
runMethod in interface Option
Parameters:
arg - the argument

setErrorMethod

public void setErrorMethod(Runnable errorMethod)

resetInstanceCount

public void resetInstanceCount()
Resets the instance count of this Option.

incrementInstanceCount

public int incrementInstanceCount()
Increments the instance count of this Option.
Returns:
the new value of the instance count property

setMinInstances

public void setMinInstances(int minInstances)
Sets the minimum instances of this option that must appear if any appear at all.

In other words, if this is set to N, there must either be 0 instances of this Option or there must be at least 3 instances of this Option.

Parameters:
minInstances - the minimum number of instances.
If this is less than 1, an IllegalArgumentException will be thrown.
If this is greater than the maxInstances, property an IllegalArgumentException will be thrown.

getMinInstances

public int getMinInstances()
Returns the minimum instances of this option that must appear if any appear at all.

In other words, if this is set to N, there must either be 0 instances of this Option or there must be at least 3 instances of this Option.

Returns:
the minimum number of instances.
See Also:
setMinInstances(int)

setMaxInstances

public void setMaxInstances(int maxInstances)
Sets the maximum instances of this option that may appear.

Parameters:
maxInstances - the maximum number of instances.
If this is less than the minInstances property, an IllegalArgumentException will be thrown.

getMaxInstances

public int getMaxInstances()
Returns the maximum instances of this option that must appear if any appear at all.

Returns:
the maximum number of instances.

clone

public Object clone()
Creates and returns a copy of this object.

Specified by:
clone in interface Option
Overrides:
clone in class Object
Throws:
OutOfMemoryError - if there is not enough memory.
See Also:
Cloneable, Object.clone()

toString

public String toString()
Overrides:
toString in class Object

createNewInstance

public Option createNewInstance()
Creates an Option of the same class as this Option.

This is similar to the clone method except none of the data contained in the object is copied.

Specified by:
createNewInstance in interface Option
See Also:
clone()

getopt-0.3