org.apache.commons.cli2.option
Class GroupImpl

java.lang.Object
  extended by org.apache.commons.cli2.option.OptionImpl
      extended by org.apache.commons.cli2.option.GroupImpl
All Implemented Interfaces:
Group, Option

public class GroupImpl
extends OptionImpl
implements Group

An implementation of Group


Field Summary
private  java.util.List anonymous
           
private  java.lang.String description
           
private  int maximum
           
private  int minimum
           
private  java.lang.String name
           
private  java.util.SortedMap optionMap
           
private  java.util.List options
           
private  java.util.Set prefixes
           
 
Constructor Summary
GroupImpl(java.util.List options, java.lang.String name, java.lang.String description, int minimum, int maximum)
          Creates a new GroupImpl using the specified parameters.
 
Method Summary
 void appendUsage(java.lang.StringBuffer buffer, java.util.Set helpSettings, java.util.Comparator comp)
          Appends usage information to the specified StringBuffer
 void appendUsage(java.lang.StringBuffer buffer, java.util.Set helpSettings, java.util.Comparator comp, java.lang.String separator)
          Appends usage information to the specified StringBuffer
 boolean canProcess(WriteableCommandLine commandLine, java.lang.String arg)
          Indicates whether this Option will be able to process the particular argument.
 void defaults(WriteableCommandLine commandLine)
          Adds defaults to a CommandLine.
 Option findOption(java.lang.String trigger)
          Recursively searches for an option with the supplied trigger.
 java.util.List getAnonymous()
          Gets the anonymous Arguments of this Group.
 java.lang.String getDescription()
          Returns a description of the option.
 int getMaximum()
          Retrieves the maximum number of members acceptable for a valid Group
 int getMinimum()
          Retrieves the minimum number of members required for a valid Group
 java.util.List getOptions()
          Gets the member Options of thie Group.
 java.lang.String getPreferredName()
          The preferred name of an option is used for generating help and usage information.
 java.util.Set getPrefixes()
          Identifies the argument prefixes that should be considered options.
 java.util.Set getTriggers()
          Identifies the argument prefixes that should trigger this option.
 java.util.List helpLines(int depth, java.util.Set helpSettings, java.util.Comparator comp)
          Builds up a list of HelpLineImpl instances to be presented by HelpFormatter.
 boolean isRequired()
          Indicates whether this option is required to be present.
 void process(WriteableCommandLine commandLine, java.util.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 org.apache.commons.cli2.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 org.apache.commons.cli2.Option
canProcess, getId
 

Field Detail

name

private final java.lang.String name

description

private final java.lang.String description

options

private final java.util.List options

minimum

private final int minimum

maximum

private final int maximum

anonymous

private final java.util.List anonymous

optionMap

private final java.util.SortedMap optionMap

prefixes

private final java.util.Set prefixes
Constructor Detail

GroupImpl

public GroupImpl(java.util.List options,
                 java.lang.String name,
                 java.lang.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,
                          java.lang.String arg)
Description copied from interface: Option
Indicates whether this Option will be able to process the particular argument.

Specified by:
canProcess in interface Option
arg - The argument to be tested
Returns:
true if the argument can be processed by this Option

getPrefixes

public java.util.Set getPrefixes()
Description copied from interface: Option
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 java.util.Set getTriggers()
Description copied from interface: Option
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,
                    java.util.ListIterator arguments)
             throws OptionException
Description copied from interface: Option
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
Description copied from interface: Option
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 java.lang.String getPreferredName()
Description copied from interface: Option
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 java.lang.String getDescription()
Description copied from interface: Option
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(java.lang.StringBuffer buffer,
                        java.util.Set helpSettings,
                        java.util.Comparator comp)
Description copied from interface: Option
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(java.lang.StringBuffer buffer,
                        java.util.Set helpSettings,
                        java.util.Comparator comp,
                        java.lang.String separator)
Description copied from interface: Group
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 java.util.List helpLines(int depth,
                                java.util.Set helpSettings,
                                java.util.Comparator comp)
Description copied from interface: Option
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 java.util.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 java.util.List getAnonymous()
Gets the anonymous Arguments of this Group.

Returns:
the Argument options of this Group

findOption

public Option findOption(java.lang.String trigger)
Description copied from interface: Option
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()
Description copied from interface: Group
Retrieves the minimum number of members required for a valid Group

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

getMaximum

public int getMaximum()
Description copied from interface: Group
Retrieves the maximum number of members acceptable for a valid Group

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

isRequired

public boolean isRequired()
Description copied from interface: Option
Indicates whether this option is required to be present.

Specified by:
isRequired in interface Group
Specified by:
isRequired in interface Option
Overrides:
isRequired in class OptionImpl
Returns:
true iff the CommandLine will be invalid without this Option
See Also:
Group.getMinimum(), Group.getMaximum()

defaults

public void defaults(WriteableCommandLine commandLine)
Description copied from interface: Option
Adds defaults to a CommandLine. Any defaults for this option are applied as well as the defaults for any contained options

Specified by:
defaults in interface Option
Overrides:
defaults in class OptionImpl
Parameters:
commandLine - The CommandLine object to store defaults in