net.dpml.cli.option
Class GroupImpl

java.lang.Object
  extended bynet.dpml.cli.option.OptionImpl
      extended bynet.dpml.cli.option.GroupImpl
All Implemented Interfaces:
Group, Option

public class GroupImpl
extends OptionImpl
implements Group

An implementation of Group

Version:
1.0.0
Author:
Digital Product Meta Library

Constructor Summary
GroupImpl(List options, String name, String description, int minimum, int maximum)
          Creates a new GroupImpl using the specified parameters.
 
Method Summary
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
          Appends usage information to the specified StringBuffer
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp, String separator)
          Appends usage information to the specified StringBuffer
 boolean canProcess(WriteableCommandLine commandLine, String arg)
          Indicates whether this Option will be able to process the particular argument.
 void defaults(WriteableCommandLine commandLine)
          Process defaults.
 Option findOption(String trigger)
          Recursively searches for an option with the supplied trigger.
 List getAnonymous()
          Gets the m_anonymous Arguments of this Group.
 String getDescription()
          Returns a description of the option.
 int getMaximum()
          Retrieves the maximum number of values acceptable for a valid Argument
 int getMinimum()
          Retrieves the minimum number of values required for a valid Argument
 List getOptions()
          Gets the member Options of thie Group.
 String getPreferredName()
          The preferred name of an option is used for generating help and usage information.
 Set getPrefixes()
          Identifies the argument prefixes that should be considered options.
 Set getTriggers()
          Identifies the argument prefixes that should trigger this option.
 List helpLines(int depth, Set helpSettings, Comparator comp)
          Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.
 boolean isRequired()
          Indicates whether argument values must be present for the CommandLine to be valid.
 void process(WriteableCommandLine commandLine, ListIterator arguments)
          Processes String arguments into a CommandLine.
 void validate(WriteableCommandLine commandLine)
          Checks that the supplied CommandLine is valid with respect to this option.
 
Methods inherited from class net.dpml.cli.option.OptionImpl
canProcess, checkPrefixes, equals, getId, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.dpml.cli.Option
canProcess, getId
 

Constructor Detail

GroupImpl

public GroupImpl(List options,
                 String name,
                 String description,
                 int minimum,
                 int maximum)
Creates a new GroupImpl using the specified parameters.

Parameters:
options - the Options and Arguments that make up the Group
name - the name of this Group, or null
description - a description of this Group
minimum - the minimum number of Options for a valid CommandLine
maximum - the maximum number of Options for a valid CommandLine
Method Detail

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          String arg)
Indicates whether this Option will be able to process the particular argument.

Specified by:
canProcess in interface Option
Parameters:
commandLine - the CommandLine object to store defaults in
arg - the argument to be tested
Returns:
true if the argument can be processed by this Option

getPrefixes

public Set getPrefixes()
Identifies the argument prefixes that should be considered options. This is used to identify whether a given string looks like an option or an argument value. Typically an option would return the set [--,-] while switches might offer [-,+]. The returned Set must not be null.

Specified by:
getPrefixes in interface Option
Returns:
The set of prefixes for this Option

getTriggers

public Set getTriggers()
Identifies the argument prefixes that should trigger this option. This is used to decide which of many Options should be tried when processing a given argument string. The returned Set must not be null.

Specified by:
getTriggers in interface Option
Returns:
The set of triggers for this Option

process

public void process(WriteableCommandLine commandLine,
                    ListIterator arguments)
             throws OptionException
Processes String arguments into a CommandLine. The iterator will initially point at the first argument to be processed and at the end of the method should point to the first argument not processed. This method MUST process at least one argument from the ListIterator.

Specified by:
process in interface Option
Parameters:
commandLine - the CommandLine object to store results in
arguments - the arguments to process
Throws:
OptionException - if any problems occur

validate

public void validate(WriteableCommandLine commandLine)
              throws OptionException
Checks that the supplied CommandLine is valid with respect to this option.

Specified by:
validate in interface Option
Parameters:
commandLine - the CommandLine to check.
Throws:
OptionException - if the CommandLine is not valid.

getPreferredName

public String getPreferredName()
The preferred name of an option is used for generating help and usage information.

Specified by:
getPreferredName in interface Option
Returns:
The preferred name of the option

getDescription

public String getDescription()
Returns a description of the option. This string is used to build help messages as in the HelpFormatter.

Specified by:
getDescription in interface Option
Returns:
a description of the option.
See Also:
HelpFormatter

appendUsage

public void appendUsage(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp)
Appends usage information to the specified StringBuffer

Specified by:
appendUsage in interface Option
Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options

appendUsage

public void appendUsage(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp,
                        String separator)
Appends usage information to the specified StringBuffer

Specified by:
appendUsage in interface Group
Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options
separator - the String used to separate member Options

helpLines

public List helpLines(int depth,
                      Set helpSettings,
                      Comparator comp)
Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.

Specified by:
helpLines in interface Option
Parameters:
depth - the initial indent depth
helpSettings - the HelpSettings that should be applied
comp - a comparator used to sort options when applicable.
Returns:
a List of HelpLineImpl objects
See Also:
HelpLine, HelpFormatter

getOptions

public List getOptions()
Gets the member Options of thie Group. Note this does not include any Arguments

Returns:
only the non Argument Options of the Group

getAnonymous

public List getAnonymous()
Gets the m_anonymous Arguments of this Group.

Returns:
the Argument options of this Group

findOption

public Option findOption(String trigger)
Recursively searches for an option with the supplied trigger.

Specified by:
findOption in interface Option
Overrides:
findOption in class OptionImpl
Parameters:
trigger - the trigger to search for.
Returns:
the matching option or null.

getMinimum

public int getMinimum()
Retrieves the minimum number of values required for a valid Argument

Specified by:
getMinimum in interface Group
Returns:
the minimum number of values

getMaximum

public int getMaximum()
Retrieves the maximum number of values acceptable for a valid Argument

Specified by:
getMaximum in interface Group
Returns:
the maximum number of values

isRequired

public boolean isRequired()
Indicates whether argument values must be present for the CommandLine to be valid.

Specified by:
isRequired in interface Group
Overrides:
isRequired in class OptionImpl
Returns:
true iff the CommandLine will be invalid without at least one value
See Also:
getMinimum(), getMaximum()

defaults

public void defaults(WriteableCommandLine commandLine)
Process defaults.

Specified by:
defaults in interface Option
Overrides:
defaults in class OptionImpl
Parameters:
commandLine - the commandline