- java.lang.Object
-
- Apache.CLI.OptionGroup
-
- All Implemented Interfaces:
java.io.Serializable
public class OptionGroup extends java.lang.Object implements java.io.Serializable
This Class-File has been copied, directly from the Apache Commons Software Foundation. Other than the minor, cosmetic changes (mentioned in the second-list below), this file is perfectly identical to the original that may be found on the Apache Website:apache.org
.- The suggested license for using this file may be read here:
Apache License
- The Source-Code Header for this file may be viewed here:
Source-File Header
- Partial contents of the
'site/resources/images'
directory:Resource Images
Notes about changes that have been made as a result of the import process:- Within all files, the original Package-Name declaration has been changed:
Original: package org.apache.commons.cli;
Updated: package Apache.CLI;
- All Classes and Class-Members (Methods, Fields, etc...) that were previously Annotated
with the
@Deprecated
Annotation have been summarily removed.
- Code Formattings and Styling has been heavily modified to conform to the Standard Java-HTML
Indentation & Styling Choices. The code itself remains identical, with only a few
squiggly-braces
'{' and '}'
being removed, for cosmetic reasons (and for lowering "Developer Stress" Levels)..
A group of mutually exclusive options.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Apache/CLI/OptionGroup.java
- Open New Browser-Tab: Apache/CLI/OptionGroup.java
File Size: 4,461 Bytes Line Count: 149 '\n' Characters Found
-
-
Constructor Summary
Constructors Constructor Description OptionGroup()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionGroup
addOption(Option option)
Add the specifiedOption
to this group.Collection<String>
getNames()
Collection<Option>
getOptions()
String
getSelected()
boolean
isRequired()
Tests whether this option group is required.void
setRequired(boolean required)
void
setSelected(Option option)
Sets the selected option of this group toname
.String
toString()
Returns the stringified version of this OptionGroup.
-
-
-
Constructor Detail
-
OptionGroup
public OptionGroup()
-
-
Method Detail
-
addOption
public OptionGroup addOption(Option option)
Add the specifiedOption
to this group.- Parameters:
option
- the option to add to this group- Returns:
- this option group with the option added
- Code:
- Exact Method Body:
// key - option name // value - the option optionMap.put(option.getKey(), option); return this;
-
getNames
public java.util.Collection<java.lang.String> getNames()
- Returns:
- the names of the options in this group as a
Collection
- Code:
- Exact Method Body:
// the key set is the collection of names return optionMap.keySet();
-
getOptions
public java.util.Collection<Option> getOptions()
- Returns:
- the options in this group as a
Collection
- Code:
- Exact Method Body:
// the values are the collection of options return optionMap.values();
-
getSelected
public java.lang.String getSelected()
- Returns:
- the selected option name
- Code:
- Exact Method Body:
return selected;
-
isRequired
public boolean isRequired()
Tests whether this option group is required.- Returns:
- whether this option group is required
- Code:
- Exact Method Body:
return required;
-
setRequired
public void setRequired(boolean required)
- Parameters:
required
- specifies if this group is required- Code:
- Exact Method Body:
this.required = required;
-
setSelected
public void setSelected(Option option) throws AlreadySelectedException
Sets 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.- Code:
- Exact Method Body:
if (option == null) { // reset the option previously selected selected = null; return; } // if no option has already been selected or the // same option is being reselected then set the // selected member variable if (selected != null && !selected.equals(option.getKey())) throw new AlreadySelectedException(this, option); selected = option.getKey();
-
toString
public java.lang.String toString()
Returns the stringified version of this OptionGroup.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the stringified representation of this group
- Code:
- Exact Method Body:
final StringBuilder buff = new StringBuilder(); final Iterator<Option> iter = getOptions().iterator(); buff.append("["); while (iter.hasNext()) { final Option option = iter.next(); if (option.getOpt() != null) { buff.append("-"); buff.append(option.getOpt()); } else { buff.append("--"); buff.append(option.getLongOpt()); } if (option.getDescription() != null) { buff.append(" "); buff.append(option.getDescription()); } if (iter.hasNext()) buff.append(", "); } buff.append("]"); return buff.toString();
-
-