org.apache.commons.cli2.commandline
Class WriteableCommandLineImpl

java.lang.Object
  extended by org.apache.commons.cli2.commandline.CommandLineImpl
      extended by org.apache.commons.cli2.commandline.WriteableCommandLineImpl
All Implemented Interfaces:
CommandLine, WriteableCommandLine

public class WriteableCommandLineImpl
extends CommandLineImpl
implements WriteableCommandLine

A WriteableCommandLine implementation allowing Options to write their processed information to a CommandLine.


Field Summary
private  java.util.Map defaultSwitches
           
private  java.util.Map defaultValues
           
private  java.util.Map nameToOption
           
private  java.util.List normalised
           
private  java.util.List options
           
private  java.util.Set prefixes
           
private  java.util.Properties properties
           
private  java.util.Map switches
           
private  java.util.Map values
           
 
Constructor Summary
WriteableCommandLineImpl(Option rootOption, java.util.List arguments)
          Creates a new WriteableCommandLineImpl rooted on the specified Option, to hold the parsed arguments.
 
Method Summary
 void addOption(Option option)
          Adds an Option to the CommandLine
 void addProperty(java.lang.String property, java.lang.String value)
          Adds a property value to a name in the CommandLine.
 void addSwitch(Option option, boolean value)
          Adds a switch value to an Option in the CommandLine.
 void addValue(Option option, java.lang.Object value)
          Adds a value to an Option in the CommandLine.
 java.util.List getNormalised()
           
 Option getOption(java.lang.String trigger)
          Finds the Option with the specified trigger
 java.util.List getOptions()
          Retrieves a list of all Options found in this CommandLine
 java.util.Set getOptionTriggers()
          Retrieves a list of all Option triggers found in this CommandLine
 java.util.Set getProperties()
          Retrieves the set of all property names associated with this CommandLine
 java.lang.String getProperty(java.lang.String property, java.lang.String defaultValue)
          Retrieves the value associated with the specified property
 java.lang.Boolean getSwitch(Option option, java.lang.Boolean defaultValue)
          Retrieves the Boolean value associated with the specified Switch
 java.util.List getValues(Option option, java.util.List defaultValues)
          Retrieves the Argument values associated with the specified Option
 boolean hasOption(Option option)
          Detects the presence of an option in this CommandLine.
 boolean looksLikeOption(java.lang.String trigger)
          Detects whether the argument looks like an Option trigger
 void setDefaultSwitch(Option option, java.lang.Boolean defaultSwitch)
          Sets the default state for a Switch in the CommandLine.
 void setDefaultValues(Option option, java.util.List defaults)
          Sets the default values for an Option in the CommandLine
 java.lang.String toString()
           
 
Methods inherited from class org.apache.commons.cli2.commandline.CommandLineImpl
getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.cli2.CommandLine
getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption
 

Field Detail

properties

private final java.util.Properties properties

options

private final java.util.List options

nameToOption

private final java.util.Map nameToOption

values

private final java.util.Map values

switches

private final java.util.Map switches

defaultValues

private final java.util.Map defaultValues

defaultSwitches

private final java.util.Map defaultSwitches

normalised

private final java.util.List normalised

prefixes

private final java.util.Set prefixes
Constructor Detail

WriteableCommandLineImpl

public WriteableCommandLineImpl(Option rootOption,
                                java.util.List arguments)
Creates a new WriteableCommandLineImpl rooted on the specified Option, to hold the parsed arguments.

Parameters:
rootOption - the CommandLine's root Option
arguments - the arguments this CommandLine represents
Method Detail

addOption

public void addOption(Option option)
Description copied from interface: WriteableCommandLine
Adds an Option to the CommandLine

Specified by:
addOption in interface WriteableCommandLine
Parameters:
option - the Option to add

addValue

public void addValue(Option option,
                     java.lang.Object value)
Description copied from interface: WriteableCommandLine
Adds a value to an Option in the CommandLine.

Specified by:
addValue in interface WriteableCommandLine
Parameters:
option - the Option to add to
value - the value to add

addSwitch

public void addSwitch(Option option,
                      boolean value)
Description copied from interface: WriteableCommandLine
Adds a switch value to an Option in the CommandLine.

Specified by:
addSwitch in interface WriteableCommandLine
Parameters:
option - the Option to add to
value - the switch value to add

hasOption

public boolean hasOption(Option option)
Description copied from interface: CommandLine
Detects the presence of an option in this CommandLine.

Specified by:
hasOption in interface CommandLine
Parameters:
option - the Option to search for
Returns:
true iff the option is present

getOption

public Option getOption(java.lang.String trigger)
Description copied from interface: CommandLine
Finds the Option with the specified trigger

Specified by:
getOption in interface CommandLine
Parameters:
trigger - the name of the option to retrieve
Returns:
the Option matching the trigger or null if none exists

getValues

public java.util.List getValues(Option option,
                                java.util.List defaultValues)
Description copied from interface: CommandLine
Retrieves the Argument values associated with the specified Option

Specified by:
getValues in interface CommandLine
Parameters:
option - the Option associated with the values
defaultValues - the result to return if no values are found
Returns:
a list of values or defaultValues if none are found

getSwitch

public java.lang.Boolean getSwitch(Option option,
                                   java.lang.Boolean defaultValue)
Description copied from interface: CommandLine
Retrieves the Boolean value associated with the specified Switch

Specified by:
getSwitch in interface CommandLine
Parameters:
option - the Option associated with the value
defaultValue - the Boolean to use if none match
Returns:
the Boolean associated with option or defaultValue if none exists

addProperty

public void addProperty(java.lang.String property,
                        java.lang.String value)
Description copied from interface: WriteableCommandLine
Adds a property value to a name in the CommandLine. Replaces any existing value for the property.

Specified by:
addProperty in interface WriteableCommandLine
Parameters:
property - the name of the property
value - the value of the property

getProperty

public java.lang.String getProperty(java.lang.String property,
                                    java.lang.String defaultValue)
Description copied from interface: CommandLine
Retrieves the value associated with the specified property

Specified by:
getProperty in interface CommandLine
Parameters:
property - the property name to lookup
defaultValue - the value to use if no other is found
Returns:
the value of the property or defaultValue

getProperties

public java.util.Set getProperties()
Description copied from interface: CommandLine
Retrieves the set of all property names associated with this CommandLine

Specified by:
getProperties in interface CommandLine
Returns:
a none null set of property names

looksLikeOption

public boolean looksLikeOption(java.lang.String trigger)
Description copied from interface: WriteableCommandLine
Detects whether the argument looks like an Option trigger

Specified by:
looksLikeOption in interface WriteableCommandLine
Parameters:
trigger - the argument to test
Returns:
true if the argument looks like an Option trigger

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getOptions

public java.util.List getOptions()
Description copied from interface: CommandLine
Retrieves a list of all Options found in this CommandLine

Specified by:
getOptions in interface CommandLine
Returns:
a none null list of Options

getOptionTriggers

public java.util.Set getOptionTriggers()
Description copied from interface: CommandLine
Retrieves a list of all Option triggers found in this CommandLine

Specified by:
getOptionTriggers in interface CommandLine
Returns:
a none null list of Option triggers

setDefaultValues

public void setDefaultValues(Option option,
                             java.util.List defaults)
Description copied from interface: WriteableCommandLine
Sets the default values for an Option in the CommandLine

Specified by:
setDefaultValues in interface WriteableCommandLine
Parameters:
option - the Option to add to
defaults - the defaults for the option

setDefaultSwitch

public void setDefaultSwitch(Option option,
                             java.lang.Boolean defaultSwitch)
Description copied from interface: WriteableCommandLine
Sets the default state for a Switch in the CommandLine.

Specified by:
setDefaultSwitch in interface WriteableCommandLine
Parameters:
option - the Option to add to
defaultSwitch - the defaults state for ths switch

getNormalised

public java.util.List getNormalised()