com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class CmdLnOption

java.lang.Object
  extended by com.Ostermiller.util.CmdLnOption

public final class CmdLnOption
extends Object

A command line option used by the CommandLineOptions parser. More information about this class and code samples for suggested use are available from ostermiller.org.

Since:
ostermillerutils 1.07.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Constructor Summary
CmdLnOption(char[] shortNames)
           
CmdLnOption(Character shortName)
           
CmdLnOption(String longName)
           
CmdLnOption(String[] longNames)
           
CmdLnOption(String[] longNames, char[] shortNames)
           
CmdLnOption(String longName, Character shortName)
           
 
Method Summary
 CmdLnOption addLongName(String name)
           
 CmdLnOption addLongNames(Collection<String> longNames)
           
 CmdLnOption addLongNames(String[] longNames)
           
 CmdLnOption addShortName(Character name)
           
 CmdLnOption addShortNames(char[] shortNames)
           
 CmdLnOption addShortNames(Character[] shortNames)
           
 CmdLnOption addShortNames(Collection<Character> shortNames)
           
 String getDescription()
           
 Object getUserObject()
          An object that may be set by the user.
 CmdLnOption setArgumentBounds(int minArguments, int maxArguments)
          Sets the bounds for command line arguments.
 CmdLnOption setDescription(String description)
           
 CmdLnOption setListener(CmdLnListener callback)
          Set the call back object
 CmdLnOption setNoArguments()
          Sets the argument bounds to require no arguments (zero arguments minimum, zero arguments maximum).
 CmdLnOption setOptionalArgument()
          Sets the argument bounds for a single optional argument (zero arguments minimum, one argument maximum).
 CmdLnOption setRequiredArgument()
          Sets the argument bounds for a single required argument (one argument minimum, one argument maximum).
 CmdLnOption setUnlimitedArguments()
          Sets the argument bounds for unlimited (but optional) arguments (zero arguments minimum, Integer.MAX_VALUE arguments maximum).
 CmdLnOption setUserObject(Object userObject)
          An object that may be set by the user.
 String toString()
          Get a short string description this option.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CmdLnOption

public CmdLnOption(String[] longNames)
Parameters:
longNames - list long names for this option
Throws:
IllegalArgumentException - if the the list does not contain at least one long name
Since:
ostermillerutils 1.07.00

CmdLnOption

public CmdLnOption(char[] shortNames)
Parameters:
shortNames - list short names for this option
Throws:
IllegalArgumentException - if the the list does not contain at least one short name
Since:
ostermillerutils 1.07.00

CmdLnOption

public CmdLnOption(String longName)
Parameters:
longName - the long name for this option
Throws:
IllegalArgumentException - if the name is null
Since:
ostermillerutils 1.07.00

CmdLnOption

public CmdLnOption(Character shortName)
Parameters:
shortName - the short name for this option
Since:
ostermillerutils 1.07.00

CmdLnOption

public CmdLnOption(String[] longNames,
                   char[] shortNames)
Parameters:
longNames - list long names for this option
shortNames - list short names for this option
Throws:
IllegalArgumentException - if the the lists do not contain at least one name
Since:
ostermillerutils 1.07.00

CmdLnOption

public CmdLnOption(String longName,
                   Character shortName)
Parameters:
longName - the long name for this option
shortName - the short name for this option
Since:
ostermillerutils 1.07.00
Method Detail

setNoArguments

public CmdLnOption setNoArguments()
Sets the argument bounds to require no arguments (zero arguments minimum, zero arguments maximum). This is the default state for a new command line option.

Returns:
this command line option for method chaining
Throws:
IllegalStateException - if this argument has already been used in parsing CommandLineOptions
Since:
ostermillerutils 1.07.00

setOptionalArgument

public CmdLnOption setOptionalArgument()
Sets the argument bounds for a single optional argument (zero arguments minimum, one argument maximum).

Returns:
this command line option for method chaining
Throws:
IllegalStateException - if this argument has already been used in parsing CommandLineOptions
Since:
ostermillerutils 1.07.00

setRequiredArgument

public CmdLnOption setRequiredArgument()
Sets the argument bounds for a single required argument (one argument minimum, one argument maximum).

Returns:
this command line option for method chaining
Throws:
IllegalStateException - if this argument has already been used in parsing CommandLineOptions
Since:
ostermillerutils 1.07.00

setUnlimitedArguments

public CmdLnOption setUnlimitedArguments()
Sets the argument bounds for unlimited (but optional) arguments (zero arguments minimum, Integer.MAX_VALUE arguments maximum).

Returns:
this command line option for method chaining
Throws:
IllegalStateException - if this argument has already been used in parsing CommandLineOptions

setArgumentBounds

public CmdLnOption setArgumentBounds(int minArguments,
                                     int maxArguments)
Sets the bounds for command line arguments.

Parameters:
minArguments - the minimum number of arguments this command line option should expect
maxArguments - the maximum number of arguments this command line option will accept
Returns:
this command line option for method chaining
Throws:
IllegalArgumentException - if minimum arguments is negative
IllegalArgumentException - if maximum arguments is less than minimum arguments
IllegalStateException - if this argument has already been used in parsing CommandLineOptions
Since:
ostermillerutils 1.07.00

addLongNames

public CmdLnOption addLongNames(Collection<String> longNames)
Parameters:
longNames - long names to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addLongNames

public CmdLnOption addLongNames(String[] longNames)
Parameters:
longNames - long names to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addLongName

public CmdLnOption addLongName(String name)
Parameters:
name - long name to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addShortNames

public CmdLnOption addShortNames(Collection<Character> shortNames)
Parameters:
shortNames - short names to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addShortNames

public CmdLnOption addShortNames(char[] shortNames)
Parameters:
shortNames - short names to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addShortNames

public CmdLnOption addShortNames(Character[] shortNames)
Parameters:
shortNames - short names to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

addShortName

public CmdLnOption addShortName(Character name)
Parameters:
name - short name to be added
Returns:
this for method chaining
Throws:
IllegalArgumentException - if the name is null or blank
Since:
ostermillerutils 1.07.00

toString

public String toString()
Get a short string description this option. It will be either the long name (if it has one) or the short name if it does not have a long name

Overrides:
toString in class Object
Returns:
string representation
Since:
ostermillerutils 1.07.00

setListener

public CmdLnOption setListener(CmdLnListener callback)
Set the call back object

Parameters:
callback - the call back object
Returns:
this for method chaining
Since:
ostermillerutils 1.07.00

getUserObject

public Object getUserObject()
An object that may be set by the user. Suggested use: set the user object to an enum value that can be used in a switch statement.

Returns:
the userObject
Since:
ostermillerutils 1.07.00

setUserObject

public CmdLnOption setUserObject(Object userObject)
An object that may be set by the user. Suggested use: set the user object to an enum value that can be used in a switch statement.

Parameters:
userObject - the userObject to set
Returns:
this for method chaining
Since:
ostermillerutils 1.07.00

getDescription

public String getDescription()
Returns:
the description used in the help message or null if no description has been set.
Since:
ostermillerutils 1.07.00

setDescription

public CmdLnOption setDescription(String description)
Parameters:
description - the description used in the help message
Returns:
this for method chaining
Since:
ostermillerutils 1.07.00

com.Ostermiller.util Java Utilities


Copyright © 2001-2012 by Stephen Ostermiller