Package Apache.CLI



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

    1. The suggested license for using this file may be read here: Apache License
    2. The Source-Code Header for this file may be viewed here: Source-File Header
    3. 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


    • Constructor Summary

      Constructors 
      Constructor Description
      OptionGroup()  
    • Method Summary

       
      Retrieve the Post-Processed OptionGroup Choice
      Modifier and Type Method
      String getSelected()  
       
      Manually assign the Post-Processed OptionGroup Choice
      Modifier and Type Method
      void setSelected​(Option option)
      Sets the selected option of this group to name.
       
      Retrieve 'this' OptionGroup's Member-Options
      Modifier and Type Method
      Collection<String> getNames()  
      Collection<Option> getOptions()  
       
      Flag 'this' OptionGroup as Mandatory or Optional at the Command-Line
      Modifier and Type Method
      boolean isRequired()
      Tests whether this option group is required.
      void setRequired​(boolean required)  
       
      Add a Member-Option to this OptionGroup
      Modifier and Type Method
      OptionGroup addOption​(Option option)
      Add the specified Option to this group.
       
      Methods: class java.lang.Object
      Modifier and Type Method
      String toString()
      Returns the stringified version of this OptionGroup.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • addOption

        🡅  🡇     🗕  🗗  🗖
        public OptionGroup addOption​(Option option)
        Add the specified Option 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<OptiongetOptions()
        Returns:
        the options in this group as a Collection
        Code:
        Exact Method Body:
         // the values are the collection of options
         return optionMap.values();
        
      • 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 to name.
        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 class java.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();