Class OptionGroup

  • All Implemented Interfaces:
    java.io.Serializable

    public class OptionGroup
    extends java.lang.Object
    implements java.io.Serializable
    A group of mutually exclusive options.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​Option> optionMap
      Maps options where keys are option name and values are the options.
      private boolean required
      Specified whether this group is required.
      private java.lang.String selected
      The name of the selected option.
      private static long serialVersionUID
      The serial version UID.
    • Constructor Summary

      Constructors 
      Constructor Description
      OptionGroup()
      Constructs a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      OptionGroup addOption​(Option option)
      Adds the given Option to this group.
      java.util.Collection<java.lang.String> getNames()
      Gets the names of the options in this group as a Collection.
      java.util.Collection<Option> getOptions()
      Gets the options in this group as a Collection.
      java.lang.String getSelected()
      Gets the selected option name.
      boolean isRequired()
      Tests whether this option group is required.
      boolean isSelected()
      Tests whether an option is selected.
      void setRequired​(boolean required)
      Sets whether this group is required.
      void setSelected​(Option option)
      Sets the selected option of this group to name.
      java.lang.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
    • 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
        Maps options where keys are option name and values are the options.
      • selected

        private java.lang.String selected
        The name of the selected option.
      • required

        private boolean required
        Specified whether this group is required.
    • Constructor Detail

      • OptionGroup

        public OptionGroup()
        Constructs a new instance.
    • Method Detail

      • addOption

        public OptionGroup addOption​(Option option)
        Adds the given Option to 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()
        Gets the names of the options in this group as a Collection.
        Returns:
        the names of the options in this group as a Collection.
      • getOptions

        public java.util.Collection<Option> getOptions()
        Gets the options in this group as a Collection.
        Returns:
        the options in this group as a Collection.
      • getSelected

        public java.lang.String getSelected()
        Gets the selected option name. If the selected option is deprecated no warning is logged.
        Returns:
        the selected option name.
      • isRequired

        public boolean isRequired()
        Tests whether this option group is required.
        Returns:
        whether this option group is required.
      • isSelected

        public boolean isSelected()
        Tests whether an option is selected. If an option is selected and is deprecated no warning is logged.
        Returns:
        whether whether an option is selected.
        Since:
        1.9.0
      • setRequired

        public void setRequired​(boolean required)
        Sets whether this group is required.
        Parameters:
        required - whether this group is required.
      • setSelected

        public void setSelected​(Option option)
                         throws AlreadySelectedException
        Sets the selected option of this group to name. If the selected option is deprecated no warning is logged.
        Parameters:
        option - the option that is selected.
        Throws:
        AlreadySelectedException - if an option from this group has already been selected.
      • 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.