net.dpml.cli.option

Class OptionImpl

public abstract class OptionImpl extends Object implements Option

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

Version: @PROJECT-VERSION@

Author: @PUBLISHER-NAME@

Constructor Summary
OptionImpl(int id, boolean required)
Creates an OptionImpl with the specified id
Method Summary
booleancanProcess(WriteableCommandLine commandLine, ListIterator arguments)
Indicates whether this Option will be able to process the particular argument.
protected voidcheckPrefixes(Set prefixes)
Check prefixes.
voiddefaults(WriteableCommandLine commandLine)
Adds defaults to a CommandLine.
booleanequals(Object thatObj)
Evaluate this instance against the supplied instance for equality.
OptionfindOption(String trigger)
Recursively searches for an option with the supplied trigger.
intgetId()
Returns the id of the option.
inthashCode()
Return the hashcode value for this instance.
booleanisRequired()
Indicates whether this option is required to be present.
StringtoString()
Returns a string representation of the option.

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)
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.

Parameters: commandLine the CommandLine object to store defaults in arguments the ListIterator over String arguments

Returns: true if the argument can be processed by this Option

See Also: OptionImpl

checkPrefixes

protected void checkPrefixes(Set prefixes)
Check prefixes.

Parameters: prefixes the prefixes set

defaults

public void defaults(WriteableCommandLine commandLine)
Adds defaults to a CommandLine. Any defaults for this option are applied as well as the defaults for any contained options

Parameters: commandLine the CommandLine object to store defaults in

equals

public boolean equals(Object thatObj)
Evaluate this instance against the supplied instance for equality.

Parameters: thatObj the other object

Returns: true if the supplied instance is equal to this instance

findOption

public Option findOption(String trigger)
Recursively searches for an option with the supplied trigger.

Parameters: trigger the trigger to search for.

Returns: the matching option or null.

getId

public int getId()
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.

Returns: the id of the option.

hashCode

public int hashCode()
Return the hashcode value for this instance.

Returns: the hash value

isRequired

public boolean isRequired()
Indicates whether this option is required to be present.

Returns: true if the CommandLine will be invalid without this Option

toString

public String toString()
Returns a string representation of the option.

Returns: the string value