org.apache.commons.cli2.commandline
Class DefaultingCommandLine

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

public class DefaultingCommandLine
extends CommandLineImpl

Manages a queue of default CommandLines. This CommandLine implementation is backed by a queue of CommandLine instances which are queried in turn until a suitable result is found. CommandLine instances can either be added to the back of the queue or can be pushed in at a specific position.

See Also:
appendCommandLine(CommandLine), insertCommandLine(int, CommandLine)

Constructor Summary
DefaultingCommandLine()
           
 
Method Summary
 void appendCommandLine(CommandLine commandLine)
          Adds a CommandLine instance to the back of the queue.
 Iterator commandLines()
          Builds an iterator over the build in CommandLines.
 Option getOption(String trigger)
          Finds the Option with the specified trigger
 List getOptions()
          Retrieves a list of all Options found in this CommandLine
 Set getOptionTriggers()
          Retrieves a list of all Option triggers found in this CommandLine
 Set getProperties()
          Retrieves the set of all property names associated with the default property option
 Set getProperties(Option option)
          Retrieves the set of all property names associated with this option
 String getProperty(Option option, String property, String defaultValue)
          Retrieves the value associated with the specified property
 String getProperty(String property)
          Retrieves the value associated with the specified property for the default property set
 Boolean getSwitch(Option option, Boolean defaultValue)
          Retrieves the Boolean value associated with the specified Switch
 List getValues(Option option, List defaultValues)
          Retrieves the Argument values associated with the specified Option
 boolean hasOption(Option option)
          Detects the presence of an option in this CommandLine.
 void insertCommandLine(int index, CommandLine commandLine)
          Adds a CommandLine instance to a specified position in the queue.
 
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, toString, wait, wait, wait
 

Constructor Detail

DefaultingCommandLine

public DefaultingCommandLine()
Method Detail

appendCommandLine

public void appendCommandLine(CommandLine commandLine)
Adds a CommandLine instance to the back of the queue. The supplied CommandLine will be used as defaults when all other CommandLines produce no result

Parameters:
commandLine - the default values to use if all CommandLines

insertCommandLine

public void insertCommandLine(int index,
                              CommandLine commandLine)
Adds a CommandLine instance to a specified position in the queue.

Parameters:
index - ths position at which to insert
commandLine - the CommandLine to insert

commandLines

public Iterator commandLines()
Builds an iterator over the build in CommandLines.

Returns:
an unmodifiable iterator

getOption

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

Parameters:
trigger - the name of the option to retrieve
Returns:
the Option matching the trigger or null if none exists

getOptions

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

Returns:
a none null list of Options

getOptionTriggers

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

Returns:
a none null list of Option triggers

hasOption

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

Parameters:
option - the Option to search for
Returns:
true iff the option is present

getValues

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

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 Boolean getSwitch(Option option,
                         Boolean defaultValue)
Description copied from interface: CommandLine
Retrieves the Boolean value associated with the specified Switch

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

getProperty

public String getProperty(String property)
Description copied from interface: CommandLine
Retrieves the value associated with the specified property for the default property set

Parameters:
property - the property name to lookup
Returns:
the value of the property or null

getProperty

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

Parameters:
option - the option i.e., -D
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 Set getProperties(Option option)
Description copied from interface: CommandLine
Retrieves the set of all property names associated with this option

Parameters:
option - the option i.e., -D
Returns:
a none null set of property names

getProperties

public Set getProperties()
Description copied from interface: CommandLine
Retrieves the set of all property names associated with the default property option

Returns:
a none null set of property names


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