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


Constructor Summary
GroupImpl(List options, String name, String description, int minimum, int maximum, boolean required)
          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)
          Adds defaults to a CommandLine.
 Option findOption(String trigger)
          Recursively searches for an option with the supplied trigger.
 List getAnonymous()
          Gets the anonymous Arguments of this Group.
 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
 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()
          Tests whether this option is required.
 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 org.apache.commons.cli2.option.OptionImpl
canProcess, checkPrefixes, equals, getId, getParent, hashCode, setParent, 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, getParent, setParent
 

Constructor Detail

GroupImpl

public GroupImpl(List options,
                 String name,
                 String description,
                 int minimum,
                 int maximum,
                 boolean required)
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
required - a flag whether this group is required
Method Detail

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          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
Parameters:
commandLine - The CommandLine to check
arg - The argument to be tested
Returns:
true if the argument can be processed by this Option

getPrefixes

public 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 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,
                    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 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 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(StringBuffer buffer,
                        Set helpSettings,
                        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(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp,
                        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 List helpLines(int depth,
                      Set helpSettings,
                      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 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 anonymous Arguments of this Group.

Returns:
the Argument options of this Group

findOption

public Option findOption(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()
Tests whether this option is required. For groups we evaluate the required flag common to all options, but also take the minimum constraints into account.

Specified by:
isRequired in interface Group
Specified by:
isRequired in interface Option
Overrides:
isRequired in class OptionImpl
Returns:
a flag whether this option is required
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


Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.