net.dpml.cli.commandline
Class WriteableCommandLineImpl

java.lang.Object
  extended by net.dpml.cli.commandline.CommandLineImpl
      extended by net.dpml.cli.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.

Version:
1.0.0
Author:
Digital Product Meta Library

Constructor Summary
WriteableCommandLineImpl(Option rootOption, List arguments)
          Creates a new WriteableCommandLineImpl rooted on the specified Option, to hold the parsed arguments.
 
Method Summary
 void addOption(Option option)
          Add an option.
 void addProperty(String property, String value)
          Add a property to the commandline.
 void addSwitch(Option option, boolean value)
          Add a switch.
 void addValue(Option option, Object value)
          Add an option.
 List getNormalised()
          Return the normalized collection.
 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 this CommandLine
 String getProperty(String property, String defaultValue)
          Retrieves the value associated with the specified property
 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.
 boolean looksLikeOption(String trigger)
          Return true if the trigger argument looks like an option.
 void setDefaultSwitch(Option option, Boolean defaultSwitch)
          Set default switch.
 void setDefaultValues(Option option, List defaults)
          Set default values.
 String toString()
          Return this commandline as a string.
 
Methods inherited from class net.dpml.cli.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 net.dpml.cli.CommandLine
getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption
 

Constructor Detail

WriteableCommandLineImpl

public WriteableCommandLineImpl(Option rootOption,
                                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)
Add an option.

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

addValue

public void addValue(Option option,
                     Object value)
Add an option.

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

addSwitch

public void addSwitch(Option option,
                      boolean value)
Add a switch.

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

hasOption

public boolean hasOption(Option option)
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(String trigger)
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 List getValues(Option option,
                      List defaultValues)
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 Boolean getSwitch(Option option,
                         Boolean defaultValue)
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(String property,
                        String value)
Add a property to the commandline.

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

getProperty

public String getProperty(String property,
                          String defaultValue)
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 Set getProperties()
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(String trigger)
Return true if the trigger argument looks like an option.

Specified by:
looksLikeOption in interface WriteableCommandLine
Parameters:
trigger - the trigger to evaluate
Returns:
true if the trigger looks like an option

toString

public String toString()
Return this commandline as a string.

Overrides:
toString in class Object
Returns:
the string representation

getOptions

public List getOptions()
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 Set getOptionTriggers()
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,
                             List defaults)
Set default values.

Specified by:
setDefaultValues in interface WriteableCommandLine
Parameters:
option - the option
defaults - a list of defaults

setDefaultSwitch

public void setDefaultSwitch(Option option,
                             Boolean defaultSwitch)
Set default switch.

Specified by:
setDefaultSwitch in interface WriteableCommandLine
Parameters:
option - the option
defaultSwitch - the default switch state

getNormalised

public List getNormalised()
Return the normalized collection.

Returns:
the moprmalized collection