Package org.apache.commons.cli
Class OptionGroup
- java.lang.Object
-
- org.apache.commons.cli.OptionGroup
-
- All Implemented Interfaces:
java.io.Serializable
public class OptionGroup extends java.lang.Object implements java.io.SerializableA group of mutually exclusive options.- Version:
- $Id: OptionGroup.java 1749596 2016-06-21 20:27:06Z britter $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Option>optionMaphold the optionsprivate booleanrequiredspecified whether this group is requiredprivate java.lang.Stringselectedthe name of the selected optionprivate static longserialVersionUIDThe serial version UID.
-
Constructor Summary
Constructors Constructor Description OptionGroup()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionGroupaddOption(Option option)Add the specifiedOptionto this group.java.util.Collection<java.lang.String>getNames()java.util.Collection<Option>getOptions()java.lang.StringgetSelected()booleanisRequired()Returns whether this option group is required.voidsetRequired(boolean required)voidsetSelected(Option option)Set the selected option of this group toname.java.lang.StringtoString()Returns the stringified version of this OptionGroup.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
The serial version UID.- See Also:
- Constant Field Values
-
optionMap
private final java.util.Map<java.lang.String,Option> optionMap
hold the options
-
selected
private java.lang.String selected
the name of the selected option
-
required
private boolean required
specified whether this group is required
-
-
Method Detail
-
addOption
public OptionGroup addOption(Option option)
Add the specifiedOptionto this group.- Parameters:
option- the option to add to this group- Returns:
- this option group with the option added
-
getNames
public java.util.Collection<java.lang.String> getNames()
- Returns:
- the names of the options in this group as a
Collection
-
getOptions
public java.util.Collection<Option> getOptions()
- Returns:
- the options in this group as a
Collection
-
setSelected
public void setSelected(Option option) throws AlreadySelectedException
Set the selected option of this group toname.- Parameters:
option- the option that is selected- Throws:
AlreadySelectedException- if an option from this group has already been selected.
-
getSelected
public java.lang.String getSelected()
- Returns:
- the selected option name
-
setRequired
public void setRequired(boolean required)
- Parameters:
required- specifies if this group is required
-
isRequired
public boolean isRequired()
Returns whether this option group is required.- Returns:
- whether this option group is required
-
toString
public java.lang.String toString()
Returns the stringified version of this OptionGroup.- Overrides:
toStringin classjava.lang.Object- Returns:
- the stringified representation of this group
-
-