org.apache.commons.cli2.option
Class OptionImpl

java.lang.Object
  extended by org.apache.commons.cli2.option.OptionImpl
All Implemented Interfaces:
Option
Direct Known Subclasses:
ArgumentImpl, GroupImpl, ParentImpl, PropertyOption

public abstract class OptionImpl
extends Object
implements Option

A base implementation of Option providing limited ground work for further Option implementations.


Constructor Summary
OptionImpl(int id, boolean required)
          Creates an OptionImpl with the specified id
 
Method Summary
 boolean canProcess(WriteableCommandLine commandLine, ListIterator arguments)
          Indicates whether this Option will be able to process the particular argument.
protected  void checkPrefixes(Set prefixes)
           
 void defaults(WriteableCommandLine commandLine)
          Adds defaults to a CommandLine.
 boolean equals(Object thatObj)
           
 Option findOption(String trigger)
          Recursively searches for an option with the supplied trigger.
 int getId()
          Returns the id of the option.
 Option getParent()
          Returns the parent of this option.
 int hashCode()
           
 boolean isRequired()
          Indicates whether this option is required to be present.
 void setParent(Option parent)
          Sets the parent of this option.
 String 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
appendUsage, canProcess, getDescription, getPreferredName, getPrefixes, getTriggers, helpLines, process, validate
 

Constructor Detail

OptionImpl

public OptionImpl(int id,
                  boolean required)
Creates an OptionImpl with the specified id

Parameters:
id - the unique id of this Option
required - true iff this Option must be present
Method Detail

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          ListIterator arguments)
Description copied from interface: Option
Indicates whether this Option will be able to process the particular argument. The ListIterator must be restored to the initial state before returning the boolean.

Specified by:
canProcess in interface Option
Parameters:
commandLine - the CommandLine to check
arguments - the ListIterator over String arguments
Returns:
true if the argument can be processed by this Option
See Also:
Option.canProcess(WriteableCommandLine,String)

toString

public String toString()
Overrides:
toString in class Object

getId

public int getId()
Description copied from interface: Option
Returns the id of the option. This can be used in a loop and switch construct: for(Option o : cmd.getOptions()){ switch(o.getId()){ case POTENTIAL_OPTION: ... } } The returned value is not guarenteed to be unique.

Specified by:
getId in interface Option
Returns:
the id of the option.

equals

public boolean equals(Object thatObj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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
Parameters:
trigger - the trigger to search for.
Returns:
the matching option or null.

isRequired

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

Specified by:
isRequired in interface Option
Returns:
true iff the CommandLine will be invalid without this Option

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
Parameters:
commandLine - The CommandLine object to store defaults in

getParent

public Option getParent()
Description copied from interface: Option
Returns the parent of this option. Options can be organized in a hierarchical manner if they are added to groups. This method can be used for obtaining the parent option of this option. The result may be null if this option does not have a parent.

Specified by:
getParent in interface Option
Returns:
the parent of this option

setParent

public void setParent(Option parent)
Description copied from interface: Option
Sets the parent of this option. This method is called when the option is added to a group. Storing the parent of an option makes it possible to keep track of hierarchical relations between options. For instance, if an option is identified while parsing a command line, the group this option belongs to can also be added to the command line.

Specified by:
setParent in interface Option
Parameters:
parent - the parent option

checkPrefixes

protected void checkPrefixes(Set prefixes)


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